Deprecate uXX and iXX bit suffixes.

Add experimental LL / ULL suffixes for int128 and uint128 literals.
This commit is contained in:
Christoffer Lerno
2025-05-13 23:48:59 +02:00
parent c528f53d58
commit abe4727c3a
25 changed files with 126 additions and 68 deletions

View File

@@ -581,10 +581,10 @@ fn DString join(Allocator allocator, String[] s, String joiner)
}
DString res = new_with_capacity(allocator, total_size);
res.append(s[0]);
foreach (String* &str : s[1..])
foreach (String str : s[1..])
{
res.append(joiner);
res.append(*str);
res.append(str);
}
return res;
}

View File

@@ -143,7 +143,7 @@ uint128 x86_features;
fn void add_feature_if_bit(X86Feature feature, uint register, int bit)
{
if (register & 1U << bit) x86_features |= 1u128 << feature.ordinal;
if (register & 1U << bit) x86_features |= 1ULL << feature.ordinal;
}
fn void x86_initialize_cpu_features()

View File

@@ -507,7 +507,7 @@ macro bool is_finite(x)
$case float16:
return bitcast((float)x, uint) & 0x7fffffff < 0x7f800000;
$default:
return bitcast((double)x, ulong) & (~0u64 >> 1) < 0x7ffu64 << 52;
return bitcast((double)x, ulong) & (~0UL >> 1) < 0x7ffUL << 52;
$endswitch
}
@@ -521,7 +521,7 @@ macro is_nan(x)
$case float16:
return bitcast((float)x, uint) & 0x7fffffff > 0x7f800000;
$default:
return bitcast((double)x, ulong) & (~0u64 >> 1) > 0x7ffu64 << 52;
return bitcast((double)x, ulong) & (~0UL >> 1) > 0x7ffUL << 52;
$endswitch
}
@@ -535,7 +535,7 @@ macro is_inf(x)
$case float16:
return bitcast((float)x, uint) & 0x7fffffff == 0x7f800000;
$default:
return bitcast((double)x, ulong) & (~0u64 >> 1) == 0x7ffu64 << 52;
return bitcast((double)x, ulong) & (~0UL >> 1) == 0x7ffUL << 52;
$endswitch
}
@@ -1053,8 +1053,8 @@ fn double _frexp(double x, int* e)
return x;
default:
*e = ee - 0x3fe;
i &= 0x800fffffffffffffu64;
i |= 0x3fe0000000000000u64;
i &= 0x800fffffffffffffUL;
i |= 0x3fe0000000000000UL;
return bitcast(i, double);
}
}
@@ -1079,8 +1079,8 @@ fn float _frexpf(float x, int* e)
return x;
default:
*e = ee - 0x7e;
i &= 0x807fffffu32;
i |= 0x3f000000u32;
i &= 0x807fffffU;
i |= 0x3f000000U;
return bitcast(i, float);
}
}

View File

@@ -47,13 +47,13 @@ fn double _exp2_specialcase(double tmp, ulong sbits, ulong ki) @private
if (ki & 0x80000000 == 0)
{
// k > 0, the exponent of scale might have overflowed by 1.
sbits -= 1u64 << 52;
sbits -= 1UL << 52;
double scale = bitcast(sbits, double);
double y = 2 * (scale + scale * tmp);
return y;
}
// k < 0, need special care in the subnormal range.
sbits += 1022u64 << 52;
sbits += 1022UL << 52;
double scale = bitcast(sbits, double);
double y = scale + scale * tmp;
if (y >= 1.0)

View File

@@ -31,4 +31,4 @@ fn char SimpleRandom.next_byte(&self) @dynamic => (char)self.next_int();
const long SIMPLE_RANDOM_MULTIPLIER @local = 0x5DEECE66D;
const long SIMPLE_RANDOM_ADDEND @local = 0xB;
const long SIMPLE_RANDOM_MASK @local = (1u64 << 48) - 1;
const long SIMPLE_RANDOM_MASK @local = (1UL << 48) - 1;

View File

@@ -315,15 +315,15 @@ macro float_from_i128($Type, a) @private
const MANT_DIG = math::DOUBLE_MANT_DIG;
const SIGNIFICANT_BITS = 52;
const EXP_BIAS = 1023;
const MANTISSA_MASK = 0xFFFFF_FFFF_FFFFu64;
const SIGN_BIT = 1u64 << 63;
const MANTISSA_MASK = 0xFFFFF_FFFF_FFFFUL;
const SIGN_BIT = 1UL << 63;
$case float:
$Rep = uint;
const MANT_DIG = math::FLOAT_MANT_DIG;
const EXP_BIAS = 127;
const SIGNIFICANT_BITS = 23;
const MANTISSA_MASK = 0x7F_FFFFu32;
const SIGN_BIT = 1u32 << 31;
const MANTISSA_MASK = 0x7F_FFFFU;
const SIGN_BIT = 1U << 31;
$case float16:
$Rep = ushort;
const MANT_DIG = math::HALF_MANT_DIG;
@@ -352,7 +352,7 @@ macro float_from_i128($Type, a) @private
a |= (uint128)((a & 4) != 0);
a++;
a >>= 2;
if (a & (1i128 << MANT_DIG))
if (a & (1LL << MANT_DIG))
{
a >>= 1;
e++;
@@ -374,13 +374,13 @@ macro float_from_u128($Type, a) @private
const MANT_DIG = math::DOUBLE_MANT_DIG;
const SIGNIFICANT_BITS = 52;
const EXP_BIAS = 1023;
const MANTISSA_MASK = 0xFFFFF_FFFF_FFFFu64;
const MANTISSA_MASK = 0xFFFFF_FFFF_FFFFUL;
$case float:
$Rep = uint;
const MANT_DIG = math::FLOAT_MANT_DIG;
const EXP_BIAS = 127;
const SIGNIFICANT_BITS = 23;
const MANTISSA_MASK = 0x7F_FFFFu32;
const MANTISSA_MASK = 0x7F_FFFFU;
$case float16:
$Rep = ushort;
const MANT_DIG = math::HALF_MANT_DIG;
@@ -406,7 +406,7 @@ macro float_from_u128($Type, a) @private
a |= (uint128)((a & 4) != 0);
a++;
a >>= 2;
if (a & (1i128 << MANT_DIG))
if (a & (1LL << MANT_DIG))
{
a >>= 1;
e++;
@@ -458,8 +458,8 @@ macro fixuint(a) @private
int sign = rep & SIGN_BIT ? -1 : 1;
int exponent = (int)((abs >> SIGNIFICANT_BITS) - EXPONENT_BIAS);
$Rep significand = (abs & SIGNIFICANT_MASK) | IMPLICIT_BIT;
if (sign == -1 || exponent < 0) return 0u128;
if ((uint)exponent >= uint128.sizeof * 8) return ~0u128;
if (sign == -1 || exponent < 0) return 0ULL;
if ((uint)exponent >= uint128.sizeof * 8) return ~0ULL;
if (exponent < SIGNIFICANT_BITS) return (uint128)significand >> (SIGNIFICANT_BITS - exponent);
return (uint128)significand << (exponent - SIGNIFICANT_BITS);
}

View File

@@ -5,13 +5,13 @@ fn Time native_timestamp()
{
TimeSpec ts;
posix::clock_gettime(posix::CLOCK_REALTIME, &ts);
return (Time)(ts.s * 1_000_000i64 + ts.ns / 1_000i64);
return (Time)(ts.s * 1_000_000L + ts.ns / 1_000L);
}
fn Clock native_clock() @if(!env::DARWIN)
{
TimeSpec ts;
posix::clock_gettime(posix::CLOCK_MONOTONIC, &ts);
return (Clock)((ulong)ts.s * 1_000_000_000u64 + (ulong)ts.ns);
return (Clock)((ulong)ts.s * 1_000_000_000UL + (ulong)ts.ns);
}

View File

@@ -3,7 +3,7 @@ import std::os::win32;
import std::math;
const ulong WINDOWS_TICK_US @local = 10;
const ulong WIN_TO_UNIX_EPOCH_US @local = 116444736000000000u64 / WINDOWS_TICK_US;
const ulong WIN_TO_UNIX_EPOCH_US @local = 116444736000000000UL / WINDOWS_TICK_US;
fn Clock native_clock()
{