escript  Revision_
speckley/src/system_dep.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __SPECKLEY_SYSTEM_DEP_H__
18 #define __SPECKLEY_SYSTEM_DEP_H__
19 
20 #include <escript/DataTypes.h>
21 
22 #define Speckley_DLL_API
23 
24 #ifdef _WIN32
25 # ifndef Speckley_STATIC_LIB
26 # undef Speckley_DLL_API
27 # ifdef Speckley_EXPORTS
28 # define Speckley_DLL_API __declspec(dllexport)
29 # else
30 # define Speckley_DLL_API __declspec(dllimport)
31 # endif
32 # endif
33 #endif
34 
35 
36 // byte swapping / endianness:
37 
38 #include <boost/detail/endian.hpp>
39 
40 namespace speckley {
41 
42 enum {
43  BYTEORDER_NATIVE = BOOST_BYTE_ORDER,
46 };
47 
48 enum {
52 };
53 
54 } // namespace
55 
56 #ifdef _WIN32
57 #include <stdlib.h>
58 namespace speckley {
59 inline char* byte_swap32(char* val)
60 {
61  unsigned long* v = reinterpret_cast<unsigned long*>(val);
62  *v = _byteswap_ulong(*v);
63  return val;
64 }
65 inline char* byte_swap64(char* val)
66 {
67  unsigned __int64* v = reinterpret_cast<unsigned __int64*>(val);
68  *v = _byteswap_uint64(*v);
69  return val;
70 }
71 } // namespace
72 
73 #else
74 
75 #include <stdint.h> // uint64_t
76 
77 #if HAVE_BYTESWAP_H
78 # include <byteswap.h>
79 #elif HAVE_SYS_ENDIAN_H
80 # include <sys/endian.h>
81 # ifdef bswap32
82 # define bswap_32(D) bswap32((D))
83 # endif
84 # ifdef bswap64
85 # define bswap_64(D) bswap64((D))
86 # endif
87 #elif HAVE_OSBYTEORDER_H
88 # include <libkern/OSByteOrder.h>
89 # define bswap_32 OSSwapInt32
90 # define bswap_64 OSSwapInt64
91 #else // uh oh, we can't swap bytes...
92 # define bswap_32(D) (D)
93 # define bswap_64(D) (D)
94 #endif // header selection
95 
96 namespace speckley {
97 inline char* byte_swap32(char* val)
98 {
99  unsigned int* v = reinterpret_cast<unsigned int*>(val);
100  *v = bswap_32(*v);
101  return val;
102 }
103 
104 inline char* byte_swap64(char* val)
105 {
106  uint64_t* v = reinterpret_cast<uint64_t*>(val);
107  *v = bswap_64(*v);
108  return val;
109 }
110 } // namespace speckley
111 
112 #endif // WIN32
113 
114 
115 #endif // __SPECKLEY_SYSTEM_DEP_H__
116 
Definition: AbstractAssembler.cpp:18
#define bswap_64(D)
Definition: speckley/src/system_dep.h:93
Definition: speckley/src/system_dep.h:49
#define bswap_32(D)
Definition: speckley/src/system_dep.h:92
Definition: speckley/src/system_dep.h:51
Definition: speckley/src/system_dep.h:44
Definition: speckley/src/system_dep.h:43
char * byte_swap32(char *val)
Definition: speckley/src/system_dep.h:97
Definition: speckley/src/system_dep.h:45
Definition: speckley/src/system_dep.h:50
char * byte_swap64(char *val)
Definition: speckley/src/system_dep.h:104