union in the c programming language. The following should be taken
literally, and assume always a little-endian layout:
+ #pragma pack
typedef union {
uint8_t b[];
uint16_t s[];
get_polymorphed_reg(reg, bitwidth, offset):
el_reg_t res;
res.l = 0; // TODO: going to need sign-extending / zero-extending
+ if !reg.isvec: // scalar has no element offset
+ offset = 0
if bitwidth == 8:
reg.b = int_regfile[reg].b[offset]
elif bitwidth == 16:
reg.i = int_regfile[reg].i[offset]
elif bitwidth == 64:
reg.l = int_regfile[reg].l[offset]
- return res
+ return res & bytemask
set_polymorphed_reg(reg, bitwidth, offset, val):
if (!reg.isvec):
- # not a vector: first element only, overwrites high bits
+ # for safety mask out hi bits
+ bytemask = (8 << bitwidth) - 1
+ val &= bytemask
+ # not a vector: first element only, overwrites high bits.
+ # and with the *Architectural* definition being LE,
+ # storing in the first DWORD works perfectly.
int_regfile[reg].l[0] = val
elif bitwidth == 8:
int_regfile[reg].b[offset] = val