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