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