Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / runtime / basis / coerce.h
... / ...
CommitLineData
1
2#define coerce(n, f, t) \
3 MLTON_CODEGEN_STATIC_INLINE \
4 t f##_##n##To##t (f x) { \
5 return (t)x; \
6 }
7#define bothFromWordCoerce(name, from, to) \
8coerce (name, Word##S##from, to) \
9coerce (name, Word##U##from, to)
10#define bothToWordCoerce(name, from, to) \
11coerce (name, from, Word##S##to) \
12coerce (name, from, Word##U##to)
13
14#define allWordCoerce(size) \
15bothToWordCoerce(rnd, Real32, size) \
16bothToWordCoerce(rnd, Real64, size) \
17bothFromWordCoerce(extd, size, Word8) \
18bothFromWordCoerce(extd, size, Word16) \
19bothFromWordCoerce(extd, size, Word32) \
20bothFromWordCoerce(extd, size, Word64)
21
22allWordCoerce(8)
23allWordCoerce(16)
24allWordCoerce(32)
25allWordCoerce(64)
26
27#undef allWordCoerce
28#undef bothToWordCoerce
29#undef bothFromWordCoerce
30
31coerce(rnd, Real32, Real32)
32coerce(rnd, Real32, Real64)
33coerce(rnd, Real64, Real32)
34coerce(rnd, Real64, Real64)
35
36#undef coerce
37
38#define cast(f, t) \
39 MLTON_CODEGEN_STATIC_INLINE \
40 t f##_castTo##t (f x) { \
41 t y; \
42 memcpy(&y, &x, sizeof(t)); \
43 return y; \
44 }
45
46cast(Real32, Word32)
47cast(Word32, Real32)
48cast(Real64, Word64)
49cast(Word64, Real64)
50
51#undef cast