escript  Revision_
speckley/src/system_dep.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 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-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 #ifndef __SPECKLEY_SYSTEM_DEP_H__
19 #define __SPECKLEY_SYSTEM_DEP_H__
20 
21 #include <escript/DataTypes.h>
22 
23 #define Speckley_DLL_API
24 
25 #ifdef _WIN32
26 # ifndef Speckley_STATIC_LIB
27 # undef Speckley_DLL_API
28 # ifdef Speckley_EXPORTS
29 # define Speckley_DLL_API __declspec(dllexport)
30 # else
31 # define Speckley_DLL_API __declspec(dllimport)
32 # endif
33 # endif
34 #endif
35 
36 
37 // byte swapping / endianness:
38 
39 #include <boost/detail/endian.hpp>
40 #ifdef ESYS_DEPRECATED_BOOST_ENDIAN
41 #include <boost/predef/other/endian.h>
42 #endif
43 
44 namespace speckley {
45 
46 enum {
47 #ifndef ESYS_DEPRECATED_BOOST_ENDIAN
48  BYTEORDER_NATIVE = BOOST_BYTE_ORDER,
49 #elif defined(ESYS_DEPRECATED_BOOST_ENDIAN) && defined(BOOST_ENDIAN_BIG_BYTE)
50  BYTEORDER_NATIVE = 4321,
51 #elif defined(ESYS_DEPRECATED_BOOST_ENDIAN) && defined(BOOST_ENDIAN_LITTLE_BYTE)
52  BYTEORDER_NATIVE = 1234,
53 #elif defined(ESYS_DEPRECATED_BOOST_ENDIAN) && defined(BOOST_ENDIAN_LITTLE_WORD)
54  BYTEORDER_NATIVE = 2134,
55 #endif
58 };
59 
60 enum {
64 };
65 
66 } // namespace
67 
68 #ifdef _WIN32
69 #include <stdlib.h>
70 namespace speckley {
71 inline char* byte_swap32(char* val)
72 {
73  unsigned long* v = reinterpret_cast<unsigned long*>(val);
74  *v = _byteswap_ulong(*v);
75  return val;
76 }
77 inline char* byte_swap64(char* val)
78 {
79  unsigned __int64* v = reinterpret_cast<unsigned __int64*>(val);
80  *v = _byteswap_uint64(*v);
81  return val;
82 }
83 } // namespace
84 
85 #else
86 
87 #include <stdint.h> // uint64_t
88 
89 #if HAVE_BYTESWAP_H
90 # include <byteswap.h>
91 #elif HAVE_SYS_ENDIAN_H
92 # include <sys/endian.h>
93 # ifdef bswap32
94 # define bswap_32(D) bswap32((D))
95 # endif
96 # ifdef bswap64
97 # define bswap_64(D) bswap64((D))
98 # endif
99 #elif HAVE_OSBYTEORDER_H
100 # include <libkern/OSByteOrder.h>
101 # define bswap_32 OSSwapInt32
102 # define bswap_64 OSSwapInt64
103 #else // uh oh, we can't swap bytes...
104 # define bswap_32(D) (D)
105 # define bswap_64(D) (D)
106 #endif // header selection
107 
108 namespace speckley {
109 inline char* byte_swap32(char* val)
110 {
111  unsigned int* v = reinterpret_cast<unsigned int*>(val);
112  *v = bswap_32(*v);
113  return val;
114 }
115 
116 inline char* byte_swap64(char* val)
117 {
118  uint64_t* v = reinterpret_cast<uint64_t*>(val);
119  *v = bswap_64(*v);
120  return val;
121 }
122 } // namespace speckley
123 
124 #endif // WIN32
125 
126 
127 #endif // __SPECKLEY_SYSTEM_DEP_H__
128 
speckley::DATATYPE_INT32
@ DATATYPE_INT32
Definition: speckley/src/system_dep.h:61
speckley::DATATYPE_FLOAT64
@ DATATYPE_FLOAT64
Definition: speckley/src/system_dep.h:63
speckley::BYTEORDER_NATIVE
@ BYTEORDER_NATIVE
Definition: speckley/src/system_dep.h:48
bswap_64
#define bswap_64(D)
Definition: speckley/src/system_dep.h:105
speckley
Definition: AbstractAssembler.cpp:19
speckley::byte_swap64
char * byte_swap64(char *val)
Definition: speckley/src/system_dep.h:116
speckley::DATATYPE_FLOAT32
@ DATATYPE_FLOAT32
Definition: speckley/src/system_dep.h:62
bswap_32
#define bswap_32(D)
Definition: speckley/src/system_dep.h:104
speckley::BYTEORDER_LITTLE_ENDIAN
@ BYTEORDER_LITTLE_ENDIAN
Definition: speckley/src/system_dep.h:56
speckley::BYTEORDER_BIG_ENDIAN
@ BYTEORDER_BIG_ENDIAN
Definition: speckley/src/system_dep.h:57
speckley::byte_swap32
char * byte_swap32(char *val)
Definition: speckley/src/system_dep.h:109