fix operators containing percent for VM usage (#13536)
* fixes #13513 * merge tarithmetics in tarithm
This commit is contained in:
parent
e64f1c7ee4
commit
2f557652d4
11 changed files with 165 additions and 137 deletions
|
|
@ -617,7 +617,6 @@ type
|
||||||
mEqI, mLeI, mLtI,
|
mEqI, mLeI, mLtI,
|
||||||
mEqF64, mLeF64, mLtF64,
|
mEqF64, mLeF64, mLtF64,
|
||||||
mLeU, mLtU,
|
mLeU, mLtU,
|
||||||
mLeU64, mLtU64,
|
|
||||||
mEqEnum, mLeEnum, mLtEnum,
|
mEqEnum, mLeEnum, mLtEnum,
|
||||||
mEqCh, mLeCh, mLtCh,
|
mEqCh, mLeCh, mLtCh,
|
||||||
mEqB, mLeB, mLtB,
|
mEqB, mLeB, mLtB,
|
||||||
|
|
@ -687,7 +686,6 @@ const
|
||||||
mEqI, mLeI, mLtI,
|
mEqI, mLeI, mLtI,
|
||||||
mEqF64, mLeF64, mLtF64,
|
mEqF64, mLeF64, mLtF64,
|
||||||
mLeU, mLtU,
|
mLeU, mLtU,
|
||||||
mLeU64, mLtU64,
|
|
||||||
mEqEnum, mLeEnum, mLtEnum,
|
mEqEnum, mLeEnum, mLtEnum,
|
||||||
mEqCh, mLeCh, mLtCh,
|
mEqCh, mLeCh, mLtCh,
|
||||||
mEqB, mLeB, mLtB,
|
mEqB, mLeB, mLtB,
|
||||||
|
|
|
||||||
|
|
@ -605,8 +605,6 @@ proc binaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
of mLtF64: applyFormat("($1 < $2)")
|
of mLtF64: applyFormat("($1 < $2)")
|
||||||
of mLeU: applyFormat("((NU$3)($1) <= (NU$3)($2))")
|
of mLeU: applyFormat("((NU$3)($1) <= (NU$3)($2))")
|
||||||
of mLtU: applyFormat("((NU$3)($1) < (NU$3)($2))")
|
of mLtU: applyFormat("((NU$3)($1) < (NU$3)($2))")
|
||||||
of mLeU64: applyFormat("((NU64)($1) <= (NU64)($2))")
|
|
||||||
of mLtU64: applyFormat("((NU64)($1) < (NU64)($2))")
|
|
||||||
of mEqEnum: applyFormat("($1 == $2)")
|
of mEqEnum: applyFormat("($1 == $2)")
|
||||||
of mLeEnum: applyFormat("($1 <= $2)")
|
of mLeEnum: applyFormat("($1 <= $2)")
|
||||||
of mLtEnum: applyFormat("($1 < $2)")
|
of mLtEnum: applyFormat("($1 < $2)")
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ import ast, astalgo
|
||||||
|
|
||||||
const
|
const
|
||||||
someCmp = {mEqI, mEqF64, mEqEnum, mEqCh, mEqB, mEqRef, mEqProc,
|
someCmp = {mEqI, mEqF64, mEqEnum, mEqCh, mEqB, mEqRef, mEqProc,
|
||||||
mLeI, mLeF64, mLeU, mLeU64, mLeEnum,
|
mLeI, mLeF64, mLeU, mLeEnum,
|
||||||
mLeCh, mLeB, mLePtr, mLtI, mLtF64, mLtU, mLtU64, mLtEnum,
|
mLeCh, mLeB, mLePtr, mLtI, mLtF64, mLtU, mLtEnum,
|
||||||
mLtCh, mLtB, mLtPtr}
|
mLtCh, mLtB, mLtPtr}
|
||||||
|
|
||||||
proc isCounter(s: PSym): bool {.inline.} =
|
proc isCounter(s: PSym): bool {.inline.} =
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ const
|
||||||
mEqStr, mEqSet, mEqCString}
|
mEqStr, mEqSet, mEqCString}
|
||||||
|
|
||||||
# set excluded here as the semantics are vastly different:
|
# set excluded here as the semantics are vastly different:
|
||||||
someLe = {mLeI, mLeF64, mLeU, mLeU64, mLeEnum,
|
someLe = {mLeI, mLeF64, mLeU, mLeEnum,
|
||||||
mLeCh, mLeB, mLePtr, mLeStr}
|
mLeCh, mLeB, mLePtr, mLeStr}
|
||||||
someLt = {mLtI, mLtF64, mLtU, mLtU64, mLtEnum,
|
someLt = {mLtI, mLtF64, mLtU, mLtEnum,
|
||||||
mLtCh, mLtB, mLtPtr, mLtStr}
|
mLtCh, mLtB, mLtPtr, mLtStr}
|
||||||
|
|
||||||
someLen = {mLengthOpenArray, mLengthStr, mLengthArray, mLengthSeq}
|
someLen = {mLengthOpenArray, mLengthStr, mLengthArray, mLengthSeq}
|
||||||
|
|
|
||||||
|
|
@ -371,69 +371,67 @@ type
|
||||||
const # magic checked op; magic unchecked op;
|
const # magic checked op; magic unchecked op;
|
||||||
jsMagics: TMagicOps = [
|
jsMagics: TMagicOps = [
|
||||||
mAddI: ["addInt", ""],
|
mAddI: ["addInt", ""],
|
||||||
["subInt", ""], # SubI
|
mSubI: ["subInt", ""],
|
||||||
["mulInt", ""], # MulI
|
mMulI: ["mulInt", ""],
|
||||||
["divInt", ""], # DivI
|
mDivI: ["divInt", ""],
|
||||||
["modInt", ""], # ModI
|
mModI: ["modInt", ""],
|
||||||
["addInt", ""], # Succ
|
mSucc: ["addInt", ""],
|
||||||
["subInt", ""], # Pred
|
mPred: ["subInt", ""],
|
||||||
["", ""], # AddF64
|
mAddF64: ["", ""],
|
||||||
["", ""], # SubF64
|
mSubF64: ["", ""],
|
||||||
["", ""], # MulF64
|
mMulF64: ["", ""],
|
||||||
["", ""], # DivF64
|
mDivF64: ["", ""],
|
||||||
["", ""], # ShrI
|
mShrI: ["", ""],
|
||||||
["", ""], # ShlI
|
mShlI: ["", ""],
|
||||||
["", ""], # AshrI
|
mAshrI: ["", ""],
|
||||||
["", ""], # BitandI
|
mBitandI: ["", ""],
|
||||||
["", ""], # BitorI
|
mBitorI: ["", ""],
|
||||||
["", ""], # BitxorI
|
mBitxorI: ["", ""],
|
||||||
["nimMin", "nimMin"], # MinI
|
mMinI: ["nimMin", "nimMin"],
|
||||||
["nimMax", "nimMax"], # MaxI
|
mMaxI: ["nimMax", "nimMax"],
|
||||||
["", ""], # addU
|
mAddU: ["", ""],
|
||||||
["", ""], # subU
|
mSubU: ["", ""],
|
||||||
["", ""], # mulU
|
mMulU: ["", ""],
|
||||||
["", ""], # divU
|
mDivU: ["", ""],
|
||||||
["", ""], # modU
|
mModU: ["", ""],
|
||||||
["", ""], # EqI
|
mEqI: ["", ""],
|
||||||
["", ""], # LeI
|
mLeI: ["", ""],
|
||||||
["", ""], # LtI
|
mLtI: ["", ""],
|
||||||
["", ""], # EqF64
|
mEqF64: ["", ""],
|
||||||
["", ""], # LeF64
|
mLeF64: ["", ""],
|
||||||
["", ""], # LtF64
|
mLtF64: ["", ""],
|
||||||
["", ""], # leU
|
mLeU: ["", ""],
|
||||||
["", ""], # ltU
|
mLtU: ["", ""],
|
||||||
["", ""], # leU64
|
mEqEnum: ["", ""],
|
||||||
["", ""], # ltU64
|
mLeEnum: ["", ""],
|
||||||
["", ""], # EqEnum
|
mLtEnum: ["", ""],
|
||||||
["", ""], # LeEnum
|
mEqCh: ["", ""],
|
||||||
["", ""], # LtEnum
|
mLeCh: ["", ""],
|
||||||
["", ""], # EqCh
|
mLtCh: ["", ""],
|
||||||
["", ""], # LeCh
|
mEqB: ["", ""],
|
||||||
["", ""], # LtCh
|
mLeB: ["", ""],
|
||||||
["", ""], # EqB
|
mLtB: ["", ""],
|
||||||
["", ""], # LeB
|
mEqRef: ["", ""],
|
||||||
["", ""], # LtB
|
mLePtr: ["", ""],
|
||||||
["", ""], # EqRef
|
mLtPtr: ["", ""],
|
||||||
["", ""], # LePtr
|
mXor: ["", ""],
|
||||||
["", ""], # LtPtr
|
mEqCString: ["", ""],
|
||||||
["", ""], # Xor
|
mEqProc: ["", ""],
|
||||||
["", ""], # EqCString
|
mUnaryMinusI: ["negInt", ""],
|
||||||
["", ""], # EqProc
|
mUnaryMinusI64: ["negInt64", ""],
|
||||||
["negInt", ""], # UnaryMinusI
|
mAbsI: ["absInt", ""],
|
||||||
["negInt64", ""], # UnaryMinusI64
|
mNot: ["", ""],
|
||||||
["absInt", ""], # AbsI
|
mUnaryPlusI: ["", ""],
|
||||||
["", ""], # Not
|
mBitnotI: ["", ""],
|
||||||
["", ""], # UnaryPlusI
|
mUnaryPlusF64: ["", ""],
|
||||||
["", ""], # BitnotI
|
mUnaryMinusF64: ["", ""],
|
||||||
["", ""], # UnaryPlusF64
|
mCharToStr: ["nimCharToStr", "nimCharToStr"],
|
||||||
["", ""], # UnaryMinusF64
|
mBoolToStr: ["nimBoolToStr", "nimBoolToStr"],
|
||||||
["nimCharToStr", "nimCharToStr"],
|
mIntToStr: ["cstrToNimstr", "cstrToNimstr"],
|
||||||
["nimBoolToStr", "nimBoolToStr"],
|
mInt64ToStr: ["cstrToNimstr", "cstrToNimstr"],
|
||||||
["cstrToNimstr", "cstrToNimstr"],
|
mFloatToStr: ["cstrToNimstr", "cstrToNimstr"],
|
||||||
["cstrToNimstr", "cstrToNimstr"],
|
mCStrToStr: ["cstrToNimstr", "cstrToNimstr"],
|
||||||
["cstrToNimstr", "cstrToNimstr"],
|
mStrToStr: ["", ""]]
|
||||||
["cstrToNimstr", "cstrToNimstr"],
|
|
||||||
["", ""]]
|
|
||||||
|
|
||||||
proc needsTemp(p: PProc; n: PNode): bool =
|
proc needsTemp(p: PProc; n: PNode): bool =
|
||||||
# check if n contains a call to determine
|
# check if n contains a call to determine
|
||||||
|
|
@ -575,8 +573,6 @@ proc arithAux(p: PProc, n: PNode, r: var TCompRes, op: TMagic) =
|
||||||
of mLtF64: applyFormat("($1 < $2)", "($1 < $2)")
|
of mLtF64: applyFormat("($1 < $2)", "($1 < $2)")
|
||||||
of mLeU: applyFormat("($1 <= $2)", "($1 <= $2)")
|
of mLeU: applyFormat("($1 <= $2)", "($1 <= $2)")
|
||||||
of mLtU: applyFormat("($1 < $2)", "($1 < $2)")
|
of mLtU: applyFormat("($1 < $2)", "($1 < $2)")
|
||||||
of mLeU64: applyFormat("($1 <= $2)", "($1 <= $2)")
|
|
||||||
of mLtU64: applyFormat("($1 < $2)", "($1 < $2)")
|
|
||||||
of mEqEnum: applyFormat("($1 == $2)", "($1 == $2)")
|
of mEqEnum: applyFormat("($1 == $2)", "($1 == $2)")
|
||||||
of mLeEnum: applyFormat("($1 <= $2)", "($1 <= $2)")
|
of mLeEnum: applyFormat("($1 <= $2)", "($1 <= $2)")
|
||||||
of mLtEnum: applyFormat("($1 < $2)", "($1 < $2)")
|
of mLtEnum: applyFormat("($1 < $2)", "($1 < $2)")
|
||||||
|
|
|
||||||
|
|
@ -288,9 +288,9 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; g: ModuleGraph): PNode =
|
||||||
of mLtStr: result = newIntNodeT(toInt128(ord(getStr(a) < getStr(b))), n, g)
|
of mLtStr: result = newIntNodeT(toInt128(ord(getStr(a) < getStr(b))), n, g)
|
||||||
of mLeStr: result = newIntNodeT(toInt128(ord(getStr(a) <= getStr(b))), n, g)
|
of mLeStr: result = newIntNodeT(toInt128(ord(getStr(a) <= getStr(b))), n, g)
|
||||||
of mEqStr: result = newIntNodeT(toInt128(ord(getStr(a) == getStr(b))), n, g)
|
of mEqStr: result = newIntNodeT(toInt128(ord(getStr(a) == getStr(b))), n, g)
|
||||||
of mLtU, mLtU64:
|
of mLtU:
|
||||||
result = newIntNodeT(toInt128(ord(`<%`(toInt64(getOrdValue(a)), toInt64(getOrdValue(b))))), n, g)
|
result = newIntNodeT(toInt128(ord(`<%`(toInt64(getOrdValue(a)), toInt64(getOrdValue(b))))), n, g)
|
||||||
of mLeU, mLeU64:
|
of mLeU:
|
||||||
result = newIntNodeT(toInt128(ord(`<=%`(toInt64(getOrdValue(a)), toInt64(getOrdValue(b))))), n, g)
|
result = newIntNodeT(toInt128(ord(`<=%`(toInt64(getOrdValue(a)), toInt64(getOrdValue(b))))), n, g)
|
||||||
of mBitandI, mAnd: result = newIntNodeT(bitand(a.getInt, b.getInt), n, g)
|
of mBitandI, mAnd: result = newIntNodeT(bitand(a.getInt, b.getInt), n, g)
|
||||||
of mBitorI, mOr: result = newIntNodeT(bitor(getInt(a), getInt(b)), n, g)
|
of mBitorI, mOr: result = newIntNodeT(bitor(getInt(a), getInt(b)), n, g)
|
||||||
|
|
|
||||||
|
|
@ -1071,8 +1071,8 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
|
||||||
of mEqF64: genBinaryABC(c, n, dest, opcEqFloat)
|
of mEqF64: genBinaryABC(c, n, dest, opcEqFloat)
|
||||||
of mLeF64: genBinaryABC(c, n, dest, opcLeFloat)
|
of mLeF64: genBinaryABC(c, n, dest, opcLeFloat)
|
||||||
of mLtF64: genBinaryABC(c, n, dest, opcLtFloat)
|
of mLtF64: genBinaryABC(c, n, dest, opcLtFloat)
|
||||||
of mLePtr, mLeU, mLeU64: genBinaryABC(c, n, dest, opcLeu)
|
of mLePtr, mLeU: genBinaryABC(c, n, dest, opcLeu)
|
||||||
of mLtPtr, mLtU, mLtU64: genBinaryABC(c, n, dest, opcLtu)
|
of mLtPtr, mLtU: genBinaryABC(c, n, dest, opcLtu)
|
||||||
of mEqProc, mEqRef:
|
of mEqProc, mEqRef:
|
||||||
genBinaryABC(c, n, dest, opcEqRef)
|
genBinaryABC(c, n, dest, opcEqRef)
|
||||||
of mXor: genBinaryABC(c, n, dest, opcXor)
|
of mXor: genBinaryABC(c, n, dest, opcXor)
|
||||||
|
|
|
||||||
|
|
@ -342,45 +342,6 @@ proc `xor`*(x, y: int16): int16 {.magic: "BitxorI", noSideEffect.}
|
||||||
proc `xor`*(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.}
|
||||||
proc `xor`*(x, y: int64): int64 {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int64): int64 {.magic: "BitxorI", noSideEffect.}
|
||||||
|
|
||||||
type
|
|
||||||
IntMax32 = int|int8|int16|int32
|
|
||||||
|
|
||||||
proc `+%`*(x, y: IntMax32): IntMax32 {.magic: "AddU", noSideEffect.}
|
|
||||||
proc `+%`*(x, y: int64): int64 {.magic: "AddU", noSideEffect.}
|
|
||||||
## Treats `x` and `y` as unsigned and adds them.
|
|
||||||
##
|
|
||||||
## The result is truncated to fit into the result.
|
|
||||||
## This implements modulo arithmetic. No overflow errors are possible.
|
|
||||||
|
|
||||||
proc `-%`*(x, y: IntMax32): IntMax32 {.magic: "SubU", noSideEffect.}
|
|
||||||
proc `-%`*(x, y: int64): int64 {.magic: "SubU", noSideEffect.}
|
|
||||||
## Treats `x` and `y` as unsigned and subtracts them.
|
|
||||||
##
|
|
||||||
## The result is truncated to fit into the result.
|
|
||||||
## This implements modulo arithmetic. No overflow errors are possible.
|
|
||||||
|
|
||||||
proc `*%`*(x, y: IntMax32): IntMax32 {.magic: "MulU", noSideEffect.}
|
|
||||||
proc `*%`*(x, y: int64): int64 {.magic: "MulU", noSideEffect.}
|
|
||||||
## Treats `x` and `y` as unsigned and multiplies them.
|
|
||||||
##
|
|
||||||
## The result is truncated to fit into the result.
|
|
||||||
## This implements modulo arithmetic. No overflow errors are possible.
|
|
||||||
|
|
||||||
proc `/%`*(x, y: IntMax32): IntMax32 {.magic: "DivU", noSideEffect.}
|
|
||||||
proc `/%`*(x, y: int64): int64 {.magic: "DivU", noSideEffect.}
|
|
||||||
## Treats `x` and `y` as unsigned and divides them.
|
|
||||||
##
|
|
||||||
## The result is truncated to fit into the result.
|
|
||||||
## This implements modulo arithmetic. No overflow errors are possible.
|
|
||||||
|
|
||||||
proc `%%`*(x, y: IntMax32): IntMax32 {.magic: "ModU", noSideEffect.}
|
|
||||||
proc `%%`*(x, y: int64): int64 {.magic: "ModU", noSideEffect.}
|
|
||||||
## Treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
|
|
||||||
##
|
|
||||||
## The result is truncated to fit into the result.
|
|
||||||
## This implements modulo arithmetic. No overflow errors are possible.
|
|
||||||
|
|
||||||
|
|
||||||
# unsigned integer operations:
|
# unsigned integer operations:
|
||||||
proc `not`*(x: uint): uint {.magic: "BitnotI", noSideEffect.}
|
proc `not`*(x: uint): uint {.magic: "BitnotI", noSideEffect.}
|
||||||
## Computes the `bitwise complement` of the integer `x`.
|
## Computes the `bitwise complement` of the integer `x`.
|
||||||
|
|
@ -461,8 +422,60 @@ proc `mod`*(x, y: uint16): uint16 {.magic: "ModU", noSideEffect.}
|
||||||
proc `mod`*(x, y: uint32): uint32 {.magic: "ModU", noSideEffect.}
|
proc `mod`*(x, y: uint32): uint32 {.magic: "ModU", noSideEffect.}
|
||||||
proc `mod`*(x, y: uint64): uint64 {.magic: "ModU", noSideEffect.}
|
proc `mod`*(x, y: uint64): uint64 {.magic: "ModU", noSideEffect.}
|
||||||
|
|
||||||
|
proc `+%`*(x, y: int): int {.inline.} =
|
||||||
|
## Treats `x` and `y` as unsigned and adds them.
|
||||||
|
##
|
||||||
|
## The result is truncated to fit into the result.
|
||||||
|
## This implements modulo arithmetic. No overflow errors are possible.
|
||||||
|
cast[int](cast[uint](x) + cast[uint](y))
|
||||||
|
proc `+%`*(x, y: int8): int8 {.inline.} = cast[int8](cast[uint8](x) + cast[uint8](y))
|
||||||
|
proc `+%`*(x, y: int16): int16 {.inline.} = cast[int16](cast[uint16](x) + cast[uint16](y))
|
||||||
|
proc `+%`*(x, y: int32): int32 {.inline.} = cast[int32](cast[uint32](x) + cast[uint32](y))
|
||||||
|
proc `+%`*(x, y: int64): int64 {.inline.} = cast[int64](cast[uint64](x) + cast[uint64](y))
|
||||||
|
|
||||||
|
proc `-%`*(x, y: int): int {.inline.} =
|
||||||
|
## Treats `x` and `y` as unsigned and subtracts them.
|
||||||
|
##
|
||||||
|
## The result is truncated to fit into the result.
|
||||||
|
## This implements modulo arithmetic. No overflow errors are possible.
|
||||||
|
cast[int](cast[uint](x) - cast[uint](y))
|
||||||
|
proc `-%`*(x, y: int8): int8 {.inline.} = cast[int8](cast[uint8](x) - cast[uint8](y))
|
||||||
|
proc `-%`*(x, y: int16): int16 {.inline.} = cast[int16](cast[uint16](x) - cast[uint16](y))
|
||||||
|
proc `-%`*(x, y: int32): int32 {.inline.} = cast[int32](cast[uint32](x) - cast[uint32](y))
|
||||||
|
proc `-%`*(x, y: int64): int64 {.inline.} = cast[int64](cast[uint64](x) - cast[uint64](y))
|
||||||
|
|
||||||
|
proc `*%`*(x, y: int): int {.inline.} =
|
||||||
|
## Treats `x` and `y` as unsigned and multiplies them.
|
||||||
|
##
|
||||||
|
## The result is truncated to fit into the result.
|
||||||
|
## This implements modulo arithmetic. No overflow errors are possible.
|
||||||
|
cast[int](cast[uint](x) * cast[uint](y))
|
||||||
|
proc `*%`*(x, y: int8): int8 {.inline.} = cast[int8](cast[uint8](x) * cast[uint8](y))
|
||||||
|
proc `*%`*(x, y: int16): int16 {.inline.} = cast[int16](cast[uint16](x) * cast[uint16](y))
|
||||||
|
proc `*%`*(x, y: int32): int32 {.inline.} = cast[int32](cast[uint32](x) * cast[uint32](y))
|
||||||
|
proc `*%`*(x, y: int64): int64 {.inline.} = cast[int64](cast[uint64](x) * cast[uint64](y))
|
||||||
|
|
||||||
|
proc `/%`*(x, y: int): int {.inline.} =
|
||||||
|
## Treats `x` and `y` as unsigned and divides them.
|
||||||
|
##
|
||||||
|
## The result is truncated to fit into the result.
|
||||||
|
## This implements modulo arithmetic. No overflow errors are possible.
|
||||||
|
cast[int](cast[uint](x) div cast[uint](y))
|
||||||
|
proc `/%`*(x, y: int8): int8 {.inline.} = cast[int8](cast[uint8](x) div cast[uint8](y))
|
||||||
|
proc `/%`*(x, y: int16): int16 {.inline.} = cast[int16](cast[uint16](x) div cast[uint16](y))
|
||||||
|
proc `/%`*(x, y: int32): int32 {.inline.} = cast[int32](cast[uint32](x) div cast[uint32](y))
|
||||||
|
proc `/%`*(x, y: int64): int64 {.inline.} = cast[int64](cast[uint64](x) div cast[uint64](y))
|
||||||
|
|
||||||
|
proc `%%`*(x, y: int): int {.inline.} =
|
||||||
|
## Treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
|
||||||
|
##
|
||||||
|
## The result is truncated to fit into the result.
|
||||||
|
## This implements modulo arithmetic. No overflow errors are possible.
|
||||||
|
cast[int](cast[uint](x) mod cast[uint](y))
|
||||||
|
proc `%%`*(x, y: int8): int8 {.inline.} = cast[int8](cast[uint8](x) mod cast[uint8](y))
|
||||||
|
proc `%%`*(x, y: int16): int16 {.inline.} = cast[int16](cast[uint16](x) mod cast[uint16](y))
|
||||||
|
proc `%%`*(x, y: int32): int32 {.inline.} = cast[int32](cast[uint32](x) mod cast[uint32](y))
|
||||||
|
proc `%%`*(x, y: int64): int64 {.inline.} = cast[int64](cast[uint64](x) mod cast[uint64](y))
|
||||||
|
|
||||||
proc `+=`*[T: SomeInteger](x: var T, y: T) {.
|
proc `+=`*[T: SomeInteger](x: var T, y: T) {.
|
||||||
magic: "Inc", noSideEffect.}
|
magic: "Inc", noSideEffect.}
|
||||||
|
|
|
||||||
|
|
@ -161,16 +161,37 @@ proc `<`*(x, y: int16): bool {.magic: "LtI", noSideEffect.}
|
||||||
proc `<`*(x, y: int32): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int32): bool {.magic: "LtI", noSideEffect.}
|
||||||
proc `<`*(x, y: int64): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int64): bool {.magic: "LtI", noSideEffect.}
|
||||||
|
|
||||||
|
proc `<=`*(x, y: uint): bool {.magic: "LeU", noSideEffect.}
|
||||||
|
## Returns true if ``x <= y``.
|
||||||
|
proc `<=`*(x, y: uint8): bool {.magic: "LeU", noSideEffect.}
|
||||||
|
proc `<=`*(x, y: uint16): bool {.magic: "LeU", noSideEffect.}
|
||||||
|
proc `<=`*(x, y: uint32): bool {.magic: "LeU", noSideEffect.}
|
||||||
|
proc `<=`*(x, y: uint64): bool {.magic: "LeU", noSideEffect.}
|
||||||
|
|
||||||
proc `<=%`*(x, y: IntMax32): bool {.magic: "LeU", noSideEffect.}
|
proc `<`*(x, y: uint): bool {.magic: "LtU", noSideEffect.}
|
||||||
proc `<=%`*(x, y: int64): bool {.magic: "LeU64", noSideEffect.}
|
## Returns true if ``x < y``.
|
||||||
|
proc `<`*(x, y: uint8): bool {.magic: "LtU", noSideEffect.}
|
||||||
|
proc `<`*(x, y: uint16): bool {.magic: "LtU", noSideEffect.}
|
||||||
|
proc `<`*(x, y: uint32): bool {.magic: "LtU", noSideEffect.}
|
||||||
|
proc `<`*(x, y: uint64): bool {.magic: "LtU", noSideEffect.}
|
||||||
|
|
||||||
|
proc `<=%`*(x, y: int): bool {.inline.} =
|
||||||
## Treats `x` and `y` as unsigned and compares them.
|
## Treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true if ``unsigned(x) <= unsigned(y)``.
|
## Returns true if ``unsigned(x) <= unsigned(y)``.
|
||||||
|
cast[uint](x) <= cast[uint](y)
|
||||||
|
proc `<=%`*(x, y: int8): bool {.inline.} = cast[uint8](x) <= cast[uint8](y)
|
||||||
|
proc `<=%`*(x, y: int16): bool {.inline.} = cast[uint16](x) <= cast[uint16](y)
|
||||||
|
proc `<=%`*(x, y: int32): bool {.inline.} = cast[uint32](x) <= cast[uint32](y)
|
||||||
|
proc `<=%`*(x, y: int64): bool {.inline.} = cast[uint64](x) <= cast[uint64](y)
|
||||||
|
|
||||||
proc `<%`*(x, y: IntMax32): bool {.magic: "LtU", noSideEffect.}
|
proc `<%`*(x, y: int): bool {.inline.} =
|
||||||
proc `<%`*(x, y: int64): bool {.magic: "LtU64", noSideEffect.}
|
|
||||||
## Treats `x` and `y` as unsigned and compares them.
|
## Treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true if ``unsigned(x) < unsigned(y)``.
|
## Returns true if ``unsigned(x) < unsigned(y)``.
|
||||||
|
cast[uint](x) < cast[uint](y)
|
||||||
|
proc `<%`*(x, y: int8): bool {.inline.} = cast[uint8](x) < cast[uint8](y)
|
||||||
|
proc `<%`*(x, y: int16): bool {.inline.} = cast[uint16](x) < cast[uint16](y)
|
||||||
|
proc `<%`*(x, y: int32): bool {.inline.} = cast[uint32](x) < cast[uint32](y)
|
||||||
|
proc `<%`*(x, y: int64): bool {.inline.} = cast[uint64](x) < cast[uint64](y)
|
||||||
|
|
||||||
template `>=%`*(x, y: untyped): untyped = y <=% x
|
template `>=%`*(x, y: untyped): untyped = y <=% x
|
||||||
## Treats `x` and `y` as unsigned and compares them.
|
## Treats `x` and `y` as unsigned and compares them.
|
||||||
|
|
@ -180,7 +201,6 @@ template `>%`*(x, y: untyped): untyped = y <% x
|
||||||
## Treats `x` and `y` as unsigned and compares them.
|
## Treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true if ``unsigned(x) > unsigned(y)``.
|
## Returns true if ``unsigned(x) > unsigned(y)``.
|
||||||
|
|
||||||
|
|
||||||
proc `==`*(x, y: uint): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: uint): bool {.magic: "EqI", noSideEffect.}
|
||||||
## Compares two unsigned integers for equality.
|
## Compares two unsigned integers for equality.
|
||||||
proc `==`*(x, y: uint8): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: uint8): bool {.magic: "EqI", noSideEffect.}
|
||||||
|
|
@ -189,21 +209,6 @@ proc `==`*(x, y: uint32): bool {.magic: "EqI", noSideEffect.}
|
||||||
proc `==`*(x, y: uint64): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: uint64): bool {.magic: "EqI", noSideEffect.}
|
||||||
|
|
||||||
|
|
||||||
proc `<=`*(x, y: uint): bool {.magic: "LeU", noSideEffect.}
|
|
||||||
## Returns true if ``x <= y``.
|
|
||||||
proc `<=`*(x, y: uint8): bool {.magic: "LeU", noSideEffect.}
|
|
||||||
proc `<=`*(x, y: uint16): bool {.magic: "LeU", noSideEffect.}
|
|
||||||
proc `<=`*(x, y: uint32): bool {.magic: "LeU", noSideEffect.}
|
|
||||||
proc `<=`*(x, y: uint64): bool {.magic: "LeU", noSideEffect.}
|
|
||||||
|
|
||||||
proc `<`*(x, y: uint): bool {.magic: "LtU", noSideEffect.}
|
|
||||||
## Returns true if ``unsigned(x) < unsigned(y)``.
|
|
||||||
proc `<`*(x, y: uint8): bool {.magic: "LtU", noSideEffect.}
|
|
||||||
proc `<`*(x, y: uint16): bool {.magic: "LtU", noSideEffect.}
|
|
||||||
proc `<`*(x, y: uint32): bool {.magic: "LtU", noSideEffect.}
|
|
||||||
proc `<`*(x, y: uint64): bool {.magic: "LtU", noSideEffect.}
|
|
||||||
|
|
||||||
|
|
||||||
{.push stackTrace: off.}
|
{.push stackTrace: off.}
|
||||||
|
|
||||||
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.} =
|
proc min*(x, y: int): int {.magic: "MinI", noSideEffect.} =
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ int32
|
||||||
4294967295
|
4294967295
|
||||||
2
|
2
|
||||||
0
|
0
|
||||||
|
tUnsignedOps OK
|
||||||
'''
|
'''
|
||||||
|
nimout: "tUnsignedOps OK"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import typetraits
|
import typetraits
|
||||||
|
|
@ -167,3 +169,19 @@ block tissue12177:
|
||||||
echo(a - b)
|
echo(a - b)
|
||||||
echo(a * b)
|
echo(a * b)
|
||||||
echo(a div b)
|
echo(a div b)
|
||||||
|
|
||||||
|
block tUnsignedOps:
|
||||||
|
proc testUnsignedOps() =
|
||||||
|
let a: int8 = -128
|
||||||
|
let b: int8 = 127
|
||||||
|
|
||||||
|
doAssert b +% 1 == -128
|
||||||
|
doAssert b -% -1 == -128
|
||||||
|
doAssert b *% 2 == -2
|
||||||
|
doAssert a /% 4 == 32
|
||||||
|
doAssert a %% 7 == 2
|
||||||
|
echo "tUnsignedOps OK"
|
||||||
|
|
||||||
|
testUnsignedOps()
|
||||||
|
static:
|
||||||
|
testUnsignedOps()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: '''ambiguous call; both foobar.async'''
|
errormsg: '''ambiguous call'''
|
||||||
line: 10
|
line: 10
|
||||||
disabled: "32bit"
|
disabled: "32bit"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue