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