diff --git a/lib/std/math/math.c3 b/lib/std/math/math.c3 index 7fa119eef..db69b0ffb 100644 --- a/lib/std/math/math.c3 +++ b/lib/std/math/math.c3 @@ -1097,48 +1097,22 @@ macro overflow_mul_helper(x, y) @local return res; } - -macro char char.mult_div(self, char mul, char div) +macro mul_div_helper(val, mul, div) @private { - return mul * (self / div) + mul * (self % div) / div; + var $Type = $typeof(val); + return ($Type)(($Type)mul * (val / ($Type)div) + ($Type)mul * (val % ($Type)div) / ($Type)div); } +macro char char.muldiv(self, char mul, char div) => mul_div_helper(self, mul, div); +macro ichar ichar.muldiv(self, ichar mul, ichar div) => mul_div_helper(self, mul, div); +macro short short.muldiv(self, short mul, short div) => mul_div_helper(self, mul, div); +macro ushort ushort.muldiv(self, ushort mul, ushort div) => mul_div_helper(self, mul, div); +macro int int.muldiv(self, int mul, int div) => mul_div_helper(self, mul, div); +macro uint uint.muldiv(self, uint mul, uint div) => mul_div_helper(self, mul, div); +macro long long.muldiv(self, long mul, long div) => mul_div_helper(self, mul, div); +macro ulong ulong.muldiv(self, ulong mul, ulong div) => mul_div_helper(self, mul, div); -macro ichar ichar.mult_div(self, ichar mul, ichar div) +macro bool @is_same_vector_or_scalar(#vector_value, #vector_or_scalar) @private { - return mul * (self / div) + mul * (self % div) / div; -} - -macro short short.mult_div(self, short mul, short div) -{ - return mul * (self / div) + mul * (self % div) / div; -} - -macro ushort ushort.mult_div(self, ushort mul, ushort div) -{ - return mul * (self / div) + mul * (self % div) / div; -} - -macro int int.mult_div(self, int mul, int div) -{ - return mul * (self / div) + mul * (self % div) / div; -} - -macro uint uint.mult_div(self, uint mul, uint div) -{ - return mul * (self / div) + mul * (self % div) / div; -} - -macro long long.mult_div(self, long mul, long div) -{ - return mul * (self / div) + mul * (self % div) / div; -} - -macro ulong ulong.mult_div(self, ulong mul, ulong div) -{ - return mul * (self / div) + mul * (self % div) / div; -} - -macro bool @is_same_vector_or_scalar(#vector_value, #vector_or_scalar) @private { return (values::@is_vector(#vector_or_scalar) &&& values::@is_same_vector_type(#vector_value, #vector_or_scalar)) ||| values::@is_int(#vector_or_scalar); } @@ -1146,62 +1120,46 @@ macro bool @is_same_vector_or_scalar(#vector_value, #vector_or_scalar) @private * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro char[<*>] char[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro char[<*>] char[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro ichar[<*>] ichar[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro ichar[<*>] ichar[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro short[<*>] short[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro short[<*>] short[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro ushort[<*>] ushort[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro ushort[<*>] ushort[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro int[<*>] int[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro int[<*>] int[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro uint[<*>] uint[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro uint[<*>] uint[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro long[<*>] long[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} +macro long[<*>] long[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); /** * @require @is_same_vector_or_scalar(self, mul) `mul must be a vector of the same type as self, or be an integer scalar` * @require @is_same_vector_or_scalar(self, div) `div must be a vector of the same type as self, or be an integer scalar` */ -macro ulong[<*>] ulong[<*>].mult_div(self, mul, div) { - return ($typeof(self))mul * (self / ($typeof(self))div) + ($typeof(self))mul * (self % ($typeof(self))div) / ($typeof(self))div; -} \ No newline at end of file +macro ulong[<*>] ulong[<*>].muldiv(self, mul, div) => mul_div_helper(self, mul, div); \ No newline at end of file diff --git a/lib/std/time/os/time_win32.c3 b/lib/std/time/os/time_win32.c3 index 7a444c1fd..998d9dcdb 100644 --- a/lib/std/time/os/time_win32.c3 +++ b/lib/std/time/os/time_win32.c3 @@ -21,7 +21,7 @@ fn Clock native_clock() } Win32_LARGE_INTEGER counter @noinit; if (!win32_QueryPerformanceCounter(&counter)) return 0; - return (Clock)counter.quadPart.mult_div(1_000_000_000, freq.quadPart); + return (Clock)counter.quadPart.muldiv(1_000_000_000, freq.quadPart); } fn Time native_timestamp() diff --git a/test/test_suite/debug_symbols/defer_macro.c3t b/test/test_suite/debug_symbols/defer_macro.c3t index fb796bad0..cff9bf45a 100644 --- a/test/test_suite/debug_symbols/defer_macro.c3t +++ b/test/test_suite/debug_symbols/defer_macro.c3t @@ -530,7 +530,7 @@ check: ; preds = %no_match, %entry missing_function: ; preds = %check ret ptr null compare: ; preds = %check - %4 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 1 + %4 = getelementptr inbounds %5 = load ptr, ptr %4, align 8 %6 = icmp eq ptr %5, %1 br i1 %6, label %match, label %no_match @@ -538,7 +538,7 @@ match: ; preds = %compare %7 = load ptr, ptr %2, align 8 ret ptr %7 no_match: ; preds = %compare - %8 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 2 + %8 = getelementptr inbounds %9 = load ptr, ptr %8, align 8 br label %check } diff --git a/test/test_suite/dynamic/inherit_linux.c3t b/test/test_suite/dynamic/inherit_linux.c3t index 68dd27ef8..99a2cb0e9 100644 --- a/test/test_suite/dynamic/inherit_linux.c3t +++ b/test/test_suite/dynamic/inherit_linux.c3t @@ -156,7 +156,7 @@ check: ; preds = %no_match, %entry missing_function: ; preds = %check ret ptr null compare: ; preds = %check - %4 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 1 + %4 = getelementptr inbounds %5 = load ptr, ptr %4, align 8 %6 = icmp eq ptr %5, %1 br i1 %6, label %match, label %no_match @@ -164,7 +164,7 @@ match: ; preds = %compare %7 = load ptr, ptr %2, align 8 ret ptr %7 no_match: ; preds = %compare - %8 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 2 + %8 = getelementptr inbounds %9 = load ptr, ptr %8, align 8 br label %check } @@ -172,23 +172,23 @@ define internal void @.c3_dynamic_register() align 8 { entry: br label %dtable_check dtable_check: ; preds = %dtable_next, %entry - %dtable_ref = phi ptr [ getelementptr inbounds (%.introspect, ptr @"$ct.inherit.Test", i32 0, i32 2), %entry ], [ %next_dtable_ref, %dtable_next ] + %dtable_ref = phi ptr [ getelementptr inbounds %dtable_ptr = load ptr, ptr %dtable_ref, align 8 %0 = icmp eq ptr %dtable_ptr, null br i1 %0, label %dtable_found, label %dtable_next dtable_next: ; preds = %dtable_check - %next_dtable_ref = getelementptr inbounds { ptr, ptr, ptr }, ptr %dtable_ptr, i32 0, i32 2 + %next_dtable_ref = getelementptr inbounds br label %dtable_check dtable_found: ; preds = %dtable_check store ptr @"$ct.dyn.inherit.Test.tesT", ptr %dtable_ref, align 8 br label %dtable_check1 dtable_check1: ; preds = %dtable_next4, %dtable_found - %dtable_ref2 = phi ptr [ getelementptr inbounds (%.introspect, ptr @"$ct.inherit.Test", i32 0, i32 2), %dtable_found ], [ %next_dtable_ref5, %dtable_next4 ] + %dtable_ref2 = phi ptr [ getelementptr inbounds %dtable_ptr3 = load ptr, ptr %dtable_ref2, align 8 %1 = icmp eq ptr %dtable_ptr3, null br i1 %1, label %dtable_found6, label %dtable_next4 dtable_next4: ; preds = %dtable_check1 - %next_dtable_ref5 = getelementptr inbounds { ptr, ptr, ptr }, ptr %dtable_ptr3, i32 0, i32 2 + %next_dtable_ref5 = getelementptr inbounds br label %dtable_check1 dtable_found6: ; preds = %dtable_check1 store ptr @"$ct.dyn.inherit.Test.hello", ptr %dtable_ref2, align 8 diff --git a/test/test_suite/dynamic/inherit_macos.c3t b/test/test_suite/dynamic/inherit_macos.c3t index 5cb303e20..4f277f118 100644 --- a/test/test_suite/dynamic/inherit_macos.c3t +++ b/test/test_suite/dynamic/inherit_macos.c3t @@ -149,7 +149,7 @@ check: ; preds = %no_match, %entry missing_function: ; preds = %check ret ptr null compare: ; preds = %check - %4 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 1 + %4 = getelementptr inbounds %5 = load ptr, ptr %4, align 8 %6 = icmp eq ptr %5, %1 br i1 %6, label %match, label %no_match @@ -157,7 +157,7 @@ match: ; preds = %compare %7 = load ptr, ptr %2, align 8 ret ptr %7 no_match: ; preds = %compare - %8 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 2 + %8 = getelementptr inbounds %9 = load ptr, ptr %8, align 8 br label %check } diff --git a/test/test_suite/dynamic/overlapping_function_linux.c3t b/test/test_suite/dynamic/overlapping_function_linux.c3t index 96d1c926e..dfaf4a9b6 100644 --- a/test/test_suite/dynamic/overlapping_function_linux.c3t +++ b/test/test_suite/dynamic/overlapping_function_linux.c3t @@ -149,7 +149,7 @@ check: ; preds = %no_match, %entry missing_function: ; preds = %check ret ptr null compare: ; preds = %check - %4 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 1 + %4 = getelementptr inbounds %5 = load ptr, ptr %4, align 8 %6 = icmp eq ptr %5, %1 br i1 %6, label %match, label %no_match @@ -157,7 +157,7 @@ match: ; preds = %compare %7 = load ptr, ptr %2, align 8 ret ptr %7 no_match: ; preds = %compare - %8 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 2 + %8 = getelementptr inbounds %9 = load ptr, ptr %8, align 8 br label %check } @@ -165,23 +165,23 @@ define internal void @.c3_dynamic_register() align 8 { entry: br label %dtable_check dtable_check: ; preds = %dtable_next, %entry - %dtable_ref = phi ptr [ getelementptr inbounds (%.introspect, ptr @"$ct.overlap.Test", i32 0, i32 2), %entry ], [ %next_dtable_ref, %dtable_next ] + %dtable_ref = phi ptr [ getelementptr inbounds %dtable_ptr = load ptr, ptr %dtable_ref, align 8 %0 = icmp eq ptr %dtable_ptr, null br i1 %0, label %dtable_found, label %dtable_next dtable_next: ; preds = %dtable_check - %next_dtable_ref = getelementptr inbounds { ptr, ptr, ptr }, ptr %dtable_ptr, i32 0, i32 2 + %next_dtable_ref = getelementptr inbounds br label %dtable_check dtable_found: ; preds = %dtable_check store ptr @"$ct.dyn.overlap.Test.tesT", ptr %dtable_ref, align 8 br label %dtable_check1 dtable_check1: ; preds = %dtable_next4, %dtable_found - %dtable_ref2 = phi ptr [ getelementptr inbounds (%.introspect, ptr @"$ct.overlap.Test", i32 0, i32 2), %dtable_found ], [ %next_dtable_ref5, %dtable_next4 ] + %dtable_ref2 = phi ptr [ getelementptr inbounds %dtable_ptr3 = load ptr, ptr %dtable_ref2, align 8 %1 = icmp eq ptr %dtable_ptr3, null br i1 %1, label %dtable_found6, label %dtable_next4 dtable_next4: ; preds = %dtable_check1 - %next_dtable_ref5 = getelementptr inbounds { ptr, ptr, ptr }, ptr %dtable_ptr3, i32 0, i32 2 + %next_dtable_ref5 = getelementptr inbounds br label %dtable_check1 dtable_found6: ; preds = %dtable_check1 store ptr @"$ct.dyn.overlap.Test.foo", ptr %dtable_ref2, align 8 diff --git a/test/test_suite/dynamic/overlapping_function_macos.c3t b/test/test_suite/dynamic/overlapping_function_macos.c3t index d00f69357..310b58641 100644 --- a/test/test_suite/dynamic/overlapping_function_macos.c3t +++ b/test/test_suite/dynamic/overlapping_function_macos.c3t @@ -160,7 +160,7 @@ missing_function: ; preds = %check ret ptr null compare: ; preds = %check - %4 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 1 + %4 = getelementptr inbounds %5 = load ptr, ptr %4, align 8 %6 = icmp eq ptr %5, %1 br i1 %6, label %match, label %no_match @@ -170,7 +170,7 @@ match: ; preds = %compare ret ptr %7 no_match: ; preds = %compare - %8 = getelementptr inbounds { ptr, ptr, ptr }, ptr %2, i32 0, i32 2 + %8 = getelementptr inbounds %9 = load ptr, ptr %8, align 8 br label %check } diff --git a/test/test_suite/errors/printing_errors.c3t b/test/test_suite/errors/printing_errors.c3t index 7da486350..4472a92c2 100644 --- a/test/test_suite/errors/printing_errors.c3t +++ b/test/test_suite/errors/printing_errors.c3t @@ -37,7 +37,7 @@ faultname_no: ; preds = %entry faultname_ok: ; preds = %entry %3 = inttoptr i64 %2 to ptr - %4 = getelementptr inbounds %.fault, ptr %3, i32 0, i32 1 + %4 = getelementptr inbounds br label %faultname_exit faultname_exit: ; preds = %faultname_ok, %faultname_no diff --git a/test/test_suite/generic/enum_in_other_module.c3t b/test/test_suite/generic/enum_in_other_module.c3t index 45dcf3e15..d80a9d76d 100644 --- a/test/test_suite/generic/enum_in_other_module.c3t +++ b/test/test_suite/generic/enum_in_other_module.c3t @@ -37,7 +37,7 @@ entry: %error_var4 = alloca i64, align 8 %error_var10 = alloca i64, align 8 %zext = zext i32 %0 to i64 - %ptroffset_any = getelementptr [16 x i8], ptr getelementptr inbounds (%.introspect, ptr @"$ct.test.Enum", i32 0, i32 6), i64 %zext + %ptroffset_any = getelementptr [16 x i8], ptr getelementptr inbounds call void @llvm.memcpy.p0.p0.i32(ptr align 8 %x, ptr align 8 %ptroffset_any, i32 16, i1 false) %1 = call ptr @std.io.stdout() call void @llvm.memcpy.p0.p0.i32(ptr align 8 %x1, ptr align 8 %x, i32 16, i1 false) diff --git a/test/test_suite/stdlib/map_linux.c3t b/test/test_suite/stdlib/map_linux.c3t index 624b15d77..1168b6c79 100644 --- a/test/test_suite/stdlib/map_linux.c3t +++ b/test/test_suite/stdlib/map_linux.c3t @@ -273,13 +273,13 @@ entry: br label %dtable_check dtable_check: ; preds = %dtable_next, %entry - %dtable_ref = phi ptr [ getelementptr inbounds (%.introspect, ptr @"$ct.test.Foo", i32 0, i32 2), %entry ], [ %next_dtable_ref, %dtable_next ] + %dtable_ref = phi ptr [ getelementptr inbounds %dtable_ptr = load ptr, ptr %dtable_ref, align 8 %0 = icmp eq ptr %dtable_ptr, null br i1 %0, label %dtable_found, label %dtable_next dtable_next: ; preds = %dtable_check - %next_dtable_ref = getelementptr inbounds { ptr, ptr, ptr }, ptr %dtable_ptr, i32 0, i32 2 + %next_dtable_ref = getelementptr inbounds br label %dtable_check dtable_found: ; preds = %dtable_check diff --git a/test/unit/stdlib/math/math.c3 b/test/unit/stdlib/math/math.c3 index d4bab1ed1..b0b00befd 100644 --- a/test/unit/stdlib/math/math.c3 +++ b/test/unit/stdlib/math/math.c3 @@ -166,32 +166,32 @@ fn void! test() @test assert(math::round_to_decimals(radians_f, 3) == 0.785f); } -fn void! test_mult_div() +fn void! test_muldiv() { char a = 20; - assert(a.mult_div(20, 10) == 40); + assert(a.muldiv(20, 10) == 40); ichar b = 20; - assert(b.mult_div(20, -10) == -40); + assert(b.muldiv(20, -10) == -40); short c = 16000; - assert(c.mult_div(4, 2) == 32000); + assert(c.muldiv(4, 2) == 32000); ushort d = 16000; - assert(d.mult_div(8, 2) == 64000); + assert(d.muldiv(8, 2) == 64000); int e = 1_000_000; - assert(e.mult_div(40000, 10000) == 4_000_000); + assert(e.muldiv(40000, 10000) == 4_000_000); uint f = 3_000_000_000u; - assert(f.mult_div(110, 100) == 3_300_000_000u); + assert(f.muldiv(110, 100) == 3_300_000_000u); long g = 1_000_000_000_000i64; - assert(g.mult_div(2_000_000_000_000i64, 1_000_000_000i64) == 2_000_000_000_000_000i64); + assert(g.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == 2_000_000_000_000_000i64); ulong h = 1_000_000_000_000u64; - assert(h.mult_div(2_000_000_000_000u64, 1_000_000_000u64) == 2_000_000_000_000_000u64); + assert(h.muldiv(2_000_000_000_000u64, 1_000_000_000u64) == 2_000_000_000_000_000u64); char[<4>] i = {20, 30, 40, 50}; - assert(i.mult_div(12,10) == char[<4>] {24, 36, 48, 60}); - assert(i.mult_div(char[<4>]{11, 12, 13, 14}, char[<4>]{10,10,10,10}) == char[<4>]{22, 36, 52, 70}); + assert(i.muldiv(12,10) == char[<4>] {24, 36, 48, 60}); + assert(i.muldiv(char[<4>]{11, 12, 13, 14}, char[<4>]{10,10,10,10}) == char[<4>]{22, 36, 52, 70}); long[<4>] j = {1_000_000_000_000i64, 2_000_000_000_000i64, 3_000_000_000_000i64, 4_000_000_000_000i64}; - assert(j.mult_div(2_000_000_000_000i64, 1_000_000_000i64) == long[<4>]{2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64}); + assert(j.muldiv(2_000_000_000_000i64, 1_000_000_000i64) == long[<4>]{2_000_000_000_000_000i64, 4_000_000_000_000_000i64, 6_000_000_000_000_000i64, 8_000_000_000_000_000i64}); ichar[<4>] k = {20, 30, 40, 50}; - assert(k.mult_div(20,-10) == ichar[<4>]{-40,-60,-80,-100}); + assert(k.muldiv(20,-10) == ichar[<4>]{-40,-60,-80,-100}); } \ No newline at end of file