compiler_rt: add __negvsi2, __negvdi2, __negvti2
- neg can only overflow, if a == MIN
- case `-0` is properly handled by hardware, so overflow check by comparing
`a == MIN` is sufficient
- tests: MIN, MIN+1, MIN+4, -42, -7, -1, 0, 1, 7..
See #1290
2021-12-12 21:25:29 +00:00
|
|
|
const negv = @import("negv.zig");
|
|
|
|
const testing = @import("std").testing;
|
|
|
|
|
|
|
|
fn test__negvti2(a: i128, expected: i128) !void {
|
2023-11-10 05:27:17 +00:00
|
|
|
const result = negv.__negvti2(a);
|
compiler_rt: add __negvsi2, __negvdi2, __negvti2
- neg can only overflow, if a == MIN
- case `-0` is properly handled by hardware, so overflow check by comparing
`a == MIN` is sufficient
- tests: MIN, MIN+1, MIN+4, -42, -7, -1, 0, 1, 7..
See #1290
2021-12-12 21:25:29 +00:00
|
|
|
try testing.expectEqual(expected, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
test "negvti2" {
|
|
|
|
// -2^127 <= i128 <= 2^127-1
|
|
|
|
// 2^127 = 170141183460469231731687303715884105728
|
|
|
|
// 2^127+1 = 170141183460469231731687303715884105727
|
|
|
|
// TODO write panic handler for testing panics
|
|
|
|
//try test__negvti2(-170141183460469231731687303715884105728, -5); // tested with return -5; and panic
|
|
|
|
try test__negvti2(-170141183460469231731687303715884105727, 170141183460469231731687303715884105727);
|
|
|
|
try test__negvti2(-170141183460469231731687303715884105726, 170141183460469231731687303715884105726);
|
|
|
|
try test__negvti2(-170141183460469231731687303715884105725, 170141183460469231731687303715884105725);
|
|
|
|
try test__negvti2(-170141183460469231731687303715884105724, 170141183460469231731687303715884105724);
|
|
|
|
try test__negvti2(-42, 42);
|
|
|
|
try test__negvti2(-7, 7);
|
|
|
|
try test__negvti2(-1, 1);
|
|
|
|
try test__negvti2(0, 0);
|
|
|
|
try test__negvti2(1, -1);
|
|
|
|
try test__negvti2(7, -7);
|
|
|
|
try test__negvti2(42, -42);
|
|
|
|
try test__negvti2(170141183460469231731687303715884105724, -170141183460469231731687303715884105724);
|
|
|
|
try test__negvti2(170141183460469231731687303715884105725, -170141183460469231731687303715884105725);
|
|
|
|
try test__negvti2(170141183460469231731687303715884105726, -170141183460469231731687303715884105726);
|
|
|
|
try test__negvti2(170141183460469231731687303715884105727, -170141183460469231731687303715884105727);
|
|
|
|
}
|