X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fmono-endian.h;h=6cee6415259bddbf97127c6dbf933e01494e6b7d;hb=fea65e31f1a8ed63b0087cbeafacef6bd3383cc3;hp=08075b406ce881bb0ddf414e09b5a1b6552ceba8;hpb=fd9ebd8238ed391edfc3600d699567d0cda8e755;p=mono.git diff --git a/mono/metadata/mono-endian.h b/mono/metadata/mono-endian.h index 08075b406ce..6cee6415259 100644 --- a/mono/metadata/mono-endian.h +++ b/mono/metadata/mono-endian.h @@ -3,8 +3,6 @@ #include -/* FIXME: implement support for misaligned reads */ - typedef union { guint32 ival; float fval; @@ -13,11 +11,39 @@ typedef union { typedef union { guint64 ival; double fval; + unsigned char cval [8]; } mono_rdouble; -#define read16(x) GUINT16_FROM_LE (*((guint16 *) (x))) -#define read32(x) GUINT32_FROM_LE (*((guint32 *) (x))) -#define read64(x) GUINT64_FROM_LE (*((guint64 *) (x))) +#ifdef ARM_FPU_FPA +#define MONO_DOUBLE_ASSERT_ENDIANITY(dbl_ptr) \ + do { \ + mono_rdouble r; \ + r.fval = *dbl_ptr; \ + r.ival = (guint64) *((guint32 *) r.cval) << 32 | \ + *((guint32 *) (r.cval + 4)); \ + *dbl_ptr = r.fval; \ + } while (0) +#else +#define MONO_DOUBLE_ASSERT_ENDIANITY(dbl_ptr) +#endif + +#if NO_UNALIGNED_ACCESS + +guint16 mono_read16 (const unsigned char *x); +guint32 mono_read32 (const unsigned char *x); +guint64 mono_read64 (const unsigned char *x); + +#define read16(x) (mono_read16 ((const unsigned char *)(x))) +#define read32(x) (mono_read32 ((const unsigned char *)(x))) +#define read64(x) (mono_read64 ((const unsigned char *)(x))) + +#else + +#define read16(x) GUINT16_FROM_LE (*((const guint16 *) (x))) +#define read32(x) GUINT32_FROM_LE (*((const guint32 *) (x))) +#define read64(x) GUINT64_FROM_LE (*((const guint64 *) (x))) + +#endif #define readr4(x,dest) \ do { \ @@ -30,6 +56,7 @@ typedef union { do { \ mono_rdouble mf; \ mf.ival = read64 ((x)); \ + MONO_DOUBLE_ASSERT_ENDIANITY (&mf.fval); \ *(dest) = mf.fval; \ } while (0)