| ... | @@ -0,0 +1,85 @@ |
| 1 | const __mulodi4 = @import("mulodi4.zig").__mulodi4; |
| 2 | const testing = @import("std").testing; |
| 3 | |
| 4 | fn test__mulodi4(a: i64, b: i64, expected: i64, expected_overflow: c_int) void { |
| 5 | var overflow: c_int = undefined; |
| 6 | const x = __mulodi4(a, b, &overflow); |
| 7 | testing.expect(overflow == expected_overflow and (expected_overflow != 0 or x == expected)); |
| 8 | } |
| 9 | |
| 10 | test "mulodi4" { |
| 11 | test__mulodi4(0, 0, 0, 0); |
| 12 | test__mulodi4(0, 1, 0, 0); |
| 13 | test__mulodi4(1, 0, 0, 0); |
| 14 | test__mulodi4(0, 10, 0, 0); |
| 15 | test__mulodi4(10, 0, 0, 0); |
| 16 | test__mulodi4(0, 81985529216486895, 0, 0); |
| 17 | test__mulodi4(81985529216486895, 0, 0, 0); |
| 18 | |
| 19 | test__mulodi4(0, -1, 0, 0); |
| 20 | test__mulodi4(-1, 0, 0, 0); |
| 21 | test__mulodi4(0, -10, 0, 0); |
| 22 | test__mulodi4(-10, 0, 0, 0); |
| 23 | test__mulodi4(0, -81985529216486895, 0, 0); |
| 24 | test__mulodi4(-81985529216486895, 0, 0, 0); |
| 25 | |
| 26 | test__mulodi4(1, 1, 1, 0); |
| 27 | test__mulodi4(1, 10, 10, 0); |
| 28 | test__mulodi4(10, 1, 10, 0); |
| 29 | test__mulodi4(1, 81985529216486895, 81985529216486895, 0); |
| 30 | test__mulodi4(81985529216486895, 1, 81985529216486895, 0); |
| 31 | |
| 32 | test__mulodi4(1, -1, -1, 0); |
| 33 | test__mulodi4(1, -10, -10, 0); |
| 34 | test__mulodi4(-10, 1, -10, 0); |
| 35 | test__mulodi4(1, -81985529216486895, -81985529216486895, 0); |
| 36 | test__mulodi4(-81985529216486895, 1, -81985529216486895, 0); |
| 37 | |
| 38 | test__mulodi4(3037000499, 3037000499, 9223372030926249001, 0); |
| 39 | test__mulodi4(-3037000499, 3037000499, -9223372030926249001, 0); |
| 40 | test__mulodi4(3037000499, -3037000499, -9223372030926249001, 0); |
| 41 | test__mulodi4(-3037000499, -3037000499, 9223372030926249001, 0); |
| 42 | |
| 43 | test__mulodi4(4398046511103, 2097152, 9223372036852678656, 0); |
| 44 | test__mulodi4(-4398046511103, 2097152, -9223372036852678656, 0); |
| 45 | test__mulodi4(4398046511103, -2097152, -9223372036852678656, 0); |
| 46 | test__mulodi4(-4398046511103, -2097152, 9223372036852678656, 0); |
| 47 | |
| 48 | test__mulodi4(2097152, 4398046511103, 9223372036852678656, 0); |
| 49 | test__mulodi4(-2097152, 4398046511103, -9223372036852678656, 0); |
| 50 | test__mulodi4(2097152, -4398046511103, -9223372036852678656, 0); |
| 51 | test__mulodi4(-2097152, -4398046511103, 9223372036852678656, 0); |
| 52 | |
| 53 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -2, 2, 1); |
| 54 | test__mulodi4(-2, 0x7FFFFFFFFFFFFFFF, 2, 1); |
| 55 | test__mulodi4(0x7FFFFFFFFFFFFFFF, -1, @bitCast(i64, u64(0x8000000000000001)), 0); |
| 56 | test__mulodi4(-1, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 0); |
| 57 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 0, 0, 0); |
| 58 | test__mulodi4(0, 0x7FFFFFFFFFFFFFFF, 0, 0); |
| 59 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 1, 0x7FFFFFFFFFFFFFFF, 0); |
| 60 | test__mulodi4(1, 0x7FFFFFFFFFFFFFFF, 0x7FFFFFFFFFFFFFFF, 0); |
| 61 | test__mulodi4(0x7FFFFFFFFFFFFFFF, 2, @bitCast(i64, u64(0x8000000000000001)), 1); |
| 62 | test__mulodi4(2, 0x7FFFFFFFFFFFFFFF, @bitCast(i64, u64(0x8000000000000001)), 1); |
| 63 | |
| 64 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -2, @bitCast(i64, u64(0x8000000000000000)), 1); |
| 65 | test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); |
| 66 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), -1, @bitCast(i64, u64(0x8000000000000000)), 1); |
| 67 | test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); |
| 68 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 0, 0, 0); |
| 69 | test__mulodi4(0, @bitCast(i64, u64(0x8000000000000000)), 0, 0); |
| 70 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 1, @bitCast(i64, u64(0x8000000000000000)), 0); |
| 71 | test__mulodi4(1, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 0); |
| 72 | test__mulodi4(@bitCast(i64, u64(0x8000000000000000)), 2, @bitCast(i64, u64(0x8000000000000000)), 1); |
| 73 | test__mulodi4(2, @bitCast(i64, u64(0x8000000000000000)), @bitCast(i64, u64(0x8000000000000000)), 1); |
| 74 | |
| 75 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -2, @bitCast(i64, u64(0x8000000000000001)), 1); |
| 76 | test__mulodi4(-2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 1); |
| 77 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), -1, 0x7FFFFFFFFFFFFFFF, 0); |
| 78 | test__mulodi4(-1, @bitCast(i64, u64(0x8000000000000001)), 0x7FFFFFFFFFFFFFFF, 0); |
| 79 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 0, 0, 0); |
| 80 | test__mulodi4(0, @bitCast(i64, u64(0x8000000000000001)), 0, 0); |
| 81 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 1, @bitCast(i64, u64(0x8000000000000001)), 0); |
| 82 | test__mulodi4(1, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000001)), 0); |
| 83 | test__mulodi4(@bitCast(i64, u64(0x8000000000000001)), 2, @bitCast(i64, u64(0x8000000000000000)), 1); |
| 84 | test__mulodi4(2, @bitCast(i64, u64(0x8000000000000001)), @bitCast(i64, u64(0x8000000000000000)), 1); |
| 85 | } |