1const testing = @import("std").testing;
2
3const mulv = @import("mulo.zig");
4const compiler_rt = @import("../compiler_rt.zig");
5const symbol = compiler_rt.symbol;
6
7comptime {
8 symbol(&__mulvsi3, "__mulvsi3");
9}
10
11pub fn __mulvsi3(a: i32, b: i32) callconv(.c) i32 {
12 var overflow: c_int = 0;
13 const sum = mulv.__mulosi4(a, b, &overflow);
14 if (overflow != 0) @panic("integer overflow");
15 return sum;
16}
17
18test "mulvsi3" {
19 // min i32 = -2147483648
20 // max i32 = 2147483647
21 // TODO write panic handler for testing panics
22 // try test__mulvsi3(-2147483648, -1, -1); // panic
23 // try test__mulvsi3(2147483647, 1, 1); // panic
24 try testing.expectEqual(-2147483648, __mulvsi3(-1073741824, 2));
25 try testing.expectEqual(2147483646, __mulvsi3(1073741823, 2)); // one too less for corner case 2147483647
26}