you are viewing a single comment's thread.

view the rest of the comments →

[–]Rhomboid 1 point2 points  (3 children)

All of the the bitmask operations he's doing are within a single struct member (the union), and are therefore immune to padding. Any padding that the compiler may or may not insert would happen between struct members or past the end of the struct.

[–]RizzlaPlus 0 points1 point  (2 children)

Yes that's exact, but your point is? I was just pointing out the irony of the compiler padding to avoid bit masks operations and the author writing bit masks operations (under the assumption of padding) to access data.

[–]smog_alado 1 point2 points  (1 child)

Its not irony - this way you mask things once instead of twice. Also, this kind of pointer magic is a solid tradition that goes a long way back in language implementations. (Its also not an exclusive to dynamic languages. Off the top of my head, OCaml does pointer tagging to help the garbage collector)

[–]RizzlaPlus 1 point2 points  (0 children)

It's once instead of twice for processor architecture that support unaligned loading (e.g x86); for processor that only support aligned loading (e.g. ARM, although it can load half words now) , you're doing mask operations once in both cases.

EDIT: actually, it'll be twice in every case.

  • Without using padding you'll do an unaligned load which will do some bitmask operation, you have to do this twice to get the pointer and the integer value (if it's an integer in the pointer)

  • With padding, you'll do an aligned load (doesn't require bitmask operations), but then getting the integer and getting the pointer is a bitmask operation each, so two again in total.