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 #include <boost/detail/endian.hpp>
39 #ifdef ESYS_DEPRECATED_BOOST_ENDIAN
40 #include <boost/predef/other/endian.h>
41 #endif
42 
43 namespace ripley {
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 ripley {
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 ripley {
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 ripley
122 
123 #endif // WIN32
124 
125 
126 #endif // __RIPLEY_SYSTEM_DEP_H__
127 
ripley
Definition: ripley/src/AbstractAssembler.h:26
ripley::byte_swap64
char * byte_swap64(char *val)
Definition: ripley/src/system_dep.h:115
ripley::DATATYPE_FLOAT64
@ DATATYPE_FLOAT64
Definition: ripley/src/system_dep.h:62
ripley::DATATYPE_INT32
@ DATATYPE_INT32
Definition: ripley/src/system_dep.h:60
ripley::BYTEORDER_NATIVE
@ BYTEORDER_NATIVE
Definition: ripley/src/system_dep.h:47
ripley::byte_swap32
char * byte_swap32(char *val)
Definition: ripley/src/system_dep.h:108
ripley::BYTEORDER_LITTLE_ENDIAN
@ BYTEORDER_LITTLE_ENDIAN
Definition: ripley/src/system_dep.h:55
ripley::DATATYPE_FLOAT32
@ DATATYPE_FLOAT32
Definition: ripley/src/system_dep.h:61
bswap_64
#define bswap_64(D)
Definition: ripley/src/system_dep.h:104
ripley::BYTEORDER_BIG_ENDIAN
@ BYTEORDER_BIG_ENDIAN
Definition: ripley/src/system_dep.h:56
bswap_32
#define bswap_32(D)
Definition: ripley/src/system_dep.h:103