Fix vm signed xor (#10519)

* fix #10482

* undo changes

* fix for bitwise not

* remove dead opcode
This commit is contained in:
Arne Döring
2019-02-01 12:12:10 +01:00
committed by Andreas Rumpf
parent 1d5437e9d2
commit b80dbdb77d
2 changed files with 16 additions and 7 deletions

View File

@@ -1009,7 +1009,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of mLtPtr, mLtU, mLtU64: genBinaryABC(c, n, dest, opcLtu)
of mEqProc, mEqRef, mEqUntracedRef:
genBinaryABC(c, n, dest, opcEqRef)
of mXor: genBinaryABCnarrowU(c, n, dest, opcXor)
of mXor: genBinaryABC(c, n, dest, opcXor)
of mNot: genUnaryABC(c, n, dest, opcNot)
of mUnaryMinusI, mUnaryMinusI64:
genUnaryABC(c, n, dest, opcUnaryMinusInt)
@@ -1018,7 +1018,10 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
of mUnaryPlusI, mUnaryPlusF64: gen(c, n.sons[1], dest)
of mBitnotI:
genUnaryABC(c, n, dest, opcBitnotInt)
genNarrowU(c, n, dest)
#genNarrowU modified, do not narrow signed types
let t = skipTypes(n.typ, abstractVar-{tyTypeDesc})
if t.kind in {tyUInt8..tyUInt32} or (t.kind == tyUInt and t.size < 8):
c.gABC(n, opcNarrowU, dest, TRegister(t.size*8))
of mToFloat, mToBiggestFloat, mToInt,
mToBiggestInt, mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr,
mFloatToStr, mCStrToStr, mStrToStr, mEnumToStr:

View File

@@ -7,25 +7,29 @@ import strutils
const x = [1'i32, -1, -10, 10, -10, 10, -20, 30, -40, 50, 7 shl 28, -(7 shl 28), 7 shl 28, -(7 shl 28)]
const y = [-1'i32, 1, -10, -10, 10, 10, -20, -30, 40, 50, 1 shl 30, 1 shl 30, -(1 shl 30), -(1 shl 30)]
const res_xor = block:
var tmp: seq[int64]
for i in 0..<x.len:
for i in 0 ..< x.len:
tmp.add(int64(x[i] xor y[i]))
tmp
const res_and = block:
var tmp: seq[int64]
for i in 0..<x.len:
for i in 0 ..< x.len:
tmp.add(int64(x[i] and y[i]))
tmp
const res_or = block:
var tmp: seq[int64]
for i in 0..<x.len:
for i in 0 ..< x.len:
tmp.add(int64(x[i] or y[i]))
tmp
const res_not = block:
var tmp: seq[int64]
for i in 0 ..< x.len:
tmp.add(not x[i])
tmp
let xx = x
let yy = y
@@ -34,6 +38,8 @@ for i in 0..<xx.len:
let z_xor = int64(xx[i] xor yy[i])
let z_and = int64(xx[i] and yy[i])
let z_or = int64(xx[i] or yy[i])
let z_not = int64(not xx[i])
doAssert(z_xor == res_xor[i], $i & ": " & $res_xor[i] & " " & $z_xor)
doAssert(z_and == res_and[i], $i & ": " & $res_and[i] & " " & $z_and)
doAssert(z_or == res_or[i], $i & ": " & $res_or[i] & " " & $z_or)
doAssert(z_not == res_not[i], $i & ": " & $res_not[i] & " " & $z_not)