tyInt tyUint fit target int bit width (#20829)
This commit is contained in:
parent
a70d3abd37
commit
658b28dc57
17 changed files with 306 additions and 267 deletions
|
|
@ -753,8 +753,13 @@ proc firstOrd*(conf: ConfigRef; t: PType): Int128 =
|
|||
assert(t.n.kind == nkRange)
|
||||
result = getOrdValue(t.n[0])
|
||||
of tyInt:
|
||||
if conf != nil and conf.target.intSize == 4:
|
||||
result = toInt128(-2147483648)
|
||||
if conf != nil:
|
||||
case conf.target.intSize
|
||||
of 8: result = toInt128(0x8000000000000000'i64)
|
||||
of 4: result = toInt128(-2147483648)
|
||||
of 2: result = toInt128(-32768)
|
||||
of 1: result = toInt128(-128)
|
||||
else: discard
|
||||
else:
|
||||
result = toInt128(0x8000000000000000'i64)
|
||||
of tyInt8: result = toInt128(-128)
|
||||
|
|
@ -797,6 +802,29 @@ proc firstFloat*(t: PType): BiggestFloat =
|
|||
internalError(newPartialConfigRef(), "invalid kind for firstFloat(" & $t.kind & ')')
|
||||
NaN
|
||||
|
||||
proc targetSizeSignedToKind*(conf: ConfigRef): TTypeKind =
|
||||
case conf.target.intSize
|
||||
of 8: result = tyInt64
|
||||
of 4: result = tyInt32
|
||||
of 2: result = tyInt16
|
||||
else: discard
|
||||
|
||||
proc targetSizeUnsignedToKind*(conf: ConfigRef): TTypeKind =
|
||||
case conf.target.intSize
|
||||
of 8: result = tyUInt64
|
||||
of 4: result = tyUInt32
|
||||
of 2: result = tyUInt16
|
||||
else: discard
|
||||
|
||||
proc normalizeKind*(conf: ConfigRef, k: TTypeKind): TTypeKind =
|
||||
case k
|
||||
of tyInt:
|
||||
result = conf.targetSizeSignedToKind()
|
||||
of tyUInt:
|
||||
result = conf.targetSizeUnsignedToKind()
|
||||
else:
|
||||
result = k
|
||||
|
||||
proc lastOrd*(conf: ConfigRef; t: PType): Int128 =
|
||||
case t.kind
|
||||
of tyBool: result = toInt128(1'u)
|
||||
|
|
@ -808,7 +836,13 @@ proc lastOrd*(conf: ConfigRef; t: PType): Int128 =
|
|||
assert(t.n.kind == nkRange)
|
||||
result = getOrdValue(t.n[1])
|
||||
of tyInt:
|
||||
if conf != nil and conf.target.intSize == 4: result = toInt128(0x7FFFFFFF)
|
||||
if conf != nil:
|
||||
case conf.target.intSize
|
||||
of 8: result = toInt128(0x7FFFFFFFFFFFFFFF'u64)
|
||||
of 4: result = toInt128(0x7FFFFFFF)
|
||||
of 2: result = toInt128(0x00007FFF)
|
||||
of 1: result = toInt128(0x0000007F)
|
||||
else: discard
|
||||
else: result = toInt128(0x7FFFFFFFFFFFFFFF'u64)
|
||||
of tyInt8: result = toInt128(0x0000007F)
|
||||
of tyInt16: result = toInt128(0x00007FFF)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue