380b3fb06132c2fab5259896f978d1a2d5be20c9
[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) of a target platform.
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://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
13 *
14 * ---------------------------------------------------------------------------*/
15
16 #ifndef MACHDEPS_H
17 #define MACHDEPS_H
18
19 /* Don't allow stage1 (cross-)compiler embed assumptions about target
20 * platform. When ghc-stage1 is being built by ghc-stage0 is should not
21 * refer to target defines. A few past examples:
22 * - https://ghc.haskell.org/trac/ghc/ticket/13491
23 * - https://phabricator.haskell.org/D3122
24 * - https://phabricator.haskell.org/D3405
25 *
26 * In those cases code change assumed target defines like SIZEOF_HSINT
27 * are applied to host platform, not target platform.
28 *
29 * So what should be used instead in STAGE=1?
30 *
31 * To get host's equivalent of SIZEOF_HSINT you can use Bits instances:
32 * Data.Bits.finiteBitSize (0 :: Int)
33 *
34 * To get target's values it is preferred to use runtime target
35 * configuration from 'targetPlatform :: DynFlags -> Platform'
36 * record. A few wrappers are already defined and used throughout GHC:
37 * wORD_SIZE :: DynFlags -> Int
38 * wORD_SIZE dflags = pc_WORD_SIZE (sPlatformConstants (settings dflags))
39 *
40 * Hence we hide these macros from -DSTAGE=1
41 */
42 #if !defined(STAGE) || STAGE >= 2
43
44 /* Sizes of C types come from here... */
45 #include "ghcautoconf.h"
46
47 /* Sizes of Haskell types follow. These sizes correspond to:
48 * - the number of bytes in the primitive type (eg. Int#)
49 * - the number of bytes in the external representation (eg. HsInt)
50 * - the scale offset used by writeFooOffAddr#
51 *
52 * In the heap, the type may take up more space: eg. SIZEOF_INT8 == 1,
53 * but it takes up SIZEOF_HSWORD (4 or 8) bytes in the heap.
54 */
55
56 #define SIZEOF_HSCHAR SIZEOF_WORD32
57 #define ALIGNMENT_HSCHAR ALIGNMENT_WORD32
58
59 #define SIZEOF_HSINT SIZEOF_VOID_P
60 #define ALIGNMENT_HSINT ALIGNMENT_VOID_P
61
62 #define SIZEOF_HSWORD SIZEOF_VOID_P
63 #define ALIGNMENT_HSWORD ALIGNMENT_VOID_P
64
65 #define SIZEOF_HSDOUBLE SIZEOF_DOUBLE
66 #define ALIGNMENT_HSDOUBLE ALIGNMENT_DOUBLE
67
68 #define SIZEOF_HSFLOAT SIZEOF_FLOAT
69 #define ALIGNMENT_HSFLOAT ALIGNMENT_FLOAT
70
71 #define SIZEOF_HSPTR SIZEOF_VOID_P
72 #define ALIGNMENT_HSPTR ALIGNMENT_VOID_P
73
74 #define SIZEOF_HSFUNPTR SIZEOF_VOID_P
75 #define ALIGNMENT_HSFUNPTR ALIGNMENT_VOID_P
76
77 #define SIZEOF_HSSTABLEPTR SIZEOF_VOID_P
78 #define ALIGNMENT_HSSTABLEPTR ALIGNMENT_VOID_P
79
80 #define SIZEOF_INT8 SIZEOF_INT8_T
81 #define ALIGNMENT_INT8 ALIGNMENT_INT8_T
82
83 #define SIZEOF_WORD8 SIZEOF_UINT8_T
84 #define ALIGNMENT_WORD8 ALIGNMENT_UINT8_T
85
86 #define SIZEOF_INT16 SIZEOF_INT16_T
87 #define ALIGNMENT_INT16 ALIGNMENT_INT16_T
88
89 #define SIZEOF_WORD16 SIZEOF_UINT16_T
90 #define ALIGNMENT_WORD16 ALIGNMENT_UINT16_T
91
92 #define SIZEOF_INT32 SIZEOF_INT32_T
93 #define ALIGNMENT_INT32 ALIGNMENT_INT32_T
94
95 #define SIZEOF_WORD32 SIZEOF_UINT32_T
96 #define ALIGNMENT_WORD32 ALIGNMENT_UINT32_T
97
98 #define SIZEOF_INT64 SIZEOF_INT64_T
99 #define ALIGNMENT_INT64 ALIGNMENT_INT64_T
100
101 #define SIZEOF_WORD64 SIZEOF_UINT64_T
102 #define ALIGNMENT_WORD64 ALIGNMENT_UINT64_T
103
104 #ifndef WORD_SIZE_IN_BITS
105 #if SIZEOF_HSWORD == 4
106 #define WORD_SIZE_IN_BITS 32
107 #define WORD_SIZE_IN_BITS_FLOAT 32.0
108 #else
109 #define WORD_SIZE_IN_BITS 64
110 #define WORD_SIZE_IN_BITS_FLOAT 64.0
111 #endif
112 #endif
113
114 #ifndef TAG_BITS
115 #if SIZEOF_HSWORD == 4
116 #define TAG_BITS 2
117 #else
118 #define TAG_BITS 3
119 #endif
120 #endif
121
122 #define TAG_MASK ((1 << TAG_BITS) - 1)
123
124 #endif /* !defined(STAGE) || STAGE >= 2 */
125
126 #endif /* MACHDEPS_H */