aboutsummaryrefslogtreecommitdiff
path: root/lib/compiler_rt
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compiler_rt')
-rw-r--r--lib/compiler_rt/README.md174
-rw-r--r--lib/compiler_rt/ashldi3_test.zig32
-rw-r--r--lib/compiler_rt/ashlti3_test.zig46
-rw-r--r--lib/compiler_rt/ashrdi3_test.zig55
-rw-r--r--lib/compiler_rt/ashrti3_test.zig56
-rw-r--r--lib/compiler_rt/int.zig68
-rw-r--r--lib/compiler_rt/lshrdi3_test.zig55
-rw-r--r--lib/compiler_rt/lshrti3_test.zig46
-rw-r--r--lib/compiler_rt/powiXf2.zig58
-rw-r--r--lib/compiler_rt/powiXf2_test.zig556
-rw-r--r--lib/compiler_rt/shift.zig32
-rw-r--r--lib/compiler_rt/shift_test.zig363
12 files changed, 1218 insertions, 323 deletions
diff --git a/lib/compiler_rt/README.md b/lib/compiler_rt/README.md
index d8df7f5489..a5d6bfdd6b 100644
--- a/lib/compiler_rt/README.md
+++ b/lib/compiler_rt/README.md
@@ -77,15 +77,15 @@ Integer and Float Operations
| ✓ | __ucmpdi2 | u64 | u64 | i32 | .. |
| ✓ | __ucmpti2 | u128 | u128 | i32 | .. |
| | | | | | **Integer Arithmetic** |
-| ✗ | __ashlsi3 | i32 | i32 | i32 | `a << b` [^unused_rl78] |
+| ✓ | __ashlsi3 | i32 | i32 | i32 | `a << b` [^unused_rl78] |
| ✓ | __ashldi3 | i64 | i32 | i64 | .. |
| ✓ | __ashlti3 | i128 | i32 | i128 | .. |
| ✓ | __aeabi_llsl | i32 | i32 | i32 | .. ARM |
-| ✗ | __ashrsi3 | i32 | i32 | i32 | `a >> b` arithmetic (sign fill) [^unused_rl78] |
+| ✓ | __ashrsi3 | i32 | i32 | i32 | `a >> b` arithmetic (sign fill) [^unused_rl78] |
| ✓ | __ashrdi3 | i64 | i32 | i64 | .. |
| ✓ | __ashrti3 | i128 | i32 | i128 | .. |
| ✓ | __aeabi_lasr | i64 | i32 | i64 | .. ARM |
-| ✗ | __lshrsi3 | i32 | i32 | i32 | `a >> b` logical (zero fill) [^unused_rl78] |
+| ✓ | __lshrsi3 | i32 | i32 | i32 | `a >> b` logical (zero fill) [^unused_rl78] |
| ✓ | __lshrdi3 | i64 | i32 | i64 | .. |
| ✓ | __lshrti3 | i128 | i32 | i128 | .. |
| ✓ | __aeabi_llsr | i64 | i32 | i64 | .. ARM |
@@ -114,7 +114,7 @@ Integer and Float Operations
| ✓ | __udivmodti4 | u128 | u128 | u128 | .. |
| ✓ | __divmodsi4 | i32 | i32 | i32 | `a / b, rem.* = a % b` |
| ✓ | __divmoddi4 | i64 | i64 | i64 | .. |
-| ✗ | __divmodti4 | i128 | i128 | i128 | .. [^libgcc_compat] |
+| ✓ | __divmodti4 | i128 | i128 | i128 | .. [^libgcc_compat] |
| | | | | | **Integer Arithmetic with Trapping Overflow**|
| ✓ | __absvsi2 | i32 | i32 | i32 | abs(a) |
| ✓ | __absvdi2 | i64 | i64 | i64 | .. |
@@ -328,11 +328,11 @@ Integer and Float Operations
| ✓ | __negtf2 | f128 | ∅ | f128 | .. |
| ✓ | __negxf2 | f80 | ∅ | f80 | .. |
| | | | | | **Floating point raised to integer power** |
-| ✗ | __powihf2 | f16 | f16 | f16 | `a ^ b` |
-| ✗ | __powisf2 | f32 | f32 | f32 | .. |
-| ✗ | __powidf2 | f64 | f64 | f64 | .. |
-| ✗ | __powitf2 | f128 | f128 | f128 | .. |
-| ✗ | __powixf2 | f80 | f80 | f80 | .. |
+| ✓ | __powihf2 | f16 | i32 | f16 | `a ^ b` |
+| ✓ | __powisf2 | f32 | i32 | f32 | .. |
+| ✓ | __powidf2 | f64 | i32 | f64 | .. |
+| ✓ | __powitf2 | f128 | i32 | f128 | .. |
+| ✓ | __powixf2 | f80 | i32 | f80 | .. |
| ✓ | __mulhc3 | all4 | f16 | f16 | `(a+ib) * (c+id)` |
| ✓ | __mulsc3 | all4 | f32 | f32 | .. |
| ✓ | __muldc3 | all4 | f64 | f64 | .. |
@@ -552,20 +552,156 @@ TODO brief explanation + implementation
| ------ | ------------- | --------- | --------- | --------- | -------------------------- |
| | | | | | **Fixed-Point Fractional** |
-Further content:
+Math functions according to C99 with gnu extension sincos. f16, f80 and f128 functions
+are additionally supported by Zig, but not part of C standard. Alphabetically sorted.
+
+| Done | Name | a | b | Out | Comment |
+| ---- | ------- | --------- | --------- | --------- | -------------------------- |
+| ✓ | __ceilh | f16 | ∅ | f16 |smallest integer value not less than a|
+| ✓ | ceilf | f32 | ∅ | f32 |If a is integer, +-0, +-NaN, or +-infinite, a itself is returned.|
+| ✓ | ceil | f64 | ∅ | f64 | .. |
+| ✓ | __ceilx | f80 | ∅ | f80 | |
+| ✓ | ceilf128 | f128 | ∅ | f128 | .. PPC |
+| ✓ | ceilq | f128 | ∅ | f128 | .. |
+| ✓ | ceill |long double| ∅ |long double| .. |
+| ✓ | __cosh | f16 | ∅ | f16 | `cos(a)=(e^(ia)+e^(-ia))/2`|
+| ✓ | cosf | f32 | ∅ | f32 | .. |
+| ✓ | cos | f64 | ∅ | f64 | .. |
+| ✓ | __cosx | f80 | ∅ | f80 | .. |
+| ✓ | cosf128 | f128 | ∅ | f128 | .. |
+| ✓ | cosq | f128 | ∅ | f128 | .. PPC |
+| ✓ | cosl |long double| ∅ |long double| .. |
+| ✓ | __exph | f16 | ∅ | f16 | `e^a` with e base of natural logarithms|
+| ✓ | expf | f32 | ∅ | f32 | .. |
+| ✓ | exp | f64 | ∅ | f64 | .. |
+| ✓ | __expx | f80 | ∅ | f80 | .. |
+| ✓ | expf128 | f128 | ∅ | f128 | .. |
+| ✓ | expq | f128 | ∅ | f128 | .. PPC |
+| ✓ | expl |long double| ∅ |long double| .. |
+| ✓ | __exp2h | f16 | ∅ | f16 | `2^a` |
+| ✓ | exp2f | f32 | ∅ | f32 | .. |
+| ✓ | exp2 | f64 | ∅ | f64 | .. |
+| ✓ | __exp2x | f80 | ∅ | f80 | .. |
+| ✓ | exp2f128 | f128 | ∅ | f128 | .. |
+| ✓ | exp2q | f128 | ∅ | f128 | .. PPC |
+| ✓ | exp2l |long double| ∅ |long double| .. |
+| ✓ | __fabsh | f16 | ∅ | f16 | absolute value of a |
+| ✓ | fabsf | f32 | ∅ | f32 | .. |
+| ✓ | fabs | f64 | ∅ | f64 | .. |
+| ✓ | __fabsx | f80 | ∅ | f80 | .. |
+| ✓ | fabsf128 | f128 | ∅ | f128 | .. |
+| ✓ | fabsq | f128 | ∅ | f128 | .. PPC |
+| ✓ | fabsl |long double| ∅ |long double| .. |
+| ✓ | __floorh | f16 | ∅ | f16 |largest integer value not greater than a|
+| ✓ | floorf | f32 | ∅ | f32 |If a is integer, +-0, +-NaN, or +-infinite, a itself is returned.|
+| ✓ | floor | f64 | ∅ | f64 | .. |
+| ✓ | __floorx | f80 | ∅ | f80 | .. |
+| ✓ | floorf128 | f128 | ∅ | f128 | .. |
+| ✓ | floorq | f128 | ∅ | f128 | .. PPC |
+| ✓ | floorl |long double| ∅ |long double| .. |
+| ✓ | __fmah | f16 | 2xf16 | f16 | args a,b,c result `(a*b)+c`|
+| ✓ | fmaf | f32 | 2xf32 | f32 |Fused multiply-add for hardware acceleration|
+| ✓ | fma | f64 | 2xf64 | f64 | .. |
+| ✓ | __fmax | f80 | 2xf80 | f80 | .. |
+| ✓ | fmaf128 | f128 | 2xf128 | f128 | .. |
+| ✓ | fmaq | f128 | 2xf128 | f128 | .. PPC |
+| ✓ | fmal |long double|2xlong double|long double| .. |
+| ✓ | __fmaxh | f16 | f16 | f16 | larger value of a,b |
+| ✓ | fmaxf | f32 | f32 | f32 | .. |
+| ✓ | fmax | f64 | f64 | f64 | .. |
+| ✓ | __fmaxx | f80 | f80 | f80 | .. |
+| ✓ | fmaxf128 | f128 | f128 | f128 | .. |
+| ✓ | fmaxq | f128 | f128 | f128 | .. PPC |
+| ✓ | fmaxl |long double|long double|long double| .. |
+| ✓ | __fminh | f16 | f16 | f16 | smaller value of a,b |
+| ✓ | fminf | f32 | f32 | f32 | .. |
+| ✓ | fmin | f64 | f64 | f64 | .. |
+| ✓ | __fminx | f80 | f80 | f80 | .. |
+| ✓ | fminf128 | f128 | f128 | f128 | .. |
+| ✓ | fminq | f128 | f128 | f128 | .. PPC |
+| ✓ | fminl |long double|long double|long double| .. |
+| ✓ | __fmodh | f16 | f16 | f16 |floating-point remainder of division a/b|
+| ✓ | fmodf | f32 | f32 | f32 | .. |
+| ✓ | fmod | f64 | f64 | f64 | .. |
+| ✓ | __fmodx | f80 | f80 | f80 | .. |
+| ✓ | fmodf128 | f128 | f128 | f128 | .. |
+| ✓ | fmodq | f128 | f128 | f128 | .. PPC |
+| ✓ | fmodl |long double|long double|long double| .. |
+| ✓ | __logh | f16 | ∅ | f16 |natural (base-e) logarithm of a|
+| ✓ | logf | f32 | ∅ | f32 | .. |
+| ✓ | log | f64 | ∅ | f64 | .. |
+| ✓ | __logx | f80 | ∅ | f80 | .. |
+| ✓ | logf128 | f128 | ∅ | f128 | .. |
+| ✓ | logq | f128 | ∅ | f128 | .. PPC |
+| ✓ | logl |long double| ∅ |long double| .. |
+| ✓ | __log10h | f16 | ∅ | f16 |common (base-10) logarithm of a|
+| ✓ | log10f | f32 | ∅ | f32 | .. |
+| ✓ | log10 | f64 | ∅ | f64 | .. |
+| ✓ | __log10x | f80 | ∅ | f80 | .. |
+| ✓ | log10f128 | f128 | ∅ | f128 | .. |
+| ✓ | log10q | f128 | ∅ | f128 | .. PPC |
+| ✓ | log10l |long double| ∅ |long double| .. |
+| ✓ | __log2h | f16 | ∅ | f16 | base-2 logarithm of a |
+| ✓ | log2f | f32 | ∅ | f32 | .. |
+| ✓ | log2 | f64 | ∅ | f64 | .. |
+| ✓ | __log2x | f80 | ∅ | f80 | .. |
+| ✓ | log2f128 | f128 | ∅ | f128 | .. |
+| ✓ | log2q | f128 | ∅ | f128 | .. PPC |
+| ✓ | log2l |long double| ∅ |long double| .. |
+| ✓ | __roundh | f16 | ∅ | f16 | a rounded to next int away from zero|
+| ✓ | roundf | f32 | ∅ | f32 | .. |
+| ✓ | round | f64 | ∅ | f64 | .. |
+| ✓ | __roundx | f80 | ∅ | f80 | .. |
+| ✓ | roundf128 | f128 | ∅ | f128 | .. |
+| ✓ | roundq | f128 | ∅ | f128 | .. PPC |
+| ✓ | roundl |long double| ∅ |long double| .. |
+| ✓ | __sinh | f16 | ∅ | f16 | `sin(a)=(e^(ia)-e^(-ia))/2`|
+| ✓ | sinf | f32 | ∅ | f32 | .. |
+| ✓ | sin | f64 | ∅ | f64 | .. |
+| ✓ | __sinx | f80 | ∅ | f80 | .. |
+| ✓ | sinf128 | f128 | ∅ | f128 | .. |
+| ✓ | sinq | f128 | ∅ | f128 | .. PPC |
+| ✓ | sinl |long double| ∅ |long double| .. |
+| ✓ | __sincosh | f16 | 2x *f16 | ∅ |sin and cos of the same angle a|
+| ✓ | sincosf | f32 | 2x *f32 | ∅ |args a,*b,*c, `b.*=sin(x),c.*=cos(x)`|
+| ✓ | sincos | f64 | 2x *f64 | ∅ | .. |
+| ✓ | __sincosx | f80 | 2x *f80 | ∅ | .. |
+| ✓ | sincosf128 | f128 | 2x *f128 | ∅ | .. |
+| ✓ | sincosq | f128 | 2x *f128 | ∅ | .. PPC |
+| ✓ | sincosl |long double| 2x *long double|∅ | .. |
+| ✓ | __sqrth | f16 | ∅ | f16 | square root of a (find `r st. a=r^2`)|
+| ✓ | sqrtf | f32 | ∅ | f32 | .. |
+| ✓ | sqrt | f64 | ∅ | f64 | .. |
+| ✓ | __sqrtx | f80 | ∅ | f80 | .. |
+| ✓ | sqrtf128 | f128 | ∅ | f128 | .. |
+| ✓ | sqrtq | f128 | ∅ | f128 | .. PPC |
+| ✓ | sqrtl |long double| ∅ |long double| .. |
+| ✓ | __tanh | f16 | ∅ | f16 | `tan(x)=sin(x)/cos(x) |
+| ✓ | tanf | f32 | ∅ | f32 | .. |
+| ✓ | tan | f64 | ∅ | f64 | .. |
+| ✓ | __tanx | f80 | ∅ | f80 | .. |
+| ✓ | tanf128 | f128 | ∅ | f128 | .. |
+| ✓ | tanq | f128 | ∅ | f128 | .. PPC |
+| ✓ | tanl |long double| ∅ |long double| .. |
+| ✓ | __trunch | f16 | ∅ | f16 | a rounded to next int towards zero|
+| ✓ | truncf | f32 | ∅ | f32 | .. |
+| ✓ | trunc | f64 | ∅ | f64 | .. |
+| ✓ | __truncx | f80 | ∅ | f80 | .. |
+| ✓ | truncf128 | f128 | ∅ | f128 | .. |
+| ✓ | truncq | f128 | ∅ | f128 | .. PPC |
+| ✓ | truncl |long double| ∅ |long double| .. |
+
+Further content (conditionally) exported with C abi:
- aarch64 outline atomics
+- arm routines (memory routines + memclr [setting to 0], divmod routines and stubs for unwind_cpp)
- atomics
-- msvc things like _alldiv, _aulldiv, _allrem
-- clear cache
-- tls emulation
-- math routines (cos, sin, tan, ceil, floor, exp, exp2, fabs, log, log10, log2, sincos, sqrt)
- bcmp
-- ieee float routines (fma, fmax, fmin, fmod, fabs, float rounding, )
-- arm routines (memory routines + memclr [setting to 0], divmod routines and stubs for unwind_cpp)
+- clear cache
- memory routines (memcmp, memcpy, memset, memmove)
+- msvc things like _alldiv, _aulldiv, _allrem
- objective-c __isPlatformVersionAtLeast check
- stack probe routines
+- tls emulation
-Future work
-
-Arbitrary length integer library routines
+Future work:
+- Arbitrary length integer library routines
diff --git a/lib/compiler_rt/ashldi3_test.zig b/lib/compiler_rt/ashldi3_test.zig
deleted file mode 100644
index b69b7a16ad..0000000000
--- a/lib/compiler_rt/ashldi3_test.zig
+++ /dev/null
@@ -1,32 +0,0 @@
-const __ashldi3 = @import("shift.zig").__ashldi3;
-const testing = @import("std").testing;
-
-fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
- const x = __ashldi3(a, b);
- try testing.expectEqual(@bitCast(i64, expected), x);
-}
-
-test "ashldi3" {
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
-
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
-
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
-
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
-
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
- try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
-}
diff --git a/lib/compiler_rt/ashlti3_test.zig b/lib/compiler_rt/ashlti3_test.zig
deleted file mode 100644
index 5ab53c3b78..0000000000
--- a/lib/compiler_rt/ashlti3_test.zig
+++ /dev/null
@@ -1,46 +0,0 @@
-const __ashlti3 = @import("shift.zig").__ashlti3;
-const testing = @import("std").testing;
-
-fn test__ashlti3(a: i128, b: i32, expected: i128) !void {
- const x = __ashlti3(a, b);
- try testing.expectEqual(expected, x);
-}
-
-test "ashlti3" {
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642BFDB97530ECA8642A)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C857FB72EA61D950C854)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xEDCBA9876543215FEDCBA98765432150)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x876543215FEDCBA98765432150000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x0ECA8642BFDB97530ECA8642A0000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x1D950C857FB72EA61D950C8540000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x3B2A190AFF6E5D4C3B2A190A80000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x76543215FEDCBA987654321500000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xECA8642BFDB97530ECA8642A00000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xD950C857FB72EA61D950C85400000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xB2A190AFF6E5D4C3B2A190A800000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x6543215FEDCBA9876543215000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x5FEDCBA9876543215000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xBFDB97530ECA8642A000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x7FB72EA61D950C854000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190A8000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFEDCBA98765432150000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFDB97530ECA8642A0000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFB72EA61D950C8540000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xF6E5D4C3B2A190A80000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xEDCBA987654321500000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x87654321500000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x0ECA8642A00000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x1D950C85400000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x3B2A190A800000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x76543215000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xECA8642A000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xD950C854000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xB2A190A8000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x65432150000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x50000000000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xA0000000000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x40000000000000000000000000000000)));
- try test__ashlti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x80000000000000000000000000000000)));
-}
diff --git a/lib/compiler_rt/ashrdi3_test.zig b/lib/compiler_rt/ashrdi3_test.zig
deleted file mode 100644
index c40b9bc054..0000000000
--- a/lib/compiler_rt/ashrdi3_test.zig
+++ /dev/null
@@ -1,55 +0,0 @@
-const __ashrdi3 = @import("shift.zig").__ashrdi3;
-const testing = @import("std").testing;
-
-fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
- const x = __ashrdi3(a, b);
- try testing.expectEqual(@bitCast(i64, expected), x);
-}
-
-test "ashrdi3" {
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
-
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
- try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
-}
diff --git a/lib/compiler_rt/ashrti3_test.zig b/lib/compiler_rt/ashrti3_test.zig
deleted file mode 100644
index d456897a27..0000000000
--- a/lib/compiler_rt/ashrti3_test.zig
+++ /dev/null
@@ -1,56 +0,0 @@
-const __ashrti3 = @import("shift.zig").__ashrti3;
-const testing = @import("std").testing;
-
-fn test__ashrti3(a: i128, b: i32, expected: i128) !void {
- const x = __ashrti3(a, b);
- try testing.expectEqual(expected, x);
-}
-
-test "ashrti3" {
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0xFFB72EA61D950C857FB72EA61D950C85)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0xFFDB97530ECA8642BFDB97530ECA8642)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0xFFEDCBA9876543215FEDCBA987654321)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0xFFFFFFFFEDCBA9876543215FEDCBA987)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFB72EA61D950C857FB72EA61)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFDB97530ECA8642BFDB97530)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFEDCBA9876543215FEDCBA98)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFB72EA61D950C857FB72EA6)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFDB97530ECA8642BFDB9753)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9)));
-
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
- try test__ashrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)));
-}
diff --git a/lib/compiler_rt/int.zig b/lib/compiler_rt/int.zig
index b844af1859..6a761807dd 100644
--- a/lib/compiler_rt/int.zig
+++ b/lib/compiler_rt/int.zig
@@ -9,10 +9,12 @@ const arch = builtin.cpu.arch;
const is_test = builtin.is_test;
const common = @import("common.zig");
const udivmod = @import("udivmod.zig").udivmod;
+const __divti3 = @import("divti3.zig").__divti3;
pub const panic = common.panic;
comptime {
+ @export(__divmodti4, .{ .name = "__divmodti4", .linkage = common.linkage, .visibility = common.visibility });
@export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = common.linkage, .visibility = common.visibility });
@export(__mulsi3, .{ .name = "__mulsi3", .linkage = common.linkage, .visibility = common.visibility });
@export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = common.linkage, .visibility = common.visibility });
@@ -33,12 +35,72 @@ comptime {
@export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = common.linkage, .visibility = common.visibility });
}
+pub fn __divmodti4(a: i128, b: i128, rem: *i128) callconv(.C) i128 {
+ const d = __divti3(a, b);
+ rem.* = a -% (d * b);
+ return d;
+}
+
+test "test_divmodti4" {
+ const cases = [_][4]i128{
+ [_]i128{ 0, 1, 0, 0 },
+ [_]i128{ 0, -1, 0, 0 },
+ [_]i128{ 2, 1, 2, 0 },
+ [_]i128{ 2, -1, -2, 0 },
+ [_]i128{ -2, 1, -2, 0 },
+ [_]i128{ -2, -1, 2, 0 },
+ [_]i128{ 7, 5, 1, 2 },
+ [_]i128{ -7, 5, -1, -2 },
+ [_]i128{ 19, 5, 3, 4 },
+ [_]i128{ 19, -5, -3, 4 },
+ [_]i128{ @bitCast(i128, @as(u128, 0x80000000000000000000000000000000)), 8, @bitCast(i128, @as(u128, 0xf0000000000000000000000000000000)), 0 },
+ [_]i128{ @bitCast(i128, @as(u128, 0x80000000000000000000000000000007)), 8, @bitCast(i128, @as(u128, 0xf0000000000000000000000000000001)), -1 },
+ };
+
+ for (cases) |case| {
+ try test_one_divmodti4(case[0], case[1], case[2], case[3]);
+ }
+}
+
+fn test_one_divmodti4(a: i128, b: i128, expected_q: i128, expected_r: i128) !void {
+ var r: i128 = undefined;
+ const q: i128 = __divmodti4(a, b, &r);
+ try testing.expect(q == expected_q and r == expected_r);
+}
+
pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {
const d = __divdi3(a, b);
- rem.* = a -% (d *% b);
+ rem.* = a -% (d * b);
return d;
}
+test "test_divmoddi4" {
+ const cases = [_][4]i64{
+ [_]i64{ 0, 1, 0, 0 },
+ [_]i64{ 0, -1, 0, 0 },
+ [_]i64{ 2, 1, 2, 0 },
+ [_]i64{ 2, -1, -2, 0 },
+ [_]i64{ -2, 1, -2, 0 },
+ [_]i64{ -2, -1, 2, 0 },
+ [_]i64{ 7, 5, 1, 2 },
+ [_]i64{ -7, 5, -1, -2 },
+ [_]i64{ 19, 5, 3, 4 },
+ [_]i64{ 19, -5, -3, 4 },
+ [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000000)), 8, @bitCast(i64, @as(u64, 0xf000000000000000)), 0 },
+ [_]i64{ @bitCast(i64, @as(u64, 0x8000000000000007)), 8, @bitCast(i64, @as(u64, 0xf000000000000001)), -1 },
+ };
+
+ for (cases) |case| {
+ try test_one_divmoddi4(case[0], case[1], case[2], case[3]);
+ }
+}
+
+fn test_one_divmoddi4(a: i64, b: i64, expected_q: i64, expected_r: i64) !void {
+ var r: i64 = undefined;
+ const q: i64 = __divmoddi4(a, b, &r);
+ try testing.expect(q == expected_q and r == expected_r);
+}
+
pub fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?*u64) callconv(.C) u64 {
return udivmod(u64, a, b, maybe_rem);
}
@@ -424,7 +486,7 @@ fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) !void {
}
pub fn __modsi3(n: i32, d: i32) callconv(.C) i32 {
- return n -% __divsi3(n, d) *% d;
+ return n -% __divsi3(n, d) * d;
}
test "test_modsi3" {
@@ -453,7 +515,7 @@ fn test_one_modsi3(a: i32, b: i32, expected_r: i32) !void {
}
pub fn __umodsi3(n: u32, d: u32) callconv(.C) u32 {
- return n -% __udivsi3(n, d) *% d;
+ return n -% __udivsi3(n, d) * d;
}
test "test_umodsi3" {
diff --git a/lib/compiler_rt/lshrdi3_test.zig b/lib/compiler_rt/lshrdi3_test.zig
deleted file mode 100644
index acae7a999a..0000000000
--- a/lib/compiler_rt/lshrdi3_test.zig
+++ /dev/null
@@ -1,55 +0,0 @@
-const __lshrdi3 = @import("shift.zig").__lshrdi3;
-const testing = @import("std").testing;
-
-fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {
- const x = __lshrdi3(a, b);
- try testing.expectEqual(@bitCast(i64, expected), x);
-}
-
-test "lshrdi3" {
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
-
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
- try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
-}
diff --git a/lib/compiler_rt/lshrti3_test.zig b/lib/compiler_rt/lshrti3_test.zig
deleted file mode 100644
index a7db70024e..0000000000
--- a/lib/compiler_rt/lshrti3_test.zig
+++ /dev/null
@@ -1,46 +0,0 @@
-const __lshrti3 = @import("shift.zig").__lshrti3;
-const testing = @import("std").testing;
-
-fn test__lshrti3(a: i128, b: i32, expected: i128) !void {
- const x = __lshrti3(a, b);
- try testing.expectEqual(expected, x);
-}
-
-test "lshrti3" {
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, @bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, @bitCast(i128, @intCast(u128, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190A)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, @bitCast(i128, @intCast(u128, 0x3FB72EA61D950C857FB72EA61D950C85)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, @bitCast(i128, @intCast(u128, 0x1FDB97530ECA8642BFDB97530ECA8642)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, @bitCast(i128, @intCast(u128, 0x0FEDCBA9876543215FEDCBA987654321)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, @bitCast(i128, @intCast(u128, 0x0000000FEDCBA9876543215FEDCBA987)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, @bitCast(i128, @intCast(u128, 0x00000007F6E5D4C3B2A190AFF6E5D4C3)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, @bitCast(i128, @intCast(u128, 0x00000003FB72EA61D950C857FB72EA61)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, @bitCast(i128, @intCast(u128, 0x00000001FDB97530ECA8642BFDB97530)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, @bitCast(i128, @intCast(u128, 0x00000000FEDCBA9876543215FEDCBA98)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, @bitCast(i128, @intCast(u128, 0x000000007F6E5D4C3B2A190AFF6E5D4C)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, @bitCast(i128, @intCast(u128, 0x000000003FB72EA61D950C857FB72EA6)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, @bitCast(i128, @intCast(u128, 0x000000001FDB97530ECA8642BFDB9753)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, @bitCast(i128, @intCast(u128, 0x000000000FEDCBA9876543215FEDCBA9)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, @bitCast(i128, @intCast(u128, 0x000000000000000FEDCBA9876543215F)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, @bitCast(i128, @intCast(u128, 0x0000000000000007F6E5D4C3B2A190AF)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, @bitCast(i128, @intCast(u128, 0x0000000000000003FB72EA61D950C857)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, @bitCast(i128, @intCast(u128, 0x0000000000000001FDB97530ECA8642B)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, @bitCast(i128, @intCast(u128, 0x0000000000000000FEDCBA9876543215)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, @bitCast(i128, @intCast(u128, 0x00000000000000007F6E5D4C3B2A190A)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, @bitCast(i128, @intCast(u128, 0x00000000000000003FB72EA61D950C85)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, @bitCast(i128, @intCast(u128, 0x00000000000000001FDB97530ECA8642)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, @bitCast(i128, @intCast(u128, 0x00000000000000000FEDCBA987654321)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, @bitCast(i128, @intCast(u128, 0x00000000000000000000000FEDCBA987)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, @bitCast(i128, @intCast(u128, 0x000000000000000000000007F6E5D4C3)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, @bitCast(i128, @intCast(u128, 0x000000000000000000000003FB72EA61)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, @bitCast(i128, @intCast(u128, 0x000000000000000000000001FDB97530)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, @bitCast(i128, @intCast(u128, 0x000000000000000000000000FEDCBA98)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, @bitCast(i128, @intCast(u128, 0x0000000000000000000000007F6E5D4C)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, @bitCast(i128, @intCast(u128, 0x0000000000000000000000003FB72EA6)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, @bitCast(i128, @intCast(u128, 0x0000000000000000000000001FDB9753)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000FEDCBA9)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, @bitCast(i128, @intCast(u128, 0x0000000000000000000000000000000F)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000007)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000003)));
- try test__lshrti3(@bitCast(i128, @intCast(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, @bitCast(i128, @intCast(u128, 0x00000000000000000000000000000001)));
-}
diff --git a/lib/compiler_rt/powiXf2.zig b/lib/compiler_rt/powiXf2.zig
new file mode 100644
index 0000000000..581dd4a909
--- /dev/null
+++ b/lib/compiler_rt/powiXf2.zig
@@ -0,0 +1,58 @@
+//! a raised to integer power of b
+//! ported from https://github.com/llvm-mirror/compiler-rt/blob/release_80/lib/builtins/powisf2.c
+//! Multiplication order (left-to-right or right-to-left) does not matter for
+//! error propagation and this method is optimized for performance, not accuracy.
+
+const builtin = @import("builtin");
+const common = @import("common.zig");
+const std = @import("std");
+
+pub const panic = common.panic;
+
+comptime {
+ @export(__powihf2, .{ .name = "__powihf2", .linkage = common.linkage, .visibility = common.visibility });
+ @export(__powisf2, .{ .name = "__powisf2", .linkage = common.linkage, .visibility = common.visibility });
+ @export(__powidf2, .{ .name = "__powidf2", .linkage = common.linkage, .visibility = common.visibility });
+ @export(__powitf2, .{ .name = "__powitf2", .linkage = common.linkage, .visibility = common.visibility });
+ @export(__powixf2, .{ .name = "__powixf2", .linkage = common.linkage, .visibility = common.visibility });
+}
+
+inline fn powiXf2(comptime FT: type, a: FT, b: i32) FT {
+ var x_a: FT = a;
+ var x_b: i32 = b;
+ const is_recip: bool = b < 0;
+ var r: FT = 1.0;
+ while (true) {
+ if (@bitCast(u32, x_b) & @as(u32, 1) != 0) {
+ r *= x_a;
+ }
+ x_b = @divTrunc(x_b, @as(i32, 2));
+ if (x_b == 0) break;
+ x_a *= x_a; // Multiplication of x_a propagates the error
+ }
+ return if (is_recip) 1 / r else r;
+}
+
+pub fn __powihf2(a: f16, b: i32) callconv(.C) f16 {
+ return powiXf2(f16, a, b);
+}
+
+pub fn __powisf2(a: f32, b: i32) callconv(.C) f32 {
+ return powiXf2(f32, a, b);
+}
+
+pub fn __powidf2(a: f64, b: i32) callconv(.C) f64 {
+ return powiXf2(f64, a, b);
+}
+
+pub fn __powitf2(a: f128, b: i32) callconv(.C) f128 {
+ return powiXf2(f128, a, b);
+}
+
+pub fn __powixf2(a: f80, b: i32) callconv(.C) f80 {
+ return powiXf2(f80, a, b);
+}
+
+test {
+ _ = @import("powiXf2_test.zig");
+}
diff --git a/lib/compiler_rt/powiXf2_test.zig b/lib/compiler_rt/powiXf2_test.zig
new file mode 100644
index 0000000000..b1f9d2b538
--- /dev/null
+++ b/lib/compiler_rt/powiXf2_test.zig
@@ -0,0 +1,556 @@
+// ported from https://github.com/llvm-mirror/compiler-rt/blob/release_80/test/builtins/Unit/
+// powisf2_test.c, powidf2_test.c, powitf2_test.c, powixf2_test.c
+// powihf2 adapted from powisf2 tests
+
+const powiXf2 = @import("powiXf2.zig");
+const testing = @import("std").testing;
+const math = @import("std").math;
+
+fn test__powihf2(a: f16, b: i32, expected: f16) !void {
+ var result = powiXf2.__powihf2(a, b);
+ try testing.expectEqual(expected, result);
+}
+
+fn test__powisf2(a: f32, b: i32, expected: f32) !void {
+ var result = powiXf2.__powisf2(a, b);
+ try testing.expectEqual(expected, result);
+}
+
+fn test__powidf2(a: f64, b: i32, expected: f64) !void {
+ var result = powiXf2.__powidf2(a, b);
+ try testing.expectEqual(expected, result);
+}
+
+fn test__powitf2(a: f128, b: i32, expected: f128) !void {
+ var result = powiXf2.__powitf2(a, b);
+ try testing.expectEqual(expected, result);
+}
+
+fn test__powixf2(a: f80, b: i32, expected: f80) !void {
+ var result = powiXf2.__powixf2(a, b);
+ try testing.expectEqual(expected, result);
+}
+
+test "powihf2" {
+ try test__powisf2(0, 0, 1);
+ try test__powihf2(1, 0, 1);
+ try test__powihf2(1.5, 0, 1);
+ try test__powihf2(2, 0, 1);
+ try test__powihf2(math.inf_f16, 0, 1);
+
+ try test__powihf2(-0.0, 0, 1);
+ try test__powihf2(-1, 0, 1);
+ try test__powihf2(-1.5, 0, 1);
+ try test__powihf2(-2, 0, 1);
+ try test__powihf2(-math.inf_f16, 0, 1);
+
+ try test__powihf2(0, 1, 0);
+ try test__powihf2(0, 2, 0);
+ try test__powihf2(0, 3, 0);
+ try test__powihf2(0, 4, 0);
+ try test__powihf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powihf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
+
+ try test__powihf2(-0.0, 1, -0.0);
+ try test__powihf2(-0.0, 2, 0);
+ try test__powihf2(-0.0, 3, -0.0);
+ try test__powihf2(-0.0, 4, 0);
+ try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
+
+ try test__powihf2(1, 1, 1);
+ try test__powihf2(1, 2, 1);
+ try test__powihf2(1, 3, 1);
+ try test__powihf2(1, 4, 1);
+ try test__powihf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
+ try test__powihf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
+
+ try test__powihf2(math.inf_f16, 1, math.inf_f16);
+ try test__powihf2(math.inf_f16, 2, math.inf_f16);
+ try test__powihf2(math.inf_f16, 3, math.inf_f16);
+ try test__powihf2(math.inf_f16, 4, math.inf_f16);
+ try test__powihf2(math.inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f16);
+ try test__powihf2(math.inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFF)), math.inf_f16);
+
+ try test__powihf2(-math.inf_f16, 1, -math.inf_f16);
+ try test__powihf2(-math.inf_f16, 2, math.inf_f16);
+ try test__powihf2(-math.inf_f16, 3, -math.inf_f16);
+ try test__powihf2(-math.inf_f16, 4, math.inf_f16);
+ try test__powihf2(-math.inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f16);
+ try test__powihf2(-math.inf_f16, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -math.inf_f16);
+ //
+ try test__powihf2(0, -1, math.inf_f16);
+ try test__powihf2(0, -2, math.inf_f16);
+ try test__powihf2(0, -3, math.inf_f16);
+ try test__powihf2(0, -4, math.inf_f16);
+ try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f16); // 0 ^ anything = +inf
+ try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000001)), math.inf_f16);
+ try test__powihf2(0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f16);
+
+ try test__powihf2(-0.0, -1, -math.inf_f16);
+ try test__powihf2(-0.0, -2, math.inf_f16);
+ try test__powihf2(-0.0, -3, -math.inf_f16);
+ try test__powihf2(-0.0, -4, math.inf_f16);
+ try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f16); // -0 ^ anything even = +inf
+ try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -math.inf_f16); // -0 ^ anything odd = -inf
+ try test__powihf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f16);
+
+ try test__powihf2(1, -1, 1);
+ try test__powihf2(1, -2, 1);
+ try test__powihf2(1, -3, 1);
+ try test__powihf2(1, -4, 1);
+ try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1); // 1.0 ^ anything = 1
+ try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
+ try test__powihf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
+
+ try test__powihf2(math.inf_f16, -1, 0);
+ try test__powihf2(math.inf_f16, -2, 0);
+ try test__powihf2(math.inf_f16, -3, 0);
+ try test__powihf2(math.inf_f16, -4, 0);
+ try test__powihf2(math.inf_f16, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powihf2(math.inf_f16, @bitCast(i32, @as(u32, 0x80000001)), 0);
+ try test__powihf2(math.inf_f16, @bitCast(i32, @as(u32, 0x80000000)), 0);
+ //
+ try test__powihf2(-math.inf_f16, -1, -0.0);
+ try test__powihf2(-math.inf_f16, -2, 0);
+ try test__powihf2(-math.inf_f16, -3, -0.0);
+ try test__powihf2(-math.inf_f16, -4, 0);
+ try test__powihf2(-math.inf_f16, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powihf2(-math.inf_f16, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
+ try test__powihf2(-math.inf_f16, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powihf2(2, 10, 1024.0);
+ try test__powihf2(-2, 10, 1024.0);
+ try test__powihf2(2, -10, 1.0 / 1024.0);
+ try test__powihf2(-2, -10, 1.0 / 1024.0);
+
+ try test__powihf2(2, 14, 16384.0);
+ try test__powihf2(-2, 14, 16384.0);
+ try test__powihf2(2, 15, 32768.0);
+ try test__powihf2(-2, 15, -32768.0);
+ try test__powihf2(2, 16, math.inf_f16);
+ try test__powihf2(-2, 16, math.inf_f16);
+
+ try test__powihf2(2, -13, 1.0 / 8192.0);
+ try test__powihf2(-2, -13, -1.0 / 8192.0);
+ try test__powihf2(2, -15, 1.0 / 32768.0);
+ try test__powihf2(-2, -15, -1.0 / 32768.0);
+ try test__powihf2(2, -16, 0.0); // expected = 0.0 = 1/(-2**16)
+ try test__powihf2(-2, -16, 0.0); // expected = 0.0 = 1/(2**16)
+}
+
+test "powisf2" {
+ try test__powisf2(0, 0, 1);
+ try test__powisf2(1, 0, 1);
+ try test__powisf2(1.5, 0, 1);
+ try test__powisf2(2, 0, 1);
+ try test__powisf2(math.inf_f32, 0, 1);
+
+ try test__powisf2(-0.0, 0, 1);
+ try test__powisf2(-1, 0, 1);
+ try test__powisf2(-1.5, 0, 1);
+ try test__powisf2(-2, 0, 1);
+ try test__powisf2(-math.inf_f32, 0, 1);
+
+ try test__powisf2(0, 1, 0);
+ try test__powisf2(0, 2, 0);
+ try test__powisf2(0, 3, 0);
+ try test__powisf2(0, 4, 0);
+ try test__powisf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powisf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
+
+ try test__powisf2(-0.0, 1, -0.0);
+ try test__powisf2(-0.0, 2, 0);
+ try test__powisf2(-0.0, 3, -0.0);
+ try test__powisf2(-0.0, 4, 0);
+ try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
+
+ try test__powisf2(1, 1, 1);
+ try test__powisf2(1, 2, 1);
+ try test__powisf2(1, 3, 1);
+ try test__powisf2(1, 4, 1);
+ try test__powisf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
+ try test__powisf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
+
+ try test__powisf2(math.inf_f32, 1, math.inf_f32);
+ try test__powisf2(math.inf_f32, 2, math.inf_f32);
+ try test__powisf2(math.inf_f32, 3, math.inf_f32);
+ try test__powisf2(math.inf_f32, 4, math.inf_f32);
+ try test__powisf2(math.inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f32);
+ try test__powisf2(math.inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFF)), math.inf_f32);
+
+ try test__powisf2(-math.inf_f32, 1, -math.inf_f32);
+ try test__powisf2(-math.inf_f32, 2, math.inf_f32);
+ try test__powisf2(-math.inf_f32, 3, -math.inf_f32);
+ try test__powisf2(-math.inf_f32, 4, math.inf_f32);
+ try test__powisf2(-math.inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f32);
+ try test__powisf2(-math.inf_f32, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -math.inf_f32);
+
+ try test__powisf2(0, -1, math.inf_f32);
+ try test__powisf2(0, -2, math.inf_f32);
+ try test__powisf2(0, -3, math.inf_f32);
+ try test__powisf2(0, -4, math.inf_f32);
+ try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f32);
+ try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000001)), math.inf_f32);
+ try test__powisf2(0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f32);
+
+ try test__powisf2(-0.0, -1, -math.inf_f32);
+ try test__powisf2(-0.0, -2, math.inf_f32);
+ try test__powisf2(-0.0, -3, -math.inf_f32);
+ try test__powisf2(-0.0, -4, math.inf_f32);
+ try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f32);
+ try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -math.inf_f32);
+ try test__powisf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f32);
+
+ try test__powisf2(1, -1, 1);
+ try test__powisf2(1, -2, 1);
+ try test__powisf2(1, -3, 1);
+ try test__powisf2(1, -4, 1);
+ try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
+ try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
+ try test__powisf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
+
+ try test__powisf2(math.inf_f32, -1, 0);
+ try test__powisf2(math.inf_f32, -2, 0);
+ try test__powisf2(math.inf_f32, -3, 0);
+ try test__powisf2(math.inf_f32, -4, 0);
+ try test__powisf2(math.inf_f32, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powisf2(math.inf_f32, @bitCast(i32, @as(u32, 0x80000001)), 0);
+ try test__powisf2(math.inf_f32, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powisf2(-math.inf_f32, -1, -0.0);
+ try test__powisf2(-math.inf_f32, -2, 0);
+ try test__powisf2(-math.inf_f32, -3, -0.0);
+ try test__powisf2(-math.inf_f32, -4, 0);
+ try test__powisf2(-math.inf_f32, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powisf2(-math.inf_f32, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
+ try test__powisf2(-math.inf_f32, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powisf2(2.0, 10, 1024.0);
+ try test__powisf2(-2, 10, 1024.0);
+ try test__powisf2(2, -10, 1.0 / 1024.0);
+ try test__powisf2(-2, -10, 1.0 / 1024.0);
+ //
+ try test__powisf2(2, 19, 524288.0);
+ try test__powisf2(-2, 19, -524288.0);
+ try test__powisf2(2, -19, 1.0 / 524288.0);
+ try test__powisf2(-2, -19, -1.0 / 524288.0);
+
+ try test__powisf2(2, 31, 2147483648.0);
+ try test__powisf2(-2, 31, -2147483648.0);
+ try test__powisf2(2, -31, 1.0 / 2147483648.0);
+ try test__powisf2(-2, -31, -1.0 / 2147483648.0);
+}
+
+test "powidf2" {
+ try test__powidf2(0, 0, 1);
+ try test__powidf2(1, 0, 1);
+ try test__powidf2(1.5, 0, 1);
+ try test__powidf2(2, 0, 1);
+ try test__powidf2(math.inf_f64, 0, 1);
+
+ try test__powidf2(-0.0, 0, 1);
+ try test__powidf2(-1, 0, 1);
+ try test__powidf2(-1.5, 0, 1);
+ try test__powidf2(-2, 0, 1);
+ try test__powidf2(-math.inf_f64, 0, 1);
+
+ try test__powidf2(0, 1, 0);
+ try test__powidf2(0, 2, 0);
+ try test__powidf2(0, 3, 0);
+ try test__powidf2(0, 4, 0);
+ try test__powidf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powidf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
+
+ try test__powidf2(-0.0, 1, -0.0);
+ try test__powidf2(-0.0, 2, 0);
+ try test__powidf2(-0.0, 3, -0.0);
+ try test__powidf2(-0.0, 4, 0);
+ try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
+
+ try test__powidf2(1, 1, 1);
+ try test__powidf2(1, 2, 1);
+ try test__powidf2(1, 3, 1);
+ try test__powidf2(1, 4, 1);
+ try test__powidf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
+ try test__powidf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
+
+ try test__powidf2(math.inf_f64, 1, math.inf_f64);
+ try test__powidf2(math.inf_f64, 2, math.inf_f64);
+ try test__powidf2(math.inf_f64, 3, math.inf_f64);
+ try test__powidf2(math.inf_f64, 4, math.inf_f64);
+ try test__powidf2(math.inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f64);
+ try test__powidf2(math.inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFF)), math.inf_f64);
+
+ try test__powidf2(-math.inf_f64, 1, -math.inf_f64);
+ try test__powidf2(-math.inf_f64, 2, math.inf_f64);
+ try test__powidf2(-math.inf_f64, 3, -math.inf_f64);
+ try test__powidf2(-math.inf_f64, 4, math.inf_f64);
+ try test__powidf2(-math.inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f64);
+ try test__powidf2(-math.inf_f64, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -math.inf_f64);
+
+ try test__powidf2(0, -1, math.inf_f64);
+ try test__powidf2(0, -2, math.inf_f64);
+ try test__powidf2(0, -3, math.inf_f64);
+ try test__powidf2(0, -4, math.inf_f64);
+ try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f64);
+ try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000001)), math.inf_f64);
+ try test__powidf2(0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f64);
+
+ try test__powidf2(-0.0, -1, -math.inf_f64);
+ try test__powidf2(-0.0, -2, math.inf_f64);
+ try test__powidf2(-0.0, -3, -math.inf_f64);
+ try test__powidf2(-0.0, -4, math.inf_f64);
+ try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f64);
+ try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -math.inf_f64);
+ try test__powidf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f64);
+
+ try test__powidf2(1, -1, 1);
+ try test__powidf2(1, -2, 1);
+ try test__powidf2(1, -3, 1);
+ try test__powidf2(1, -4, 1);
+ try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
+ try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
+ try test__powidf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
+
+ try test__powidf2(math.inf_f64, -1, 0);
+ try test__powidf2(math.inf_f64, -2, 0);
+ try test__powidf2(math.inf_f64, -3, 0);
+ try test__powidf2(math.inf_f64, -4, 0);
+ try test__powidf2(math.inf_f64, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powidf2(math.inf_f64, @bitCast(i32, @as(u32, 0x80000001)), 0);
+ try test__powidf2(math.inf_f64, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powidf2(-math.inf_f64, -1, -0.0);
+ try test__powidf2(-math.inf_f64, -2, 0);
+ try test__powidf2(-math.inf_f64, -3, -0.0);
+ try test__powidf2(-math.inf_f64, -4, 0);
+ try test__powidf2(-math.inf_f64, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powidf2(-math.inf_f64, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
+ try test__powidf2(-math.inf_f64, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powidf2(2, 10, 1024.0);
+ try test__powidf2(-2, 10, 1024.0);
+ try test__powidf2(2, -10, 1.0 / 1024.0);
+ try test__powidf2(-2, -10, 1.0 / 1024.0);
+
+ try test__powidf2(2, 19, 524288.0);
+ try test__powidf2(-2, 19, -524288.0);
+ try test__powidf2(2, -19, 1.0 / 524288.0);
+ try test__powidf2(-2, -19, -1.0 / 524288.0);
+
+ try test__powidf2(2, 31, 2147483648.0);
+ try test__powidf2(-2, 31, -2147483648.0);
+ try test__powidf2(2, -31, 1.0 / 2147483648.0);
+ try test__powidf2(-2, -31, -1.0 / 2147483648.0);
+}
+
+test "powitf2" {
+ try test__powitf2(0, 0, 1);
+ try test__powitf2(1, 0, 1);
+ try test__powitf2(1.5, 0, 1);
+ try test__powitf2(2, 0, 1);
+ try test__powitf2(math.inf_f128, 0, 1);
+
+ try test__powitf2(-0.0, 0, 1);
+ try test__powitf2(-1, 0, 1);
+ try test__powitf2(-1.5, 0, 1);
+ try test__powitf2(-2, 0, 1);
+ try test__powitf2(-math.inf_f128, 0, 1);
+
+ try test__powitf2(0, 1, 0);
+ try test__powitf2(0, 2, 0);
+ try test__powitf2(0, 3, 0);
+ try test__powitf2(0, 4, 0);
+ try test__powitf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powitf2(0, 0x7FFFFFFF, 0);
+
+ try test__powitf2(-0.0, 1, -0.0);
+ try test__powitf2(-0.0, 2, 0);
+ try test__powitf2(-0.0, 3, -0.0);
+ try test__powitf2(-0.0, 4, 0);
+ try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
+
+ try test__powitf2(1, 1, 1);
+ try test__powitf2(1, 2, 1);
+ try test__powitf2(1, 3, 1);
+ try test__powitf2(1, 4, 1);
+ try test__powitf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
+ try test__powitf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
+
+ try test__powitf2(math.inf_f128, 1, math.inf_f128);
+ try test__powitf2(math.inf_f128, 2, math.inf_f128);
+ try test__powitf2(math.inf_f128, 3, math.inf_f128);
+ try test__powitf2(math.inf_f128, 4, math.inf_f128);
+ try test__powitf2(math.inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f128);
+ try test__powitf2(math.inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFF)), math.inf_f128);
+
+ try test__powitf2(-math.inf_f128, 1, -math.inf_f128);
+ try test__powitf2(-math.inf_f128, 2, math.inf_f128);
+ try test__powitf2(-math.inf_f128, 3, -math.inf_f128);
+ try test__powitf2(-math.inf_f128, 4, math.inf_f128);
+ try test__powitf2(-math.inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f128);
+ try test__powitf2(-math.inf_f128, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -math.inf_f128);
+
+ try test__powitf2(0, -1, math.inf_f128);
+ try test__powitf2(0, -2, math.inf_f128);
+ try test__powitf2(0, -3, math.inf_f128);
+ try test__powitf2(0, -4, math.inf_f128);
+ try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f128);
+ try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000001)), math.inf_f128);
+ try test__powitf2(0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f128);
+
+ try test__powitf2(-0.0, -1, -math.inf_f128);
+ try test__powitf2(-0.0, -2, math.inf_f128);
+ try test__powitf2(-0.0, -3, -math.inf_f128);
+ try test__powitf2(-0.0, -4, math.inf_f128);
+ try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f128);
+ try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -math.inf_f128);
+ try test__powitf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f128);
+
+ try test__powitf2(1, -1, 1);
+ try test__powitf2(1, -2, 1);
+ try test__powitf2(1, -3, 1);
+ try test__powitf2(1, -4, 1);
+ try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
+ try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
+ try test__powitf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
+
+ try test__powitf2(math.inf_f128, -1, 0);
+ try test__powitf2(math.inf_f128, -2, 0);
+ try test__powitf2(math.inf_f128, -3, 0);
+ try test__powitf2(math.inf_f128, -4, 0);
+ try test__powitf2(math.inf_f128, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powitf2(math.inf_f128, @bitCast(i32, @as(u32, 0x80000001)), 0);
+ try test__powitf2(math.inf_f128, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powitf2(-math.inf_f128, -1, -0.0);
+ try test__powitf2(-math.inf_f128, -2, 0);
+ try test__powitf2(-math.inf_f128, -3, -0.0);
+ try test__powitf2(-math.inf_f128, -4, 0);
+ try test__powitf2(-math.inf_f128, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powitf2(-math.inf_f128, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
+ try test__powitf2(-math.inf_f128, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powitf2(2, 10, 1024.0);
+ try test__powitf2(-2, 10, 1024.0);
+ try test__powitf2(2, -10, 1.0 / 1024.0);
+ try test__powitf2(-2, -10, 1.0 / 1024.0);
+
+ try test__powitf2(2, 19, 524288.0);
+ try test__powitf2(-2, 19, -524288.0);
+ try test__powitf2(2, -19, 1.0 / 524288.0);
+ try test__powitf2(-2, -19, -1.0 / 524288.0);
+
+ try test__powitf2(2, 31, 2147483648.0);
+ try test__powitf2(-2, 31, -2147483648.0);
+ try test__powitf2(2, -31, 1.0 / 2147483648.0);
+ try test__powitf2(-2, -31, -1.0 / 2147483648.0);
+}
+
+test "powixf2" {
+ try test__powixf2(0, 0, 1);
+ try test__powixf2(1, 0, 1);
+ try test__powixf2(1.5, 0, 1);
+ try test__powixf2(2, 0, 1);
+ try test__powixf2(math.inf_f80, 0, 1);
+
+ try test__powixf2(-0.0, 0, 1);
+ try test__powixf2(-1, 0, 1);
+ try test__powixf2(-1.5, 0, 1);
+ try test__powixf2(-2, 0, 1);
+ try test__powixf2(-math.inf_f80, 0, 1);
+
+ try test__powixf2(0, 1, 0);
+ try test__powixf2(0, 2, 0);
+ try test__powixf2(0, 3, 0);
+ try test__powixf2(0, 4, 0);
+ try test__powixf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powixf2(0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 0);
+
+ try test__powixf2(-0.0, 1, -0.0);
+ try test__powixf2(-0.0, 2, 0);
+ try test__powixf2(-0.0, 3, -0.0);
+ try test__powixf2(-0.0, 4, 0);
+ try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 0);
+ try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -0.0);
+
+ try test__powixf2(1, 1, 1);
+ try test__powixf2(1, 2, 1);
+ try test__powixf2(1, 3, 1);
+ try test__powixf2(1, 4, 1);
+ try test__powixf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFE)), 1);
+ try test__powixf2(1, @bitCast(i32, @as(u32, 0x7FFFFFFF)), 1);
+
+ try test__powixf2(math.inf_f80, 1, math.inf_f80);
+ try test__powixf2(math.inf_f80, 2, math.inf_f80);
+ try test__powixf2(math.inf_f80, 3, math.inf_f80);
+ try test__powixf2(math.inf_f80, 4, math.inf_f80);
+ try test__powixf2(math.inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f80);
+ try test__powixf2(math.inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFF)), math.inf_f80);
+
+ try test__powixf2(-math.inf_f80, 1, -math.inf_f80);
+ try test__powixf2(-math.inf_f80, 2, math.inf_f80);
+ try test__powixf2(-math.inf_f80, 3, -math.inf_f80);
+ try test__powixf2(-math.inf_f80, 4, math.inf_f80);
+ try test__powixf2(-math.inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFE)), math.inf_f80);
+ try test__powixf2(-math.inf_f80, @bitCast(i32, @as(u32, 0x7FFFFFFF)), -math.inf_f80);
+
+ try test__powixf2(0, -1, math.inf_f80);
+ try test__powixf2(0, -2, math.inf_f80);
+ try test__powixf2(0, -3, math.inf_f80);
+ try test__powixf2(0, -4, math.inf_f80);
+ try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f80);
+ try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000001)), math.inf_f80);
+ try test__powixf2(0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f80);
+
+ try test__powixf2(-0.0, -1, -math.inf_f80);
+ try test__powixf2(-0.0, -2, math.inf_f80);
+ try test__powixf2(-0.0, -3, -math.inf_f80);
+ try test__powixf2(-0.0, -4, math.inf_f80);
+ try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000002)), math.inf_f80);
+ try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000001)), -math.inf_f80);
+ try test__powixf2(-0.0, @bitCast(i32, @as(u32, 0x80000000)), math.inf_f80);
+
+ try test__powixf2(1, -1, 1);
+ try test__powixf2(1, -2, 1);
+ try test__powixf2(1, -3, 1);
+ try test__powixf2(1, -4, 1);
+ try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000002)), 1);
+ try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000001)), 1);
+ try test__powixf2(1, @bitCast(i32, @as(u32, 0x80000000)), 1);
+
+ try test__powixf2(math.inf_f80, -1, 0);
+ try test__powixf2(math.inf_f80, -2, 0);
+ try test__powixf2(math.inf_f80, -3, 0);
+ try test__powixf2(math.inf_f80, -4, 0);
+ try test__powixf2(math.inf_f80, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powixf2(math.inf_f80, @bitCast(i32, @as(u32, 0x80000001)), 0);
+ try test__powixf2(math.inf_f80, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powixf2(-math.inf_f80, -1, -0.0);
+ try test__powixf2(-math.inf_f80, -2, 0);
+ try test__powixf2(-math.inf_f80, -3, -0.0);
+ try test__powixf2(-math.inf_f80, -4, 0);
+ try test__powixf2(-math.inf_f80, @bitCast(i32, @as(u32, 0x80000002)), 0);
+ try test__powixf2(-math.inf_f80, @bitCast(i32, @as(u32, 0x80000001)), -0.0);
+ try test__powixf2(-math.inf_f80, @bitCast(i32, @as(u32, 0x80000000)), 0);
+
+ try test__powixf2(2, 10, 1024.0);
+ try test__powixf2(-2, 10, 1024.0);
+ try test__powixf2(2, -10, 1.0 / 1024.0);
+ try test__powixf2(-2, -10, 1.0 / 1024.0);
+
+ try test__powixf2(2, 19, 524288.0);
+ try test__powixf2(-2, 19, -524288.0);
+ try test__powixf2(2, -19, 1.0 / 524288.0);
+ try test__powixf2(-2, -19, -1.0 / 524288.0);
+
+ try test__powixf2(2, 31, 2147483648.0);
+ try test__powixf2(-2, 31, -2147483648.0);
+ try test__powixf2(2, -31, 1.0 / 2147483648.0);
+ try test__powixf2(-2, -31, -1.0 / 2147483648.0);
+}
diff --git a/lib/compiler_rt/shift.zig b/lib/compiler_rt/shift.zig
index 6d711ee553..df6ce82059 100644
--- a/lib/compiler_rt/shift.zig
+++ b/lib/compiler_rt/shift.zig
@@ -7,6 +7,11 @@ const common = @import("common.zig");
pub const panic = common.panic;
comptime {
+ // symbol compatibility with libgcc
+ @export(__ashlsi3, .{ .name = "__ashlsi3", .linkage = common.linkage, .visibility = common.visibility });
+ @export(__ashrsi3, .{ .name = "__ashrsi3", .linkage = common.linkage, .visibility = common.visibility });
+ @export(__lshrsi3, .{ .name = "__lshrsi3", .linkage = common.linkage, .visibility = common.visibility });
+
@export(__ashlti3, .{ .name = "__ashlti3", .linkage = common.linkage, .visibility = common.visibility });
@export(__ashrti3, .{ .name = "__ashrti3", .linkage = common.linkage, .visibility = common.visibility });
@export(__lshrti3, .{ .name = "__lshrti3", .linkage = common.linkage, .visibility = common.visibility });
@@ -37,7 +42,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {
};
}
-// Arithmetic shift left
+// Arithmetic shift left: shift in 0 from right to left
// Precondition: 0 <= b < bits_in_dword
inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
const dwords = Dwords(T, false);
@@ -60,7 +65,7 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
return output.all;
}
-// Arithmetic shift right
+// Arithmetic shift right: shift in 1 from left to right
// Precondition: 0 <= b < T.bit_count
inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
const dwords = Dwords(T, true);
@@ -87,7 +92,7 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
return output.all;
}
-// Logical shift right
+// Logical shift right: shift in 0 from left to right
// Precondition: 0 <= b < T.bit_count
inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
const dwords = Dwords(T, false);
@@ -110,6 +115,18 @@ inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
return output.all;
}
+pub fn __ashlsi3(a: i32, b: i32) callconv(.C) i32 {
+ return ashlXi3(i32, a, b);
+}
+
+pub fn __ashrsi3(a: i32, b: i32) callconv(.C) i32 {
+ return ashrXi3(i32, a, b);
+}
+
+pub fn __lshrsi3(a: i32, b: i32) callconv(.C) i32 {
+ return lshrXi3(i32, a, b);
+}
+
pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 {
return ashlXi3(i64, a, b);
}
@@ -144,12 +161,5 @@ pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
}
test {
- _ = @import("ashrdi3_test.zig");
- _ = @import("ashrti3_test.zig");
-
- _ = @import("ashldi3_test.zig");
- _ = @import("ashlti3_test.zig");
-
- _ = @import("lshrdi3_test.zig");
- _ = @import("lshrti3_test.zig");
+ _ = @import("shift_test.zig");
}
diff --git a/lib/compiler_rt/shift_test.zig b/lib/compiler_rt/shift_test.zig
new file mode 100644
index 0000000000..b9c5dc64fa
--- /dev/null
+++ b/lib/compiler_rt/shift_test.zig
@@ -0,0 +1,363 @@
+const testing = @import("std").testing;
+const shift = @import("shift.zig");
+
+// arithmetic shift left
+const __ashlsi3 = shift.__ashlsi3;
+const __ashldi3 = shift.__ashldi3;
+const __ashlti3 = shift.__ashlti3;
+
+// arithmetic shift right
+const __ashrsi3 = shift.__ashrsi3;
+const __ashrdi3 = shift.__ashrdi3;
+const __ashrti3 = shift.__ashrti3;
+
+// logic shift right
+const __lshrsi3 = shift.__lshrsi3;
+const __lshrdi3 = shift.__lshrdi3;
+const __lshrti3 = shift.__lshrti3;
+
+fn test__ashlsi3(a: i32, b: i32, expected: u32) !void {
+ const x = __ashlsi3(a, b);
+ try testing.expectEqual(expected, @bitCast(u32, x));
+}
+fn test__ashldi3(a: i64, b: i32, expected: u64) !void {
+ const x = __ashldi3(a, b);
+ try testing.expectEqual(expected, @bitCast(u64, x));
+}
+fn test__ashlti3(a: i128, b: i32, expected: u128) !void {
+ const x = __ashlti3(a, b);
+ try testing.expectEqual(expected, @bitCast(u128, x));
+}
+
+test "ashlsi3" {
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 0, 0x12ABCDEF);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 1, 0x25579BDE);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 2, 0x4AAF37BC);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 3, 0x955E6F78);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 4, 0x2ABCDEF0);
+
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 28, 0xF0000000);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 29, 0xE0000000);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 30, 0xC0000000);
+ try test__ashlsi3(@bitCast(i32, @as(u32, 0x12ABCDEF)), 31, 0x80000000);
+}
+
+test "ashldi3" {
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
+
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
+
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
+
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
+
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
+ try test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
+}
+
+test "ashlti3" {
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, 0xFEDCBA9876543215FEDCBA9876543215);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, 0xFDB97530ECA8642BFDB97530ECA8642A);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, 0xFB72EA61D950C857FB72EA61D950C854);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, 0xF6E5D4C3B2A190AFF6E5D4C3B2A190A8);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, 0xEDCBA9876543215FEDCBA98765432150);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, 0x876543215FEDCBA98765432150000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, 0x0ECA8642BFDB97530ECA8642A0000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, 0x1D950C857FB72EA61D950C8540000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, 0x3B2A190AFF6E5D4C3B2A190A80000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, 0x76543215FEDCBA987654321500000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, 0xECA8642BFDB97530ECA8642A00000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, 0xD950C857FB72EA61D950C85400000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, 0xB2A190AFF6E5D4C3B2A190A800000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, 0x6543215FEDCBA9876543215000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, 0x5FEDCBA9876543215000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, 0xBFDB97530ECA8642A000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, 0x7FB72EA61D950C854000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, 0xFF6E5D4C3B2A190A8000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, 0xFEDCBA98765432150000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, 0xFDB97530ECA8642A0000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, 0xFB72EA61D950C8540000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, 0xF6E5D4C3B2A190A80000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, 0xEDCBA987654321500000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, 0x87654321500000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, 0x0ECA8642A00000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, 0x1D950C85400000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, 0x3B2A190A800000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, 0x76543215000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, 0xECA8642A000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, 0xD950C854000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, 0xB2A190A8000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, 0x65432150000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, 0x50000000000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, 0xA0000000000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, 0x40000000000000000000000000000000);
+ try test__ashlti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, 0x80000000000000000000000000000000);
+}
+
+fn test__ashrsi3(a: i32, b: i32, expected: u32) !void {
+ const x = __ashrsi3(a, b);
+ try testing.expectEqual(expected, @bitCast(u32, x));
+}
+fn test__ashrdi3(a: i64, b: i32, expected: u64) !void {
+ const x = __ashrdi3(a, b);
+ try testing.expectEqual(expected, @bitCast(u64, x));
+}
+fn test__ashrti3(a: i128, b: i32, expected: u128) !void {
+ const x = __ashrti3(a, b);
+ try testing.expectEqual(expected, @bitCast(u128, x));
+}
+
+test "ashrsi3" {
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 0, 0xFEDBCA98);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 1, 0xFF6DE54C);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 2, 0xFFB6F2A6);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 3, 0xFFDB7953);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 4, 0xFFEDBCA9);
+
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 28, 0xFFFFFFFF);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 31, 0xFFFFFFFF);
+
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 0, 0x8CEF8CEF);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 1, 0xC677C677);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 2, 0xE33BE33B);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 3, 0xF19DF19D);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 4, 0xF8CEF8CE);
+
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 28, 0xFFFFFFF8);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 29, 0xFFFFFFFC);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 30, 0xFFFFFFFE);
+ try test__ashrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 31, 0xFFFFFFFF);
+}
+
+test "ashrdi3" {
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
+
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
+ try test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
+}
+
+test "ashrti3" {
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 0, 0xFEDCBA9876543215FEDCBA9876543215);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 1, 0xFF6E5D4C3B2A190AFF6E5D4C3B2A190A);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 2, 0xFFB72EA61D950C857FB72EA61D950C85);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 3, 0xFFDB97530ECA8642BFDB97530ECA8642);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 4, 0xFFEDCBA9876543215FEDCBA987654321);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 28, 0xFFFFFFFFEDCBA9876543215FEDCBA987);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 29, 0xFFFFFFFFF6E5D4C3B2A190AFF6E5D4C3);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 30, 0xFFFFFFFFFB72EA61D950C857FB72EA61);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 31, 0xFFFFFFFFFDB97530ECA8642BFDB97530);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 32, 0xFFFFFFFFFEDCBA9876543215FEDCBA98);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 33, 0xFFFFFFFFFF6E5D4C3B2A190AFF6E5D4C);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 34, 0xFFFFFFFFFFB72EA61D950C857FB72EA6);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 35, 0xFFFFFFFFFFDB97530ECA8642BFDB9753);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 36, 0xFFFFFFFFFFEDCBA9876543215FEDCBA9);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 60, 0xFFFFFFFFFFFFFFFFEDCBA9876543215F);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 61, 0xFFFFFFFFFFFFFFFFF6E5D4C3B2A190AF);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 62, 0xFFFFFFFFFFFFFFFFFB72EA61D950C857);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 63, 0xFFFFFFFFFFFFFFFFFDB97530ECA8642B);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 64, 0xFFFFFFFFFFFFFFFFFEDCBA9876543215);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 65, 0xFFFFFFFFFFFFFFFFFF6E5D4C3B2A190A);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 66, 0xFFFFFFFFFFFFFFFFFFB72EA61D950C85);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 67, 0xFFFFFFFFFFFFFFFFFFDB97530ECA8642);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 68, 0xFFFFFFFFFFFFFFFFFFEDCBA987654321);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 92, 0xFFFFFFFFFFFFFFFFFFFFFFFFEDCBA987);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 93, 0xFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C3);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 94, 0xFFFFFFFFFFFFFFFFFFFFFFFFFB72EA61);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 95, 0xFFFFFFFFFFFFFFFFFFFFFFFFFDB97530);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 96, 0xFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA98);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 97, 0xFFFFFFFFFFFFFFFFFFFFFFFFFF6E5D4C);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 98, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFB72EA6);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 99, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFDB9753);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 100, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFEDCBA9);
+
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 124, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 125, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 126, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+ try test__ashrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA9876543215)), 127, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
+}
+
+fn test__lshrsi3(a: i32, b: i32, expected: u32) !void {
+ const x = __lshrsi3(a, b);
+ try testing.expectEqual(expected, @bitCast(u32, x));
+}
+fn test__lshrdi3(a: i64, b: i32, expected: u64) !void {
+ const x = __lshrdi3(a, b);
+ try testing.expectEqual(expected, @bitCast(u64, x));
+}
+fn test__lshrti3(a: i128, b: i32, expected: u128) !void {
+ const x = __lshrti3(a, b);
+ try testing.expectEqual(expected, @bitCast(u128, x));
+}
+
+test "lshrsi3" {
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 0, 0xFEDBCA98);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 1, 0x7F6DE54C);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 2, 0x3FB6F2A6);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 3, 0x1FDB7953);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 4, 0xFEDBCA9);
+
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 28, 0xF);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 29, 0x7);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 30, 0x3);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0xFEDBCA98)), 31, 0x1);
+
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 0, 0x8CEF8CEF);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 1, 0x4677C677);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 2, 0x233BE33B);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 3, 0x119DF19D);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 4, 0x8CEF8CE);
+
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 28, 0x8);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 29, 0x4);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 30, 0x2);
+ try test__lshrsi3(@bitCast(i32, @as(u32, 0x8CEF8CEF)), 31, 0x1);
+}
+
+test "lshrdi3" {
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
+
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
+ try test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
+}
+
+test "lshrti3" {
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 0, 0xFEDCBA9876543215FEDCBA987654321F);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 1, 0x7F6E5D4C3B2A190AFF6E5D4C3B2A190F);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 2, 0x3FB72EA61D950C857FB72EA61D950C87);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 3, 0x1FDB97530ECA8642BFDB97530ECA8643);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 4, 0xFEDCBA9876543215FEDCBA987654321);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 28, 0xFEDCBA9876543215FEDCBA987);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 29, 0x7F6E5D4C3B2A190AFF6E5D4C3);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 30, 0x3FB72EA61D950C857FB72EA61);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 31, 0x1FDB97530ECA8642BFDB97530);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 32, 0xFEDCBA9876543215FEDCBA98);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 33, 0x7F6E5D4C3B2A190AFF6E5D4C);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 34, 0x3FB72EA61D950C857FB72EA6);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 35, 0x1FDB97530ECA8642BFDB9753);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 36, 0xFEDCBA9876543215FEDCBA9);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 60, 0xFEDCBA9876543215F);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 61, 0x7F6E5D4C3B2A190AF);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 62, 0x3FB72EA61D950C857);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 63, 0x1FDB97530ECA8642B);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 64, 0xFEDCBA9876543215);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 65, 0x7F6E5D4C3B2A190A);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 66, 0x3FB72EA61D950C85);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 67, 0x1FDB97530ECA8642);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 68, 0xFEDCBA987654321);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 92, 0xFEDCBA987);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 93, 0x7F6E5D4C3);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 94, 0x3FB72EA61);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 95, 0x1FDB97530);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 96, 0xFEDCBA98);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 97, 0x7F6E5D4C);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 98, 0x3FB72EA6);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 99, 0x1FDB9753);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 100, 0xFEDCBA9);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 124, 0xF);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 125, 0x7);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 126, 0x3);
+ try test__lshrti3(@bitCast(i128, @as(u128, 0xFEDCBA9876543215FEDCBA987654321F)), 127, 0x1);
+}