diff options
-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 | ||||
-rw-r--r-- | lib/system.nim | 59 | ||||
-rw-r--r-- | lib/system/jssys.nim | 33 |
10 files changed, 76 insertions, 116 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) diff --git a/lib/system.nim b/lib/system.nim index 11c91533c..d6f117d39 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -1116,7 +1116,64 @@ proc chr*(u: range[0..255]): char {.magic: "Chr", noSideEffect.} # -------------------------------------------------------------------------- # built-in operators -when not defined(JS): +when defined(nimNoZeroExtendMagic): + proc ze*(x: int8): int = + ## zero extends a smaller integer type to ``int``. This treats `x` as + ## unsigned. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + + cast[int](uint(cast[uint8](x))) + + proc ze*(x: int16): int = + ## zero extends a smaller integer type to ``int``. This treats `x` as + ## unsigned. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int](uint(cast[uint16](x))) + + proc ze64*(x: int8): int64 = + ## zero extends a smaller integer type to ``int64``. This treats `x` as + ## unsigned. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int64](uint64(cast[uint8](x))) + + proc ze64*(x: int16): int64 = + ## zero extends a smaller integer type to ``int64``. This treats `x` as + ## unsigned. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int64](uint64(cast[uint16](x))) + + proc ze64*(x: int32): int64 = + ## zero extends a smaller integer type to ``int64``. This treats `x` as + ## unsigned. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int64](uint64(cast[uint32](x))) + + proc ze64*(x: int): int64 = + ## zero extends a smaller integer type to ``int64``. This treats `x` as + ## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``. + ## (This is the case on 64 bit processors.) + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int64](uint64(cast[uint](x))) + + proc toU8*(x: int): int8 = + ## treats `x` as unsigned and converts it to a byte by taking the last 8 bits + ## from `x`. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int8](x) + + proc toU16*(x: int): int16 = + ## treats `x` as unsigned and converts it to an ``int16`` by taking the last + ## 16 bits from `x`. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int16](x) + + proc toU32*(x: int64): int32 = + ## treats `x` as unsigned and converts it to an ``int32`` by taking the + ## last 32 bits from `x`. + ## **Deprecated since version 0.19.9**: Use unsigned integers instead. + cast[int32](x) + +elif not defined(JS): proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect, deprecated.} ## zero extends a smaller integer type to ``int``. This treats `x` as ## unsigned. diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 27dd9b020..077c81d59 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -475,26 +475,27 @@ proc absInt(a: int): int {.compilerproc.} = proc absInt64(a: int64): int64 {.compilerproc.} = result = if a < 0: a*(-1) else: a -proc ze*(a: int): int {.compilerproc.} = - result = a +when not defined(nimNoZeroExtendMagic): + proc ze*(a: int): int {.compilerproc.} = + result = a -proc ze64*(a: int64): int64 {.compilerproc.} = - result = a + proc ze64*(a: int64): int64 {.compilerproc.} = + result = a -proc toU8*(a: int): int8 {.asmNoStackFrame, compilerproc.} = - asm """ - return `a`; - """ + proc toU8*(a: int): int8 {.asmNoStackFrame, compilerproc.} = + asm """ + return `a`; + """ -proc toU16*(a: int): int16 {.asmNoStackFrame, compilerproc.} = - asm """ - return `a`; - """ + proc toU16*(a: int): int16 {.asmNoStackFrame, compilerproc.} = + asm """ + return `a`; + """ -proc toU32*(a: int64): int32 {.asmNoStackFrame, compilerproc.} = - asm """ - return `a`; - """ + proc toU32*(a: int64): int32 {.asmNoStackFrame, compilerproc.} = + asm """ + return `a`; + """ proc nimMin(a, b: int): int {.compilerproc.} = return if a <= b: a else: b proc nimMax(a, b: int): int {.compilerproc.} = return if a >= b: a else: b |