Vm fix zero extend proc ze/ze64 && toU32/toU16/toU8 (#5988)

* fixes ze/ze64 procs in VM.
* fixes toU8/toU16/toU32.
* add tests for ze/ze64 toU32/toU16/toU8 procs
This commit is contained in:
Parashurama 2017-08-03 10:58:45 +02:00 • committed by Andreas Rumpf
commit f063943d5f
4 changed files with 73 additions and 3 deletions

View file

@ -1483,6 +1483,17 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
createStrKeepNode(regs[ra])
if regs[ra].node.strVal.isNil: regs[ra].node.strVal = newStringOfCap(1000)
storeAny(regs[ra].node.strVal, typ, regs[rb].regToNode)
of opcToNarrowInt:
decodeBC(rkInt)
let mask = (1'i64 shl rc) - 1 # 0xFF
let signbit = 1'i64 shl (rc - 1) # 0x80
let toggle = mask - signbit # 0x7F
# algorithm: -((i8 and 0xFF) xor 0x7F) + 0x7F
# mask off higher bits.
# uses two's complement to sign-extend integer.
# reajust integer into desired range.
regs[ra].intVal = -((regs[rb].intVal and mask) xor toggle) + toggle
inc pc
proc execute(c: PCtx, start: int): PNode =