diff options
author | Michal Terepeta <michal.terepeta@gmail.com> | 2017-10-29 20:49:32 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-10-29 21:51:05 -0400 |
commit | cca2d6b78f97bfb79bef4dc3f75d6c4d15b94680 (patch) | |
tree | 9be80ec91082ad99ba79d21a6cd0aac68309a236 /includes | |
parent | 85aa1f4253163985fe07d172f8da73b784bb7b4b (diff) | |
download | haskell-cca2d6b78f97bfb79bef4dc3f75d6c4d15b94680.tar.gz |
Allow packing constructor fields
This is another step for fixing #13825 and is based on D38 by Simon
Marlow.
The change allows storing multiple constructor fields within the same
word. This currently applies only to `Float`s, e.g.,
```
data Foo = Foo {-# UNPACK #-} !Float {-# UNPACK #-} !Float
```
on 64-bit arch, will now store both fields within the same constructor
word. For `WordX/IntX` we'll need to introduce new primop types.
Main changes:
- We now use sizes in bytes when we compute the offsets for
constructor fields in `StgCmmLayout` and introduce padding if
necessary (word-sized fields are still word-aligned)
- `ByteCodeGen` had to be updated to correctly construct the data
types. This required some new bytecode instructions to allow pushing
things that are not full words onto the stack (and updating
`Interpreter.c`). Note that we only use the packed stuff when
constructing data types (i.e., for `PACK`), in all other cases the
behavior should not change.
- `RtClosureInspect` was changed to handle the new layout when
extracting subterms. This seems to be used by things like `:print`.
I've also added a test for this.
- I deviated slightly from Simon's approach and use `PrimRep` instead
of `ArgRep` for computing the size of fields. This seemed more
natural and in the future we'll probably want to introduce new
primitive types (e.g., `Int8#`) and `PrimRep` seems like a better
place to do that (where we already have `Int64Rep` for example).
`ArgRep` on the other hand seems to be more focused on calling
functions.
Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
Test Plan: ./validate
Reviewers: bgamari, simonmar, austin, hvr, goldfire, erikd
Reviewed By: bgamari
Subscribers: maoe, rwbarton, thomie
GHC Trac Issues: #13825
Differential Revision: https://phabricator.haskell.org/D3809
Diffstat (limited to 'includes')
-rw-r--r-- | includes/rts/Bytecodes.h | 116 | ||||
-rw-r--r-- | includes/stg/Types.h | 4 |
2 files changed, 68 insertions, 52 deletions
diff --git a/includes/rts/Bytecodes.h b/includes/rts/Bytecodes.h index 6ca74bf36e..e5d55f694f 100644 --- a/includes/rts/Bytecodes.h +++ b/includes/rts/Bytecodes.h @@ -27,58 +27,70 @@ #define bci_PUSH_L 2 #define bci_PUSH_LL 3 #define bci_PUSH_LLL 4 -#define bci_PUSH_G 5 -#define bci_PUSH_ALTS 6 -#define bci_PUSH_ALTS_P 7 -#define bci_PUSH_ALTS_N 8 -#define bci_PUSH_ALTS_F 9 -#define bci_PUSH_ALTS_D 10 -#define bci_PUSH_ALTS_L 11 -#define bci_PUSH_ALTS_V 12 -#define bci_PUSH_UBX 13 -#define bci_PUSH_APPLY_N 14 -#define bci_PUSH_APPLY_F 15 -#define bci_PUSH_APPLY_D 16 -#define bci_PUSH_APPLY_L 17 -#define bci_PUSH_APPLY_V 18 -#define bci_PUSH_APPLY_P 19 -#define bci_PUSH_APPLY_PP 20 -#define bci_PUSH_APPLY_PPP 21 -#define bci_PUSH_APPLY_PPPP 22 -#define bci_PUSH_APPLY_PPPPP 23 -#define bci_PUSH_APPLY_PPPPPP 24 -/* #define bci_PUSH_APPLY_PPPPPPP 25 */ -#define bci_SLIDE 26 -#define bci_ALLOC_AP 27 -#define bci_ALLOC_AP_NOUPD 28 -#define bci_ALLOC_PAP 29 -#define bci_MKAP 30 -#define bci_MKPAP 31 -#define bci_UNPACK 32 -#define bci_PACK 33 -#define bci_TESTLT_I 34 -#define bci_TESTEQ_I 35 -#define bci_TESTLT_F 36 -#define bci_TESTEQ_F 37 -#define bci_TESTLT_D 38 -#define bci_TESTEQ_D 39 -#define bci_TESTLT_P 40 -#define bci_TESTEQ_P 41 -#define bci_CASEFAIL 42 -#define bci_JMP 43 -#define bci_CCALL 44 -#define bci_SWIZZLE 45 -#define bci_ENTER 46 -#define bci_RETURN 47 -#define bci_RETURN_P 48 -#define bci_RETURN_N 49 -#define bci_RETURN_F 50 -#define bci_RETURN_D 51 -#define bci_RETURN_L 52 -#define bci_RETURN_V 53 -#define bci_BRK_FUN 54 -#define bci_TESTLT_W 55 -#define bci_TESTEQ_W 56 +#define bci_PUSH8 5 +#define bci_PUSH16 6 +#define bci_PUSH32 7 +#define bci_PUSH8_W 8 +#define bci_PUSH16_W 9 +#define bci_PUSH32_W 10 +#define bci_PUSH_G 11 +#define bci_PUSH_ALTS 12 +#define bci_PUSH_ALTS_P 13 +#define bci_PUSH_ALTS_N 14 +#define bci_PUSH_ALTS_F 15 +#define bci_PUSH_ALTS_D 16 +#define bci_PUSH_ALTS_L 17 +#define bci_PUSH_ALTS_V 18 +#define bci_PUSH_PAD8 19 +#define bci_PUSH_PAD16 20 +#define bci_PUSH_PAD32 21 +#define bci_PUSH_UBX8 22 +#define bci_PUSH_UBX16 23 +#define bci_PUSH_UBX32 24 +#define bci_PUSH_UBX 25 +#define bci_PUSH_APPLY_N 26 +#define bci_PUSH_APPLY_F 27 +#define bci_PUSH_APPLY_D 28 +#define bci_PUSH_APPLY_L 29 +#define bci_PUSH_APPLY_V 30 +#define bci_PUSH_APPLY_P 31 +#define bci_PUSH_APPLY_PP 32 +#define bci_PUSH_APPLY_PPP 33 +#define bci_PUSH_APPLY_PPPP 34 +#define bci_PUSH_APPLY_PPPPP 35 +#define bci_PUSH_APPLY_PPPPPP 36 +/* #define bci_PUSH_APPLY_PPPPPPP 37 */ +#define bci_SLIDE 38 +#define bci_ALLOC_AP 39 +#define bci_ALLOC_AP_NOUPD 40 +#define bci_ALLOC_PAP 41 +#define bci_MKAP 42 +#define bci_MKPAP 43 +#define bci_UNPACK 44 +#define bci_PACK 45 +#define bci_TESTLT_I 46 +#define bci_TESTEQ_I 47 +#define bci_TESTLT_F 48 +#define bci_TESTEQ_F 49 +#define bci_TESTLT_D 50 +#define bci_TESTEQ_D 51 +#define bci_TESTLT_P 52 +#define bci_TESTEQ_P 53 +#define bci_CASEFAIL 54 +#define bci_JMP 55 +#define bci_CCALL 56 +#define bci_SWIZZLE 57 +#define bci_ENTER 58 +#define bci_RETURN 59 +#define bci_RETURN_P 60 +#define bci_RETURN_N 61 +#define bci_RETURN_F 62 +#define bci_RETURN_D 63 +#define bci_RETURN_L 64 +#define bci_RETURN_V 65 +#define bci_BRK_FUN 66 +#define bci_TESTLT_W 67 +#define bci_TESTEQ_W 68 /* If you need to go past 255 then you will run into the flags */ /* If you need to go below 0x0100 then you will run into the instructions */ diff --git a/includes/stg/Types.h b/includes/stg/Types.h index af6a51791c..91ad446993 100644 --- a/includes/stg/Types.h +++ b/includes/stg/Types.h @@ -68,6 +68,8 @@ typedef uint8_t StgWord8; #define STG_INT8_MAX INT8_MAX #define STG_WORD8_MAX UINT8_MAX +#define FMT_Word8 PRIu8 + typedef int16_t StgInt16; typedef uint16_t StgWord16; @@ -75,6 +77,8 @@ typedef uint16_t StgWord16; #define STG_INT16_MAX INT16_MAX #define STG_WORD16_MAX UINT16_MAX +#define FMT_Word16 PRIu16 + typedef int32_t StgInt32; typedef uint32_t StgWord32; |