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