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__negvsi2(a: i32, expected: i32) !void {
|
2023-11-10 05:27:17 +00:00
|
|
|
const result = negv.__negvsi2(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 "negvsi2" {
|
|
|
|
// -2^31 <= i32 <= 2^31-1
|
|
|
|
// 2^31 = 2147483648
|
|
|
|
// 2^31-1 = 2147483647
|
|
|
|
// TODO write panic handler for testing panics
|
|
|
|
//try test__negvsi2(-2147483648, -5); // tested with return -5; and panic
|
|
|
|
try test__negvsi2(-2147483647, 2147483647);
|
|
|
|
try test__negvsi2(-2147483646, 2147483646);
|
|
|
|
try test__negvsi2(-2147483645, 2147483645);
|
|
|
|
try test__negvsi2(-2147483644, 2147483644);
|
|
|
|
try test__negvsi2(-42, 42);
|
|
|
|
try test__negvsi2(-7, 7);
|
|
|
|
try test__negvsi2(-1, 1);
|
|
|
|
try test__negvsi2(0, 0);
|
|
|
|
try test__negvsi2(1, -1);
|
|
|
|
try test__negvsi2(7, -7);
|
|
|
|
try test__negvsi2(42, -42);
|
|
|
|
try test__negvsi2(2147483644, -2147483644);
|
|
|
|
try test__negvsi2(2147483645, -2147483645);
|
|
|
|
try test__negvsi2(2147483646, -2147483646);
|
|
|
|
try test__negvsi2(2147483647, -2147483647);
|
|
|
|
}
|