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