jsource
jsource copied to clipboard
WIP: Restructure constants in j.c
Well, it works, but we should merge #178 first to prevent a conflict hell, and finish this one.
- TODO: Take a better look at
I1mem, it works now but this is really ugly - TODO: Change the other
I[8]entries in this file as well.
Well, the more you learn, the more you realize the thing you're trying to do won't work.
The AD struct has a number of fields, this refactor relates mainly to 3 of them:
I kchain.k(union, we use thekfield), used for an offsetRANKT rank(unsigned short)I s[1]shape
The complete structure is of a size of 64 bits, but this is just the header. The contents of the array itself are appended after this struct, unless we're dealing with an atom of certain types.
The structure is visualized in these slides at the first three slides.The red part in these visualizations are the 64 bits allocated for the struct. The I s[1] for the shape is very misleading. The actual memory layout is like this:
- 56 bytes of
kchainup to (but excluding)s[1]. ranktimes 8 bits of shapes, which can be zerontimes the size of an atom. This starts at offsetkchain
Looking at the slides again, the second visualization shows an integer atom. This one has rank=0, which means the entry at s[1] is actually not a shape, but the integer value. This one fits in the 64 bits of AD, and this is what the Bnum array and the booleans use.
The first visualization is a larger, we have a rank of two, which means the shape array actually contains 2 items, and using the value of s[1]returns a byte outside theAD` struct. And there are 4 more bytes trailing this datastructure.
Back to my original statement: converting I[8] to AD. This works, but next you're getting to the macros CREBLOCKVEC1I and CREBLOCKVEC2I that allocate I[9].
This files also shows an atom for an imaginary number, where the shape is empty, and the items are two floats. This is stored in the struct Bd2, that consists of a header of 56 bits, and two floats (with the first float located at the memory index where AD stores an integer). With my current knowledge, this looks like a start for the desired direction: remove the shape array from the AD struct, which makes AD an actual header. Use structs to combine the header with the shape and the actual data if these values are static. Make the values in kchain/k depend on the size of the header instead of hardcoded values. And finally, we're allowed to touch the internals of AD.