Apply changes from https://github.com/dotnet/runtime/commit/eb1756e97d23df13bc6fe798e...
[mono-project.git] / mono / metadata / mono-endian.h
blob6fdd09cc7c6b902cb2c2bc2f8f306747bf80c890
1 /**
2 * \file
3 */
5 #ifndef _MONO_METADATA_ENDIAN_H_
6 #define _MONO_METADATA_ENDIAN_H_ 1
8 #include <glib.h>
10 typedef union {
11 guint32 ival;
12 float fval;
13 } mono_rfloat;
15 typedef union {
16 guint64 ival;
17 double fval;
18 unsigned char cval [8];
19 } mono_rdouble;
21 #if defined(__s390x__)
23 #define read16(x) __builtin_bswap16(*((guint16 *)(x)))
24 #define read32(x) __builtin_bswap32(*((guint32 *)(x)))
25 #define read64(x) __builtin_bswap64(*((guint64 *)(x)))
27 #else
29 # if NO_UNALIGNED_ACCESS
31 guint16 mono_read16 (const unsigned char *x);
32 guint32 mono_read32 (const unsigned char *x);
33 guint64 mono_read64 (const unsigned char *x);
35 #define read16(x) (mono_read16 ((const unsigned char *)(x)))
36 #define read32(x) (mono_read32 ((const unsigned char *)(x)))
37 #define read64(x) (mono_read64 ((const unsigned char *)(x)))
39 # else
41 #define read16(x) GUINT16_FROM_LE (*((const guint16 *) (x)))
42 #define read32(x) GUINT32_FROM_LE (*((const guint32 *) (x)))
43 #define read64(x) GUINT64_FROM_LE (*((const guint64 *) (x)))
45 # endif
47 #endif
49 #define readr4(x,dest) \
50 do { \
51 mono_rfloat mf; \
52 mf.ival = read32 ((x)); \
53 *(dest) = mf.fval; \
54 } while (0)
56 #define readr8(x,dest) \
57 do { \
58 mono_rdouble mf; \
59 mf.ival = read64 ((x)); \
60 *(dest) = mf.fval; \
61 } while (0)
63 #endif /* _MONO_METADATA_ENDIAN_H_ */