diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-06-24 09:19:02 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-06-24 09:19:02 +0200 |
commit | e90d91f0e463e870c49a7558d216fff03a581949 (patch) | |
tree | ebfaa523ffaf0545e4bf3c2bf334250f7efa1b9d /compiler | |
parent | 800bc661b674c071e829b8a959c0966a38ae710e (diff) | |
download | Nim-e90d91f0e463e870c49a7558d216fff03a581949.tar.gz |
[refactoring] remove zeroExtend and friends from the compiler builtins. (#11531)
* remove zeroExtend and friends from the compiler builtins. * fix jssys
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 8 | ||||
-rw-r--r-- | compiler/ccgexprs.nim | 41 | ||||
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/jsgen.nim | 18 | ||||
-rw-r--r-- | compiler/semfold.nim | 6 | ||||
-rw-r--r-- | compiler/vm.nim | 10 | ||||
-rw-r--r-- | compiler/vmdef.nim | 1 | ||||
-rw-r--r-- | compiler/vmgen.nim | 15 |
8 files changed, 1 insertions, 99 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index d6ab06ec7..c8ce0dccb 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -621,10 +621,6 @@ type mUnaryMinusI, mUnaryMinusI64, mAbsI, mNot, mUnaryPlusI, mBitnotI, mUnaryPlusF64, mUnaryMinusF64, mAbsF64, - mZe8ToI, mZe8ToI64, - mZe16ToI, mZe16ToI64, - mZe32ToI64, mZeIToI64, - mToU8, mToU16, mToU32, mToFloat, mToBiggestFloat, mToInt, mToBiggestInt, mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mFloatToStr, mCStrToStr, @@ -695,10 +691,6 @@ const mEqRef, mEqProc, mEqUntracedRef, mLePtr, mLtPtr, mEqCString, mXor, mUnaryMinusI, mUnaryMinusI64, mAbsI, mNot, mUnaryPlusI, mBitnotI, mUnaryPlusF64, mUnaryMinusF64, mAbsF64, - mZe8ToI, mZe8ToI64, - mZe16ToI, mZe16ToI64, - mZe32ToI64, mZeIToI64, - mToU8, mToU16, mToU32, mToFloat, mToBiggestFloat, mToInt, mToBiggestInt, mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mFloatToStr, mCStrToStr, diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 2d434748c..f3eb71bdc 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -639,28 +639,6 @@ proc genIsNil(p: BProc, e: PNode, d: var TLoc) = unaryExpr(p, e, d, "($1 == 0)") proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = - const - unArithTab: array[mNot..mToBiggestInt, string] = [ - "!($1)", # Not - "$1", # UnaryPlusI - "($3)((NU$2) ~($1))", # BitnotI - "$1", # UnaryPlusF64 - "-($1)", # UnaryMinusF64 - "($1 < 0? -($1) : ($1))", # AbsF64; BUGFIX: fabs() makes problems - # for Tiny C, so we don't use it - "(($3)(NU)(NU8)($1))", # mZe8ToI - "(($3)(NU64)(NU8)($1))", # mZe8ToI64 - "(($3)(NU)(NU16)($1))", # mZe16ToI - "(($3)(NU64)(NU16)($1))", # mZe16ToI64 - "(($3)(NU64)(NU32)($1))", # mZe32ToI64 - "(($3)(NU64)(NU)($1))", # mZeIToI64 - "(($3)(NU8)(NU)($1))", # ToU8 - "(($3)(NU16)(NU)($1))", # ToU16 - "(($3)(NU32)(NU64)($1))", # ToU32 - "((double) ($1))", # ToFloat - "((double) ($1))", # ToBiggestFloat - "float64ToInt32($1)", # ToInt - "float64ToInt64($1)"] # ToBiggestInt var a: TLoc t: PType @@ -671,7 +649,6 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = template applyFormat(frmt: untyped) = putIntoDest(p, d, e, frmt % [rdLoc(a), rope(getSize(p.config, t) * 8), getSimpleTypeDesc(p.module, e.typ)]) - case op of mNot: applyFormat("!($1)") @@ -686,24 +663,6 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mAbsF64: applyFormat("($1 < 0? -($1) : ($1))") # BUGFIX: fabs() makes problems for Tiny C - of mZe8ToI: - applyFormat("(($3)(NU)(NU8)($1))") - of mZe8ToI64: - applyFormat("(($3)(NU64)(NU8)($1))") - of mZe16ToI: - applyFormat("(($3)(NU)(NU16)($1))") - of mZe16ToI64: - applyFormat("(($3)(NU64)(NU16)($1))") - of mZe32ToI64: - applyFormat("(($3)(NU64)(NU32)($1))") - of mZeIToI64: - applyFormat("(($3)(NU64)(NU)($1))") - of mToU8: - applyFormat("(($3)(NU8)(NU)($1))") - of mToU16: - applyFormat("(($3)(NU16)(NU)($1))") - of mToU32: - applyFormat("(($3)(NU32)(NU64)($1))") of mToFloat: applyFormat("((double) ($1))") of mToBiggestFloat: diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index c8f3dede5..e984816b5 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -86,6 +86,7 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimHasSignatureHashInMacro") defineSymbol("nimHasDefault") defineSymbol("nimMacrosSizealignof") + defineSymbol("nimNoZeroExtendMagic") for f in low(Feature)..high(Feature): defineSymbol("nimHas" & $f) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 5387631dc..b60f2c5e9 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -431,15 +431,6 @@ const # magic checked op; magic unchecked op; ["", ""], # UnaryPlusF64 ["", ""], # UnaryMinusF64 ["", ""], # AbsF64 - ["Ze8ToI", "Ze8ToI"], # mZe8ToI - ["Ze8ToI64", "Ze8ToI64"], # mZe8ToI64 - ["Ze16ToI", "Ze16ToI"], # mZe16ToI - ["Ze16ToI64", "Ze16ToI64"], # mZe16ToI64 - ["Ze32ToI64", "Ze32ToI64"], # mZe32ToI64 - ["ZeIToI64", "ZeIToI64"], # mZeIToI64 - ["toU8", "toU8"], # toU8 - ["toU16", "toU16"], # toU16 - ["toU32", "toU32"], # toU32 ["", ""], # ToFloat ["", ""], # ToBiggestFloat ["", ""], # ToInt @@ -621,15 +612,6 @@ proc arithAux(p: PProc, n: PNode, r: var TCompRes, op: TMagic) = of mUnaryPlusF64: applyFormat("+($1)", "+($1)") of mUnaryMinusF64: applyFormat("-($1)", "-($1)") of mAbsF64: applyFormat("Math.abs($1)", "Math.abs($1)") - of mZe8ToI: applyFormat("Ze8ToI($1)", "Ze8ToI($1)") - of mZe8ToI64: applyFormat("Ze8ToI64($1)", "Ze8ToI64($1)") - of mZe16ToI: applyFormat("Ze16ToI($1)", "Ze16ToI($1)") - of mZe16ToI64: applyFormat("Ze16ToI64($1)", "Ze16ToI64($1)") - of mZe32ToI64: applyFormat("Ze32ToI64($1)", "Ze32ToI64($1)") - of mZeIToI64: applyFormat("ZeIToI64($1)", "ZeIToI64($1)") - of mtoU8: applyFormat("toU8($1)", "toU8($1)") - of mtoU16: applyFormat("toU16($1)", "toU16($1)") - of mtoU32: applyFormat("toU32($1)", "toU32($1)") of mToFloat: applyFormat("$1", "$1") of mToBiggestFloat: applyFormat("$1", "$1") of mToInt: applyFormat("Math.trunc($1)", "Math.trunc($1)") diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 3957baef4..8c4e6431f 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -219,12 +219,6 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode = of mToInt, mToBiggestInt: result = newIntNodeT(system.toInt(getFloat(a)), n, g) of mAbsF64: result = newFloatNodeT(abs(getFloat(a)), n, g) of mAbsI: result = foldAbs(getInt(a), n, g) - of mZe8ToI, mZe8ToI64, mZe16ToI, mZe16ToI64, mZe32ToI64, mZeIToI64: - # byte(-128) = 1...1..1000_0000'64 --> 0...0..1000_0000'64 - result = newIntNodeT(getInt(a) and (`shl`(1, getSize(g.config, a.typ) * 8) - 1), n, g) - of mToU8: result = newIntNodeT(getInt(a) and 0x000000FF, n, g) - of mToU16: result = newIntNodeT(getInt(a) and 0x0000FFFF, n, g) - of mToU32: result = newIntNodeT(getInt(a) and 0x00000000FFFFFFFF'i64, n, g) of mUnaryLt: result = doAndFit(foldSub(getOrdValue(a), 1, n, g)) of mSucc: result = doAndFit(foldAdd(getOrdValue(a), getInt(b), n, g)) of mPred: result = doAndFit(foldSub(getOrdValue(a), getInt(b), n, g)) diff --git a/compiler/vm.nim b/compiler/vm.nim index a2af0e7b8..2919e865a 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1905,16 +1905,6 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = when not defined(nimNoNilSeqs): if regs[ra].node.strVal.isNil: regs[ra].node.strVal = newStringOfCap(1000) storeAny(regs[ra].node.strVal, typ, regs[rb].regToNode, c.config) - 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 diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim index 608f20526..723863ca7 100644 --- a/compiler/vmdef.nim +++ b/compiler/vmdef.nim @@ -149,7 +149,6 @@ type opcSetType, # dest.typ = types[Bx] opcTypeTrait, opcMarshalLoad, opcMarshalStore, - opcToNarrowInt, opcSymOwner, opcSymIsInstantiationOf diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index de314a552..08d79bbb7 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1061,21 +1061,6 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = mToBiggestInt, mCharToStr, mBoolToStr, mIntToStr, mInt64ToStr, mFloatToStr, mCStrToStr, mStrToStr, mEnumToStr: genConv(c, n, n.sons[1], dest) - of mZe8ToI, mZe8ToI64, mZe16ToI, mZe16ToI64, mZe32ToI64, mZeIToI64: - #genNarrowU modified - let t = skipTypes(n.sons[1].typ, abstractVar-{tyTypeDesc}) - let tmp = c.genx(n.sons[1]) - c.gABC(n, opcNarrowU, tmp, TRegister(t.size*8)) - # assign result to dest register - if dest < 0: dest = c.getTemp(n.typ) - c.gABC(n, opcAsgnInt, dest, tmp) - c.freeTemp(tmp) - of mToU8, mToU16, mToU32: - let t = skipTypes(n.typ, abstractVar-{tyTypeDesc}) - var tmp = c.genx(n.sons[1]) - if dest < 0: dest = c.getTemp(n.typ) - c.gABC(n, opcToNarrowInt, dest, tmp, TRegister(t.size*8)) - c.freeTemp(tmp) of mEqStr, mEqCString: genBinaryABC(c, n, dest, opcEqStr) of mLeStr: genBinaryABC(c, n, dest, opcLeStr) of mLtStr: genBinaryABC(c, n, dest, opcLtStr) |