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__negvdi2(a: i64, expected: i64) !void {
|
2023-11-10 05:27:17 +00:00
|
|
|
const result = negv.__negvdi2(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 "negvdi2" {
|
|
|
|
// -2^63 <= i64 <= 2^63-1
|
|
|
|
// 2^63 = 9223372036854775808
|
|
|
|
// 2^63-1 = 9223372036854775807
|
|
|
|
// TODO write panic handler for testing panics
|
|
|
|
//try test__negvdi2(-9223372036854775808, -5); // tested with return -5; and panic
|
|
|
|
try test__negvdi2(-9223372036854775807, 9223372036854775807);
|
|
|
|
try test__negvdi2(-9223372036854775806, 9223372036854775806);
|
|
|
|
try test__negvdi2(-9223372036854775805, 9223372036854775805);
|
|
|
|
try test__negvdi2(-9223372036854775804, 9223372036854775804);
|
|
|
|
try test__negvdi2(-42, 42);
|
|
|
|
try test__negvdi2(-7, 7);
|
|
|
|
try test__negvdi2(-1, 1);
|
|
|
|
try test__negvdi2(0, 0);
|
|
|
|
try test__negvdi2(1, -1);
|
|
|
|
try test__negvdi2(7, -7);
|
|
|
|
try test__negvdi2(42, -42);
|
|
|
|
try test__negvdi2(9223372036854775804, -9223372036854775804);
|
|
|
|
try test__negvdi2(9223372036854775805, -9223372036854775805);
|
|
|
|
try test__negvdi2(9223372036854775806, -9223372036854775806);
|
|
|
|
try test__negvdi2(9223372036854775807, -9223372036854775807);
|
|
|
|
}
|