RTS tidyup sweep, first phase
[ghc.git] / includes / MachDeps.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The University of Glasgow 2002
4 *
5 * Definitions that characterise machine specific properties of basic
6 * types (C & Haskell).
7 *
8 * NB: Keep in sync with HsFFI.h and StgTypes.h.
9 * NB: THIS FILE IS INCLUDED IN HASKELL SOURCE!
10 * ---------------------------------------------------------------------------*/
11
12 #ifndef MACHDEPS_H
13 #define MACHDEPS_H
14
15 /* Sizes of C types come from here... */
16 #include "ghcautoconf.h"
17
18 /* Sizes of Haskell types follow. These sizes correspond to:
19 * - the number of bytes in the primitive type (eg. Int#)
20 * - the number of bytes in the external representation (eg. HsInt)
21 * - the scale offset used by writeFooOffAddr#
22 *
23 * In the heap, the type may take up more space: eg. SIZEOF_INT8 == 1,
24 * but it takes up SIZEOF_HSWORD (4 or 8) bytes in the heap.
25 */
26
27 /* First, check some assumptions.. */
28 #if SIZEOF_CHAR != 1
29 #error GHC untested on this architecture: sizeof(char) != 1
30 #endif
31
32 #if SIZEOF_SHORT != 2
33 #error GHC untested on this architecture: sizeof(short) != 2
34 #endif
35
36 #if SIZEOF_UNSIGNED_INT != 4
37 #error GHC untested on this architecture: sizeof(unsigned int) != 4
38 #endif
39
40 #define SIZEOF_HSCHAR SIZEOF_WORD32
41 #define ALIGNMENT_HSCHAR ALIGNMENT_WORD32
42
43 #define SIZEOF_HSINT SIZEOF_VOID_P
44 #define ALIGNMENT_HSINT ALIGNMENT_VOID_P
45
46 #define SIZEOF_HSWORD SIZEOF_VOID_P
47 #define ALIGNMENT_HSWORD ALIGNMENT_VOID_P
48
49 #define SIZEOF_HSDOUBLE SIZEOF_DOUBLE
50 #define ALIGNMENT_HSDOUBLE ALIGNMENT_DOUBLE
51
52 #define SIZEOF_HSFLOAT SIZEOF_FLOAT
53 #define ALIGNMENT_HSFLOAT ALIGNMENT_FLOAT
54
55 #define SIZEOF_HSPTR SIZEOF_VOID_P
56 #define ALIGNMENT_HSPTR ALIGNMENT_VOID_P
57
58 #define SIZEOF_HSFUNPTR SIZEOF_VOID_P
59 #define ALIGNMENT_HSFUNPTR ALIGNMENT_VOID_P
60
61 #define SIZEOF_HSSTABLEPTR SIZEOF_VOID_P
62 #define ALIGNMENT_HSSTABLEPTR ALIGNMENT_VOID_P
63
64 #define SIZEOF_INT8 SIZEOF_CHAR
65 #define ALIGNMENT_INT8 ALIGNMENT_CHAR
66
67 #define SIZEOF_WORD8 SIZEOF_UNSIGNED_CHAR
68 #define ALIGNMENT_WORD8 ALIGNMENT_UNSIGNED_CHAR
69
70 #define SIZEOF_INT16 SIZEOF_SHORT
71 #define ALIGNMENT_INT16 ALIGNMENT_SHORT
72
73 #define SIZEOF_WORD16 SIZEOF_UNSIGNED_SHORT
74 #define ALIGNMENT_WORD16 ALIGNMENT_UNSIGNED_SHORT
75
76 #define SIZEOF_INT32 SIZEOF_INT
77 #define ALIGNMENT_INT32 ALIGNMENT_INT
78
79 #define SIZEOF_WORD32 SIZEOF_UNSIGNED_INT
80 #define ALIGNMENT_WORD32 ALIGNMENT_UNSIGNED_INT
81
82 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
83 /* assume long long is 64 bits */
84 #define SIZEOF_INT64 SIZEOF_LONG_LONG
85 #define ALIGNMENT_INT64 ALIGNMENT_LONG_LONG
86 #define SIZEOF_WORD64 SIZEOF_UNSIGNED_LONG_LONG
87 #define ALIGNMENT_WORD64 ALIGNMENT_UNSIGNED_LONG_LONG
88 #elif SIZEOF_LONG == 8
89 #define SIZEOF_INT64 SIZEOF_LONG
90 #define ALIGNMENT_INT64 ALIGNMENT_LONG
91 #define SIZEOF_WORD64 SIZEOF_UNSIGNED_LONG
92 #define ALIGNMENT_WORD64 ALIGNMENT_UNSIGNED_LONG
93 #else
94 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
95 #endif
96
97 #ifndef WORD_SIZE_IN_BITS
98 #if SIZEOF_HSWORD == 4
99 #define WORD_SIZE_IN_BITS 32
100 #else
101 #define WORD_SIZE_IN_BITS 64
102 #endif
103 #endif
104
105 #ifndef TAG_BITS
106 #if SIZEOF_HSWORD == 4
107 #define TAG_BITS 2
108 #else
109 #define TAG_BITS 3
110 #endif
111 #endif
112
113 #define TAG_MASK ((1 << TAG_BITS) - 1)
114
115 #endif /* MACHDEPS_H */