mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
add zig builtins for wrapped mul and shift right (for 128-bit ints)
This commit is contained in:
parent
d56d3311d4
commit
312fb23567
3 changed files with 33 additions and 0 deletions
|
@ -73,6 +73,9 @@ comptime {
|
|||
exportNumFn(num.bytesToU64C, "bytes_to_u64");
|
||||
exportNumFn(num.bytesToU128C, "bytes_to_u128");
|
||||
|
||||
exportNumFn(num.shiftRightZeroFillI128, "shift_right_zero_fill.i128");
|
||||
exportNumFn(num.shiftRightZeroFillU128, "shift_right_zero_fill.u128");
|
||||
|
||||
inline for (INTEGERS) |T, i| {
|
||||
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int.");
|
||||
num.exportDivCeil(T, ROC_BUILTINS ++ "." ++ NUM ++ ".div_ceil.");
|
||||
|
@ -91,6 +94,7 @@ comptime {
|
|||
num.exportMulWithOverflow(T, WIDEINTS[i], ROC_BUILTINS ++ "." ++ NUM ++ ".mul_with_overflow.");
|
||||
num.exportMulOrPanic(T, WIDEINTS[i], ROC_BUILTINS ++ "." ++ NUM ++ ".mul_or_panic.");
|
||||
num.exportMulSaturatedInt(T, WIDEINTS[i], ROC_BUILTINS ++ "." ++ NUM ++ ".mul_saturated.");
|
||||
num.exportMulWrappedInt(T, ROC_BUILTINS ++ "." ++ NUM ++ ".mul_wrapped.");
|
||||
|
||||
num.exportCountLeadingZeroBits(T, ROC_BUILTINS ++ "." ++ NUM ++ ".count_leading_zero_bits.");
|
||||
num.exportCountTrailingZeroBits(T, ROC_BUILTINS ++ "." ++ NUM ++ ".count_trailing_zero_bits.");
|
||||
|
|
|
@ -464,6 +464,31 @@ pub fn exportMulSaturatedInt(comptime T: type, comptime W: type, comptime name:
|
|||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn exportMulWrappedInt(comptime T: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(self: T, other: T) callconv(.C) T {
|
||||
return self *% other;
|
||||
}
|
||||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub export fn shiftRightZeroFillI128(self: i128, other: u8) i128 {
|
||||
if (other & 0b1000_0000 > 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return self >> @intCast(u7, other);
|
||||
}
|
||||
}
|
||||
|
||||
pub export fn shiftRightZeroFillU128(self: u128, other: u8) u128 {
|
||||
if (other & 0b1000_0000 > 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return self >> @intCast(u7, other);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exportMulOrPanic(comptime T: type, comptime W: type, comptime name: []const u8) void {
|
||||
comptime var f = struct {
|
||||
fn func(self: T, other: T) callconv(.C) T {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue