Kurt Stephens

Nerd Up!

Tradeoffs


Pointers to data structures are almost never actually used “as is”, they are almost always used with a offset into a structure starting at an address.

struct cons {
  value type; 
  value car;
  value cdr;
};

For 32-bit word-aligned pointer ptr, encoded with 0x03 tag, accessing the car field in the hypothetical cons struct above, becomes *((ptr - 3) + 4), which constant-folds to *(ptr + 1). AFIAK, there is no difference in instruction time between *(ptr + 4) and *(ptr + 1). However, on some RISC architectures such may not the case.

As others have pointed out, all tag schemes have trade-offs. A trade-off for using non-zero bits for pointers might mean extra tag removal when communicating pointers to low-level code, e.g. C libraries. Fixed-size tags would likely simplify code and allow additional values besides small integers to be immediate values.

I would encode Symbols like every other allocated object.

— Kurt

Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.

Primary links

Syndicate

Syndicate content

Browse archives

« September 2010  
Mo Tu We Th Fr Sa Su
    1 2 3 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30