2009-03-11 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / metadata / mono-endian.h
blob6cee6415259bddbf97127c6dbf933e01494e6b7d
1 #ifndef _MONO_METADATA_ENDIAN_H_
2 #define _MONO_METADATA_ENDIAN_H_ 1
4 #include <glib.h>
6 typedef union {
7 guint32 ival;
8 float fval;
9 } mono_rfloat;
11 typedef union {
12 guint64 ival;
13 double fval;
14 unsigned char cval [8];
15 } mono_rdouble;
17 #ifdef ARM_FPU_FPA
18 #define MONO_DOUBLE_ASSERT_ENDIANITY(dbl_ptr) \
19 do { \
20 mono_rdouble r; \
21 r.fval = *dbl_ptr; \
22 r.ival = (guint64) *((guint32 *) r.cval) << 32 | \
23 *((guint32 *) (r.cval + 4)); \
24 *dbl_ptr = r.fval; \
25 } while (0)
26 #else
27 #define MONO_DOUBLE_ASSERT_ENDIANITY(dbl_ptr)
28 #endif
30 #if NO_UNALIGNED_ACCESS
32 guint16 mono_read16 (const unsigned char *x);
33 guint32 mono_read32 (const unsigned char *x);
34 guint64 mono_read64 (const unsigned char *x);
36 #define read16(x) (mono_read16 ((const unsigned char *)(x)))
37 #define read32(x) (mono_read32 ((const unsigned char *)(x)))
38 #define read64(x) (mono_read64 ((const unsigned char *)(x)))
40 #else
42 #define read16(x) GUINT16_FROM_LE (*((const guint16 *) (x)))
43 #define read32(x) GUINT32_FROM_LE (*((const guint32 *) (x)))
44 #define read64(x) GUINT64_FROM_LE (*((const guint64 *) (x)))
46 #endif
48 #define readr4(x,dest) \
49 do { \
50 mono_rfloat mf; \
51 mf.ival = read32 ((x)); \
52 *(dest) = mf.fval; \
53 } while (0)
55 #define readr8(x,dest) \
56 do { \
57 mono_rdouble mf; \
58 mf.ival = read64 ((x)); \
59 MONO_DOUBLE_ASSERT_ENDIANITY (&mf.fval); \
60 *(dest) = mf.fval; \
61 } while (0)
63 #endif /* _MONO_METADATA_ENDIAN_H_ */