-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
#23909 adds __addvsi3, __subvsi3, __mulvsi3, subvdi3 to compiler_rt #24000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eb00d65
#23909 adds __addvsi3, __subvsi3, __mulvsi3, subvdi3 to compiler_rt
e98b84e
adds addvsi, subvsi, subvdi, mulvsi to compiler_rt.zig and CMakeList.txt
02b6380
__addvsi3 is now based on __addosi4
796fa79
fixes typos, thanks to jayschwa
7129e16
Merge branch 'master' into #23909
hi7 75a62b7
sorted subs
4d00a78
the other functions are now based on subo and mulo
6c31044
Merge branch 'ziglang:master' into #23909
hi7 f5e7546
moves tests into the files containing the function
3eb5cec
Merge branch 'ziglang:master' into #23909
hi7 ce8791d
moves addvsi3 four lines down to match alphabet
c7b6207
changes == 1 check into != 0 to match abi
e80095e
Merge branch 'master' into #23909
hi7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const addv = @import("addo.zig"); | ||
const common = @import("./common.zig"); | ||
|
||
pub const panic = common.panic; | ||
|
||
comptime { | ||
@export(&__addvsi3, .{ .name = "__addvsi3", .linkage = common.linkage, .visibility = common.visibility }); | ||
} | ||
|
||
pub fn __addvsi3(a: i32, b: i32) callconv(.c) i32 { | ||
alexrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var overflow: c_int = 0; | ||
const sum = addv.__addosi4(a, b, &overflow); | ||
if (overflow == 1) @panic("compiler-rt: integer overflow"); | ||
return sum; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const testing = @import("std").testing; | ||
|
||
const __addvsi3 = @import("addvsi3.zig").__addvsi3; | ||
|
||
fn test__addvsi3(a: i32, b: i32, expected: i32) !void { | ||
const result = __addvsi3(a, b); | ||
try testing.expectEqual(expected, result); | ||
} | ||
|
||
test "addvsi3" { | ||
// const min: i32 = -2147483648 | ||
// const max: i32 = 2147483647 | ||
// TODO write panic handler for testing panics | ||
// try test__addvsi3(-2147483648, -1, -1); // panic | ||
// try test__addvsi3(2147483647, 1, 1); // panic | ||
try test__addvsi3(-2147483647, -1, -2147483648); | ||
try test__addvsi3(2147483646, 1, 2147483647); | ||
} | ||
alexrp marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const common = @import("./common.zig"); | ||
|
||
pub const panic = common.panic; | ||
|
||
comptime { | ||
@export(&__mulvsi3, .{ .name = "__mulvsi3", .linkage = common.linkage, .visibility = common.visibility }); | ||
} | ||
|
||
pub fn __mulvsi3(a: i32, b: i32) callconv(.c) i32 { | ||
const bits = 32; | ||
if (a == -2147483648) { | ||
if (b == 0 or b == 1) | ||
return a * b; | ||
@panic("compiler-rt: interger overflow"); | ||
alexrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (b == -2147483648) { | ||
if (a == 0 or a == 1) | ||
return a * b; | ||
@panic("compiler-rt: interger overflow"); | ||
alexrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
const sa = a >> (bits - 1); | ||
const abs_a = (a ^ sa) - sa; | ||
const sb = b >> (bits - 1); | ||
const abs_b = (b ^ sb) - sb; | ||
if (abs_a < 2 or abs_b < 2) | ||
return a * b; | ||
if (sa == sb) { | ||
if (abs_a > @divTrunc(2147483647, abs_b)) | ||
@panic("compiler-rt: interger overflow"); | ||
alexrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
if (abs_a > @divTrunc(-2147483648, -abs_b)) | ||
@panic("compiler-rt: interger overflow"); | ||
alexrp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return a * b; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const testing = @import("std").testing; | ||
|
||
const __mulvsi3 = @import("mulvsi3.zig").__mulvsi3; | ||
|
||
fn test__mulvsi3(a: i32, b: i32, expected: i32) !void { | ||
const result = __mulvsi3(a, b); | ||
try testing.expectEqual(expected, result); | ||
} | ||
|
||
test "mulvsi3" { | ||
// min i32 = -2147483648 | ||
// max i32 = 2147483647 | ||
// TODO write panic handler for testing panics | ||
// try test__mulvsi3(-2147483648, -1, -1); // panic | ||
// try test__mulvsi3(2147483647, 1, 1); // panic | ||
try test__mulvsi3(-1073741824, 2, -2147483648); | ||
try test__mulvsi3(1073741823, 2, 2147483646); // one too less for corner case 2147483647 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const common = @import("./common.zig"); | ||
|
||
pub const panic = common.panic; | ||
|
||
comptime { | ||
@export(&__subvdi3, .{ .name = "__subvdi3", .linkage = common.linkage, .visibility = common.visibility }); | ||
} | ||
|
||
pub fn __subvdi3(a: i64, b: i64) callconv(.c) i64 { | ||
// first allow overflow to panic with a reference to compiler-rt | ||
const sum: i64 = a -% b; | ||
if (b >= 0) { | ||
if (sum > a) | ||
@panic("compiler-rt: integer overflow"); | ||
} else { | ||
if (sum <= a) | ||
@panic("compiler-rt: integer overflow"); | ||
} | ||
return sum; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const testing = @import("std").testing; | ||
|
||
const __subvdi3 = @import("subvdi3.zig").__subvdi3; | ||
|
||
fn test__subvdi3(a: i64, b: i64, expected: i64) !void { | ||
const result = __subvdi3(a, b); | ||
try testing.expectEqual(expected, result); | ||
} | ||
|
||
test "subvdi3" { | ||
// min i64 = -9223372036854775808 | ||
// max i64 = 9223372036854775807 | ||
// TODO write panic handler for testing panics | ||
// try test__subvdi3(-9223372036854775808, -1, -1); // panic | ||
// try test__addvdi3(9223372036854775807, 1, 1); // panic | ||
try test__subvdi3(-9223372036854775807, 1, -9223372036854775808); | ||
try test__subvdi3(9223372036854775806, -1, 9223372036854775807); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const common = @import("./common.zig"); | ||
|
||
pub const panic = common.panic; | ||
|
||
comptime { | ||
@export(&__subvsi3, .{ .name = "__subvsi3", .linkage = common.linkage, .visibility = common.visibility }); | ||
} | ||
|
||
pub fn __subvsi3(a: i32, b: i32) callconv(.c) i32 { | ||
// first allow overflow to panic with a reference to compiler-rt | ||
const sum: i32 = a -% b; | ||
if (b >= 0) { | ||
if (sum > a) | ||
@panic("compiler-rt: integer overflow"); | ||
} else { | ||
if (sum <= a) | ||
@panic("compiler-rt: integer overflow"); | ||
} | ||
return sum; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const testing = @import("std").testing; | ||
|
||
const __subvsi3 = @import("subvsi3.zig").__subvsi3; | ||
|
||
fn test__subvsi3(a: i32, b: i32, expected: i32) !void { | ||
const result = __subvsi3(a, b); | ||
try testing.expectEqual(expected, result); | ||
} | ||
|
||
test "subvsi3" { | ||
// min i32 = -2147483648 | ||
// max i32 = 2147483647 | ||
// TODO write panic handler for testing panics | ||
// try test__subvsi3(-2147483648, -1, -1); // panic | ||
// try test__subvsi3(2147483647, 1, 1); // panic | ||
try test__subvsi3(-2147483647, 1, -2147483648); | ||
try test__subvsi3(2147483646, -1, 2147483647); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.