From e90d91f0e463e870c49a7558d216fff03a581949 Mon Sep 17 00:00:00 2001 From: Arne Döring Date: Mon, 24 Jun 2019 09:19:02 +0200 Subject: [refactoring] remove zeroExtend and friends from the compiler builtins. (#11531) * remove zeroExtend and friends from the compiler builtins. * fix jssys --- lib/system.nim | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++- lib/system/jssys.nim | 33 +++++++++++++++-------------- 2 files changed, 75 insertions(+), 17 deletions(-) (limited to 'lib') 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 -- cgit 1.4.1-2-gfad0