[MLton-commit] r4312
Matthew Fluet
MLton@mlton.org
Thu, 26 Jan 2006 17:55:42 -0800
Fixing some casts
----------------------------------------------------------------------
A mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/PackWord.c
U mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word.c
D mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Array.c
D mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Vector.c
U mlton/branches/on-20050822-x86_64-branch/runtime/basis/IntInf.c
U mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/PackReal.c
----------------------------------------------------------------------
Added: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/PackWord.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/PackWord.c 2006-01-27 01:54:17 UTC (rev 4311)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/PackWord.c 2006-01-27 01:55:39 UTC (rev 4312)
@@ -0,0 +1,76 @@
+#include "platform.h"
+
+#define Arr(t) Array(t)
+#define Vec(t) Vector(t)
+
+#define mkSubSeq(kind, Seq) \
+Word##kind##_t PackWord##kind##_sub##Seq (Seq(Word8_t) seq, Int offset) { \
+ Word##kind##_t w; \
+ pointer p = (pointer)&w; \
+ pointer s = (pointer)seq + ((kind / 8) * offset); \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ p[i] = s[i]; \
+ return w; \
+}
+#define mkSubSeqRev(kind, Seq) \
+Word##kind##_t PackWord##kind##_sub##Seq##Rev (Seq(Word8_t) seq, Int offset) { \
+ Word##kind##_t w; \
+ pointer p = (pointer)&w; \
+ pointer s = (pointer)seq + ((kind / 8) * offset); \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ p[i] = s[((kind / 8) - 1) - i]; \
+ return w; \
+}
+
+#define mkUpdate(kind) \
+void PackWord##kind##_update (Arr(Word8_t) a, Int offset, Word##kind##_t w) { \
+ pointer p = (pointer)&w; \
+ pointer s = (pointer)a + ((kind / 8) * offset); \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ s[i] = p[i]; \
+}
+#define mkUpdateRev(kind) \
+void PackWord##kind##_updateRev (Arr(Word8_t) a, Int offset, Word##kind##_t w) { \
+ pointer p = (pointer)&w; \
+ pointer s = (pointer)a + ((kind / 8) * offset); \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ s[i] = p[((kind / 8) - 1) - i]; \
+}
+
+#define all(size) \
+ mkSubSeq(size, Arr) \
+ mkSubSeq(size, Vec) \
+ mkSubSeqRev(size, Arr) \
+ mkSubSeqRev(size, Vec) \
+ mkUpdate(size) \
+ mkUpdateRev(size)
+
+all (16)
+all (32)
+all (64)
+
+#undef mkSubSeq
+#undef mkSubSeqRev
+#undef mkUpdate
+#undef all
+
+
+Word32_t Word8Array_subWord32Rev (Array(Word8_t) a, Int offset) {
+ return PackWord32_subArrRev (a, offset);
+}
+
+void Word8Array_updateWord32Rev (Array(Word32_t) a, Int offset, Word32_t w) {
+ PackWord32_updateRev (a, offset, w);
+}
+
+Word32_t Word8Vector_subWord32Rev (Vector(Word8_t) v, Int offset) {
+ return PackWord32_subArrRev (v, offset);
+}
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word.c 2006-01-27 01:54:17 UTC (rev 4311)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word.c 2006-01-27 01:55:39 UTC (rev 4312)
@@ -24,10 +24,6 @@
* implements / and %.
*/
-#ifndef DEBUG
-#define DEBUG FALSE
-#endif
-
#if ! (defined (__amd64__) || defined (__hppa__) || defined (__i386__) || defined (__ppc__) || defined (__powerpc__) || defined (__sparc__))
#error check that C {/,%} correctly implement {quot,rem} from the basis library
#endif
@@ -42,18 +38,18 @@
coerce (Word##S##from, Word##to) \
coerce (Word##U##from, Word##to)
-#define WordS8_max (WordS8)0x7F
-#define WordS8_min (WordS8)0x80
-#define WordS16_max (WordS16)0x7FFF
-#define WordS16_min (WordS16)0x8000
-#define WordS32_max (WordS32)0x7FFFFFFF
-#define WordS32_min (WordS32)0x80000000
-#define WordS64_max (WordS64)0x7FFFFFFFFFFFFFFFll
-#define WordS64_min (WordS64)0x8000000000000000ll
-#define WordU8_max (WordU8)0xFF
-#define WordU16_max (WordU16)0xFFFF
-#define WordU32_max (WordU32)0xFFFFFFFF
-#define WordU64_max (WordU64)0xFFFFFFFFFFFFFFFFull
+#define WordS8_max (WordS8)INT8_MAX
+#define WordS8_min (WordS8)INT8_MIN
+#define WordS16_max (WordS16)INT16_MAX
+#define WordS16_min (WordS16)INT16_MIN
+#define WordS32_max (WordS32)INT32_MAX
+#define WordS32_min (WordS32)INT32_MIN
+#define WordS64_max (WordS64)INT64_MAX
+#define WordS64_min (WordS64)INT64_MIN
+#define WordU8_max (WordU8)UINT8_MAX
+#define WordU16_max (WordU16)UINT16_MAX
+#define WordU32_max (WordU32)UINT32_MAX
+#define WordU64_max (WordU64)UINT64_MAX
#define binary(kind, name, op) \
Word##kind Word##kind##_##name (Word##kind w1, Word##kind w2); \
Deleted: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Array.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Array.c 2006-01-27 01:54:17 UTC (rev 4311)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Array.c 2006-01-27 01:55:39 UTC (rev 4312)
@@ -1,26 +0,0 @@
-#include "platform.h"
-
-Word32 Word8Array_subWord32Rev (Pointer v, Int offset) {
- Word32 w;
- pointer p;
- pointer s;
- int i;
-
- p = (pointer )&w;
- s = v + (offset * 4);
- for (i = 0; i < 4; ++i)
- p[i] = s[3 - i];
- return w;
-}
-
-void Word8Array_updateWord32Rev (Pointer a, Int offset, Word32 w) {
- pointer p;
- pointer s;
- int i;
-
- p = (pointer)&w;
- s = a + (offset * 4);
- for (i = 0; i < 4; ++i) {
- s[i] = p[3 - i];
- }
-}
Deleted: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Vector.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Vector.c 2006-01-27 01:54:17 UTC (rev 4311)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Int/Word8Vector.c 2006-01-27 01:55:39 UTC (rev 4312)
@@ -1,14 +0,0 @@
-#include "platform.h"
-
-Word32 Word8Vector_subWord32Rev (Pointer v, Int offset) {
- Word32 w;
- pointer p;
- pointer s;
- int i;
-
- p = (pointer)&w;
- s = v + (offset * 4);
- for (i = 0; i < 4; ++i)
- p[i] = s[3 - i];
- return w;
-}
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis/IntInf.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/IntInf.c 2006-01-27 01:54:17 UTC (rev 4311)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/IntInf.c 2006-01-27 01:55:39 UTC (rev 4312)
@@ -22,11 +22,11 @@
* Test if a intInf is a fixnum.
*/
static inline bool isSmall (pointer arg) {
- return ((uintptr_t)arg & 1);
+ return ((uintptr_t)arg & 1);
}
static inline bool eitherIsSmall (pointer arg1, pointer arg2) {
- return (((uintptr_t)arg1 | (uintptr_t)arg2) & 1);
+ return (((uintptr_t)arg1 | (uintptr_t)arg2) & 1);
}
static inline bool areSmall (pointer arg1, pointer arg2) {
Modified: mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/PackReal.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/PackReal.c 2006-01-27 01:54:17 UTC (rev 4311)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/basis/Real/PackReal.c 2006-01-27 01:55:39 UTC (rev 4312)
@@ -1,85 +1,62 @@
#include "platform.h"
-Real32 PackReal32_subVec (Pointer v, Int offset) {
- Real32 r;
- pointer p = (pointer)&r;
- pointer s = v + offset;
- int i;
+#define Arr(t) Array(t)
+#define Vec(t) Vector(t)
- for (i = 0; i < 4; ++i)
- p[i] = s[i];
- return r;
+#define mkSubSeq(kind, Seq) \
+Real##kind##_t PackReal##kind##_sub##Seq (Seq(Word8_t) seq, Int offset) { \
+ Real##kind##_t r; \
+ pointer p = (pointer)&r; \
+ pointer s = (pointer)seq + offset; \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ p[i] = s[i]; \
+ return r; \
}
-
-Real32 PackReal32_subVecRev (Pointer v, Int offset) {
- Real32 r;
- pointer p = (pointer)&r;
- pointer s = v + offset;
- int i;
-
- for (i = 0; i < 4; ++i)
- p[i] = s[3 - i];
- return r;
+#define mkSubSeqRev(kind, Seq) \
+Real##kind##_t PackReal##kind##_sub##Seq##Rev (Seq(Word8_t) seq, Int offset) { \
+ Real##kind##_t r; \
+ pointer p = (pointer)&r; \
+ pointer s = (pointer)seq + offset; \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ p[i] = s[((kind / 8) - 1) - i]; \
+ return r; \
}
-Real64 PackReal64_subVec (Pointer v, Int offset) {
- Real64 r;
- pointer p = (pointer)&r;
- pointer s = v + offset;
- int i;
-
- for (i = 0; i < 8; ++i)
- p[i] = s[i];
- return r;
+#define mkUpdate(kind) \
+void PackReal##kind##_update (Arr(Word8_t) a, Int offset, Real##kind##_t r) { \
+ pointer p = (pointer)&r; \
+ pointer s = (pointer)a + offset; \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ s[i] = p[i]; \
}
-
-Real64 PackReal64_subVecRev (Pointer v, Int offset) {
- Real64 r;
- pointer p = (pointer)&r;
- pointer s = v + offset;
- int i;
-
- for (i = 0; i < 8; ++i)
- p[i] = s[7 - i];
- return r;
+#define mkUpdateRev(kind) \
+void PackReal##kind##_updateRev (Arr(Word8_t) a, Int offset, Real##kind##_t r) { \
+ pointer p = (pointer)&r; \
+ pointer s = (pointer)a + offset; \
+ int i; \
+ \
+ for (i = 0; i < kind / 8; ++i) \
+ s[i] = p[((kind / 8) - 1) - i]; \
}
-void PackReal32_update (Pointer a, Int offset, Real32 r) {
- pointer p = (pointer)&r;
- pointer s = a + offset;
- int i;
+#define all(size) \
+ mkSubSeq(size, Arr) \
+ mkSubSeq(size, Vec) \
+ mkSubSeqRev(size, Arr) \
+ mkSubSeqRev(size, Vec) \
+ mkUpdate(size) \
+ mkUpdateRev(size)
- for (i = 0; i < 4; ++i) {
- s[i] = p[i];
- }
-}
+all (32)
+all (64)
-void PackReal32_updateRev (Pointer a, Int offset, Real32 r) {
- pointer p = (pointer)&r;
- pointer s = a + offset;
- int i;
-
- for (i = 0; i < 4; ++i) {
- s[i] = p[3 - i];
- }
-}
-
-void PackReal64_update (Pointer a, Int offset, Real64 r) {
- pointer p = (pointer)&r;
- pointer s = a + offset;
- int i;
-
- for (i = 0; i < 8; ++i) {
- s[i] = p[i];
- }
-}
-
-void PackReal64_updateRev (Pointer a, Int offset, Real64 r) {
- pointer p = (pointer)&r;
- pointer s = a + offset;
- int i;
-
- for (i = 0; i < 8; ++i) {
- s[i] = p[7 - i];
- }
-}
+#undef mkSubSeq
+#undef mkSubSeqRev
+#undef mkUpdate
+#undef all