fix VM intsize for 32bits and smaller targetOS. (#6211)
This commit change the default behaviour of VM int/uint always being 64bits and make int/uint on VM behave identically to compiled code. This insert 'opcNarrowU' or 'opcNarrow' opcode on Int/Uint operations when needed to simulate smaller Int/Uint on VM.
This commit is contained in:
parent
11082180b7
commit
4fdf7f2ea3
1 changed files with 4 additions and 3 deletions
|
|
@ -656,16 +656,17 @@ proc genNarrow(c: PCtx; n: PNode; dest: TDest) =
|
||||||
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
|
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
|
||||||
# uint is uint64 in the VM, we we only need to mask the result for
|
# uint is uint64 in the VM, we we only need to mask the result for
|
||||||
# other unsigned types:
|
# other unsigned types:
|
||||||
if t.kind in {tyUInt8..tyUInt32}:
|
if t.kind in {tyUInt8..tyUInt32} or (t.kind == tyUInt and t.size < 8):
|
||||||
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
|
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
|
||||||
elif t.kind in {tyInt8..tyInt32}:
|
elif t.kind in {tyInt8..tyInt32} or (t.kind == tyInt and t.size < 8):
|
||||||
c.gABC(n, opcNarrowS, dest, TRegister(t.size*8))
|
c.gABC(n, opcNarrowS, dest, TRegister(t.size*8))
|
||||||
|
|
||||||
proc genNarrowU(c: PCtx; n: PNode; dest: TDest) =
|
proc genNarrowU(c: PCtx; n: PNode; dest: TDest) =
|
||||||
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
|
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
|
||||||
# uint is uint64 in the VM, we we only need to mask the result for
|
# uint is uint64 in the VM, we we only need to mask the result for
|
||||||
# other unsigned types:
|
# other unsigned types:
|
||||||
if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32}:
|
if t.kind in {tyUInt8..tyUInt32, tyInt8..tyInt32} or
|
||||||
|
(t.kind in {tyUInt, tyInt} and t.size < 8):
|
||||||
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
|
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
|
||||||
|
|
||||||
proc genBinaryABCnarrow(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) =
|
proc genBinaryABCnarrow(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue