escript  Revision_
speckley/src/system_dep.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 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 #ifdef ESYS_DEPRECATED_BOOST_ENDIAN
40 #include <boost/predef/other/endian.h>
41 #endif
42 
43 namespace speckley {
44 
45 enum {
46 #ifndef ESYS_DEPRECATED_BOOST_ENDIAN
47  BYTEORDER_NATIVE = BOOST_BYTE_ORDER,
48 #elif defined(ESYS_DEPRECATED_BOOST_ENDIAN) && defined(BOOST_ENDIAN_BIG_BYTE)
49  BYTEORDER_NATIVE = 4321,
50 #elif defined(ESYS_DEPRECATED_BOOST_ENDIAN) && defined(BOOST_ENDIAN_LITTLE_BYTE)
51  BYTEORDER_NATIVE = 1234,
52 #elif defined(ESYS_DEPRECATED_BOOST_ENDIAN) && defined(BOOST_ENDIAN_LITTLE_WORD)
53  BYTEORDER_NATIVE = 2134,
54 #endif
57 };
58 
59 enum {
63 };
64 
65 } // namespace
66 
67 #ifdef _WIN32
68 #include <stdlib.h>
69 namespace speckley {
70 inline char* byte_swap32(char* val)
71 {
72  unsigned long* v = reinterpret_cast<unsigned long*>(val);
73  *v = _byteswap_ulong(*v);
74  return val;
75 }
76 inline char* byte_swap64(char* val)
77 {
78  unsigned __int64* v = reinterpret_cast<unsigned __int64*>(val);
79  *v = _byteswap_uint64(*v);
80  return val;
81 }
82 } // namespace
83 
84 #else
85 
86 #include <stdint.h> // uint64_t
87 
88 #if HAVE_BYTESWAP_H
89 # include <byteswap.h>
90 #elif HAVE_SYS_ENDIAN_H
91 # include <sys/endian.h>
92 # ifdef bswap32
93 # define bswap_32(D) bswap32((D))
94 # endif
95 # ifdef bswap64
96 # define bswap_64(D) bswap64((D))
97 # endif
98 #elif HAVE_OSBYTEORDER_H
99 # include <libkern/OSByteOrder.h>
100 # define bswap_32 OSSwapInt32
101 # define bswap_64 OSSwapInt64
102 #else // uh oh, we can't swap bytes...
103 # define bswap_32(D) (D)
104 # define bswap_64(D) (D)
105 #endif // header selection
106 
107 namespace speckley {
108 inline char* byte_swap32(char* val)
109 {
110  unsigned int* v = reinterpret_cast<unsigned int*>(val);
111  *v = bswap_32(*v);
112  return val;
113 }
114 
115 inline char* byte_swap64(char* val)
116 {
117  uint64_t* v = reinterpret_cast<uint64_t*>(val);
118  *v = bswap_64(*v);
119  return val;
120 }
121 } // namespace speckley
122 
123 #endif // WIN32
124 
125 
126 #endif // __SPECKLEY_SYSTEM_DEP_H__
127 
Definition: AbstractAssembler.cpp:18
#define bswap_64(D)
Definition: speckley/src/system_dep.h:104
Definition: speckley/src/system_dep.h:60
#define bswap_32(D)
Definition: speckley/src/system_dep.h:103
Definition: speckley/src/system_dep.h:62
Definition: speckley/src/system_dep.h:55
Definition: speckley/src/system_dep.h:47
char * byte_swap32(char *val)
Definition: speckley/src/system_dep.h:108
Definition: speckley/src/system_dep.h:56
Definition: speckley/src/system_dep.h:61
char * byte_swap64(char *val)
Definition: speckley/src/system_dep.h:115