| 1 | const std = @import("std"); |
| 2 | const testing = std.testing; |
| 3 | const mulXi3 = @import("mulXi3.zig"); |
| 4 | const maxInt = std.math.maxInt; |
| 5 | const minInt = std.math.minInt; |
| 6 | |
| 7 | fn test_one_mulsi3(a: i32, b: i32, result: i32) !void { |
| 8 | try testing.expectEqual(result, mulXi3.__mulsi3(a, b)); |
| 9 | } |
| 10 | |
| 11 | fn test__muldi3(a: i64, b: i64, expected: i64) !void { |
| 12 | const x = mulXi3.__muldi3(a, b); |
| 13 | try testing.expect(x == expected); |
| 14 | } |
| 15 | |
| 16 | fn test__multi3(a: i128, b: i128, expected: i128) !void { |
| 17 | const x = mulXi3.__multi3(a, b); |
| 18 | try testing.expect(x == expected); |
| 19 | } |
| 20 | |
| 21 | test "mulsi3" { |
| 22 | try test_one_mulsi3(0, 0, 0); |
| 23 | try test_one_mulsi3(0, 1, 0); |
| 24 | try test_one_mulsi3(1, 0, 0); |
| 25 | try test_one_mulsi3(0, 10, 0); |
| 26 | try test_one_mulsi3(10, 0, 0); |
| 27 | try test_one_mulsi3(0, maxInt(i32), 0); |
| 28 | try test_one_mulsi3(maxInt(i32), 0, 0); |
| 29 | try test_one_mulsi3(0, -1, 0); |
| 30 | try test_one_mulsi3(-1, 0, 0); |
| 31 | try test_one_mulsi3(0, -10, 0); |
| 32 | try test_one_mulsi3(-10, 0, 0); |
| 33 | try test_one_mulsi3(0, minInt(i32), 0); |
| 34 | try test_one_mulsi3(minInt(i32), 0, 0); |
| 35 | try test_one_mulsi3(1, 1, 1); |
| 36 | try test_one_mulsi3(1, 10, 10); |
| 37 | try test_one_mulsi3(10, 1, 10); |
| 38 | try test_one_mulsi3(1, maxInt(i32), maxInt(i32)); |
| 39 | try test_one_mulsi3(maxInt(i32), 1, maxInt(i32)); |
| 40 | try test_one_mulsi3(1, -1, -1); |
| 41 | try test_one_mulsi3(1, -10, -10); |
| 42 | try test_one_mulsi3(-10, 1, -10); |
| 43 | try test_one_mulsi3(1, minInt(i32), minInt(i32)); |
| 44 | try test_one_mulsi3(minInt(i32), 1, minInt(i32)); |
| 45 | try test_one_mulsi3(46340, 46340, 2147395600); |
| 46 | try test_one_mulsi3(-46340, 46340, -2147395600); |
| 47 | try test_one_mulsi3(46340, -46340, -2147395600); |
| 48 | try test_one_mulsi3(-46340, -46340, 2147395600); |
| 49 | try test_one_mulsi3(4194303, 8192, @as(i32, @truncate(34359730176))); |
| 50 | try test_one_mulsi3(-4194303, 8192, @as(i32, @truncate(-34359730176))); |
| 51 | try test_one_mulsi3(4194303, -8192, @as(i32, @truncate(-34359730176))); |
| 52 | try test_one_mulsi3(-4194303, -8192, @as(i32, @truncate(34359730176))); |
| 53 | try test_one_mulsi3(8192, 4194303, @as(i32, @truncate(34359730176))); |
| 54 | try test_one_mulsi3(-8192, 4194303, @as(i32, @truncate(-34359730176))); |
| 55 | try test_one_mulsi3(8192, -4194303, @as(i32, @truncate(-34359730176))); |
| 56 | try test_one_mulsi3(-8192, -4194303, @as(i32, @truncate(34359730176))); |
| 57 | } |
| 58 | |
| 59 | test "muldi3" { |
| 60 | try test__muldi3(0, 0, 0); |
| 61 | try test__muldi3(0, 1, 0); |
| 62 | try test__muldi3(1, 0, 0); |
| 63 | try test__muldi3(0, 10, 0); |
| 64 | try test__muldi3(10, 0, 0); |
| 65 | try test__muldi3(0, 81985529216486895, 0); |
| 66 | try test__muldi3(81985529216486895, 0, 0); |
| 67 | |
| 68 | try test__muldi3(0, -1, 0); |
| 69 | try test__muldi3(-1, 0, 0); |
| 70 | try test__muldi3(0, -10, 0); |
| 71 | try test__muldi3(-10, 0, 0); |
| 72 | try test__muldi3(0, -81985529216486895, 0); |
| 73 | try test__muldi3(-81985529216486895, 0, 0); |
| 74 | |
| 75 | try test__muldi3(1, 1, 1); |
| 76 | try test__muldi3(1, 10, 10); |
| 77 | try test__muldi3(10, 1, 10); |
| 78 | try test__muldi3(1, 81985529216486895, 81985529216486895); |
| 79 | try test__muldi3(81985529216486895, 1, 81985529216486895); |
| 80 | |
| 81 | try test__muldi3(1, -1, -1); |
| 82 | try test__muldi3(1, -10, -10); |
| 83 | try test__muldi3(-10, 1, -10); |
| 84 | try test__muldi3(1, -81985529216486895, -81985529216486895); |
| 85 | try test__muldi3(-81985529216486895, 1, -81985529216486895); |
| 86 | |
| 87 | try test__muldi3(3037000499, 3037000499, 9223372030926249001); |
| 88 | try test__muldi3(-3037000499, 3037000499, -9223372030926249001); |
| 89 | try test__muldi3(3037000499, -3037000499, -9223372030926249001); |
| 90 | try test__muldi3(-3037000499, -3037000499, 9223372030926249001); |
| 91 | |
| 92 | try test__muldi3(4398046511103, 2097152, 9223372036852678656); |
| 93 | try test__muldi3(-4398046511103, 2097152, -9223372036852678656); |
| 94 | try test__muldi3(4398046511103, -2097152, -9223372036852678656); |
| 95 | try test__muldi3(-4398046511103, -2097152, 9223372036852678656); |
| 96 | |
| 97 | try test__muldi3(2097152, 4398046511103, 9223372036852678656); |
| 98 | try test__muldi3(-2097152, 4398046511103, -9223372036852678656); |
| 99 | try test__muldi3(2097152, -4398046511103, -9223372036852678656); |
| 100 | try test__muldi3(-2097152, -4398046511103, 9223372036852678656); |
| 101 | } |
| 102 | |
| 103 | test "multi3" { |
| 104 | try test__multi3(0, 0, 0); |
| 105 | try test__multi3(0, 1, 0); |
| 106 | try test__multi3(1, 0, 0); |
| 107 | try test__multi3(0, 10, 0); |
| 108 | try test__multi3(10, 0, 0); |
| 109 | try test__multi3(0, 81985529216486895, 0); |
| 110 | try test__multi3(81985529216486895, 0, 0); |
| 111 | |
| 112 | try test__multi3(0, -1, 0); |
| 113 | try test__multi3(-1, 0, 0); |
| 114 | try test__multi3(0, -10, 0); |
| 115 | try test__multi3(-10, 0, 0); |
| 116 | try test__multi3(0, -81985529216486895, 0); |
| 117 | try test__multi3(-81985529216486895, 0, 0); |
| 118 | |
| 119 | try test__multi3(1, 1, 1); |
| 120 | try test__multi3(1, 10, 10); |
| 121 | try test__multi3(10, 1, 10); |
| 122 | try test__multi3(1, 81985529216486895, 81985529216486895); |
| 123 | try test__multi3(81985529216486895, 1, 81985529216486895); |
| 124 | |
| 125 | try test__multi3(1, -1, -1); |
| 126 | try test__multi3(1, -10, -10); |
| 127 | try test__multi3(-10, 1, -10); |
| 128 | try test__multi3(1, -81985529216486895, -81985529216486895); |
| 129 | try test__multi3(-81985529216486895, 1, -81985529216486895); |
| 130 | |
| 131 | try test__multi3(3037000499, 3037000499, 9223372030926249001); |
| 132 | try test__multi3(-3037000499, 3037000499, -9223372030926249001); |
| 133 | try test__multi3(3037000499, -3037000499, -9223372030926249001); |
| 134 | try test__multi3(-3037000499, -3037000499, 9223372030926249001); |
| 135 | |
| 136 | try test__multi3(4398046511103, 2097152, 9223372036852678656); |
| 137 | try test__multi3(-4398046511103, 2097152, -9223372036852678656); |
| 138 | try test__multi3(4398046511103, -2097152, -9223372036852678656); |
| 139 | try test__multi3(-4398046511103, -2097152, 9223372036852678656); |
| 140 | |
| 141 | try test__multi3(2097152, 4398046511103, 9223372036852678656); |
| 142 | try test__multi3(-2097152, 4398046511103, -9223372036852678656); |
| 143 | try test__multi3(2097152, -4398046511103, -9223372036852678656); |
| 144 | try test__multi3(-2097152, -4398046511103, 9223372036852678656); |
| 145 | |
| 146 | try test__multi3(0x00000000000000B504F333F9DE5BE000, 0x000000000000000000B504F333F9DE5B, 0x7FFFFFFFFFFFF328DF915DA296E8A000); |
| 147 | } |