Merge branch 'master' of ssh://darcs.haskell.org/srv/darcs/ghc
[ghc-hetmet.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  * To understand the structure of the RTS headers, see the wiki:
12  *   http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
13  *
14  * ---------------------------------------------------------------------------*/
15
16 #ifndef MACHDEPS_H
17 #define MACHDEPS_H
18
19 /* Sizes of C types come from here... */
20 #include "ghcautoconf.h"
21
22 /* Sizes of Haskell types follow.  These sizes correspond to:
23  *   - the number of bytes in the primitive type (eg. Int#)
24  *   - the number of bytes in the external representation (eg. HsInt)
25  *   - the scale offset used by writeFooOffAddr#
26  *
27  * In the heap, the type may take up more space: eg. SIZEOF_INT8 == 1,
28  * but it takes up SIZEOF_HSWORD (4 or 8) bytes in the heap.
29  */
30
31 /* First, check some assumptions.. */
32 #if SIZEOF_CHAR != 1
33 #error GHC untested on this architecture: sizeof(char) != 1
34 #endif
35
36 #if SIZEOF_SHORT != 2
37 #error GHC untested on this architecture: sizeof(short) != 2
38 #endif
39
40 #if SIZEOF_UNSIGNED_INT != 4
41 #error GHC untested on this architecture: sizeof(unsigned int) != 4
42 #endif
43
44 #define SIZEOF_HSCHAR           SIZEOF_WORD32
45 #define ALIGNMENT_HSCHAR        ALIGNMENT_WORD32
46
47 #define SIZEOF_HSINT            SIZEOF_VOID_P
48 #define ALIGNMENT_HSINT         ALIGNMENT_VOID_P
49
50 #define SIZEOF_HSWORD           SIZEOF_VOID_P
51 #define ALIGNMENT_HSWORD        ALIGNMENT_VOID_P
52
53 #define SIZEOF_HSDOUBLE         SIZEOF_DOUBLE
54 #define ALIGNMENT_HSDOUBLE      ALIGNMENT_DOUBLE
55
56 #define SIZEOF_HSFLOAT          SIZEOF_FLOAT
57 #define ALIGNMENT_HSFLOAT       ALIGNMENT_FLOAT
58
59 #define SIZEOF_HSPTR            SIZEOF_VOID_P
60 #define ALIGNMENT_HSPTR         ALIGNMENT_VOID_P
61
62 #define SIZEOF_HSFUNPTR         SIZEOF_VOID_P
63 #define ALIGNMENT_HSFUNPTR      ALIGNMENT_VOID_P
64
65 #define SIZEOF_HSSTABLEPTR      SIZEOF_VOID_P
66 #define ALIGNMENT_HSSTABLEPTR   ALIGNMENT_VOID_P
67
68 #define SIZEOF_INT8             SIZEOF_CHAR
69 #define ALIGNMENT_INT8          ALIGNMENT_CHAR
70
71 #define SIZEOF_WORD8            SIZEOF_UNSIGNED_CHAR
72 #define ALIGNMENT_WORD8         ALIGNMENT_UNSIGNED_CHAR
73
74 #define SIZEOF_INT16            SIZEOF_SHORT
75 #define ALIGNMENT_INT16         ALIGNMENT_SHORT
76
77 #define SIZEOF_WORD16           SIZEOF_UNSIGNED_SHORT
78 #define ALIGNMENT_WORD16        ALIGNMENT_UNSIGNED_SHORT
79
80 #define SIZEOF_INT32            SIZEOF_INT
81 #define ALIGNMENT_INT32         ALIGNMENT_INT
82
83 #define SIZEOF_WORD32           SIZEOF_UNSIGNED_INT
84 #define ALIGNMENT_WORD32        ALIGNMENT_UNSIGNED_INT
85
86 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
87 /* assume long long is 64 bits */
88 #define SIZEOF_INT64            SIZEOF_LONG_LONG
89 #define ALIGNMENT_INT64         ALIGNMENT_LONG_LONG
90 #define SIZEOF_WORD64           SIZEOF_UNSIGNED_LONG_LONG
91 #define ALIGNMENT_WORD64        ALIGNMENT_UNSIGNED_LONG_LONG
92 #elif SIZEOF_LONG == 8
93 #define SIZEOF_INT64            SIZEOF_LONG
94 #define ALIGNMENT_INT64         ALIGNMENT_LONG
95 #define SIZEOF_WORD64           SIZEOF_UNSIGNED_LONG
96 #define ALIGNMENT_WORD64        ALIGNMENT_UNSIGNED_LONG
97 #else
98 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
99 #endif
100
101 #ifndef WORD_SIZE_IN_BITS
102 #if SIZEOF_HSWORD == 4
103 #define WORD_SIZE_IN_BITS       32
104 #else 
105 #define WORD_SIZE_IN_BITS       64
106 #endif
107 #endif
108
109 #ifndef TAG_BITS
110 #if SIZEOF_HSWORD == 4
111 #define TAG_BITS                2
112 #else 
113 #define TAG_BITS                3
114 #endif
115 #endif
116
117 #define TAG_MASK ((1 << TAG_BITS) - 1)
118
119 #endif /* MACHDEPS_H */