-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Int128 Parsing support [PART 1] #11196
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
Changes from all commits
fdb52dc
8e001b9
21a3421
1254065
0a77b75
6adb83e
3b3634d
64187a2
2b1ba7b
c5e1279
3c7d7a1
c8378b7
dae48fb
fd8a77e
e3e8458
b91eb8c
f64d70a
5e0fd92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| require "spec" | ||
|
|
||
| # TODO: Remove these helpers in PR part 2 | ||
|
|
||
| private def make_ti(a : Int128, b : Int128) | ||
| (a << 64) + b | ||
| end | ||
|
|
||
| private def make_tu(a : UInt128, b : UInt128) | ||
| (a << 64) + b | ||
| end | ||
|
|
||
| # Specs ported from compiler-rt | ||
|
|
||
| private def test__divti3(a : Int128, b : Int128, expected : Int128, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is the same design as in the existing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Placing it all in the one example will show just the first fail instead of all.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but that doesn't really matter much. They're all expected to pass anyways.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course they are :D I'm saying is that you want to know exactly which ones are failing if they don't. |
||
| actual = __divti3(a, b) | ||
| actual.should eq(expected), file: file, line: line | ||
| end | ||
| end | ||
|
|
||
| private def test__modti3(a : Int128, b : Int128, expected : Int128, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual = __modti3(a, b) | ||
| actual.should eq(expected), file: file, line: line | ||
| end | ||
| end | ||
|
|
||
| private def test__udivti3(a : UInt128, b : UInt128, expected : UInt128, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual = __udivti3(a, b) | ||
| actual.should eq(expected), file: file, line: line | ||
| end | ||
| end | ||
|
|
||
| private def test__umodti3(a : UInt128, b : UInt128, expected : UInt128, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual = __umodti3(a, b) | ||
| actual.should eq(expected), file: file, line: line | ||
| end | ||
| end | ||
|
|
||
| describe "__divti3" do | ||
| test__divti3(0, 1, 0) | ||
| test__divti3(0, -1, 0) | ||
| test__divti3(2, 1, 2) | ||
| test__divti3(2, -1, -2) | ||
| test__divti3(-2, 1, -2) | ||
| test__divti3(-2, -1, 2) | ||
| test__divti3(make_ti(-9223372036854775808, 0x0), 1, make_ti(-9223372036854775808, 0x0)) | ||
| test__divti3(make_ti(-9223372036854775808, 0x0), -1, make_ti(-9223372036854775808, 0x0)) | ||
| test__divti3(make_ti(-9223372036854775808, 0x0), -2, make_ti(0x4000000000000000, 0x0)) | ||
| test__divti3(make_ti(-9223372036854775808, 0x0), 2, make_ti(-0x4000000000000000, 0x0)) | ||
| end | ||
|
|
||
| describe "__modti3" do | ||
| test__modti3(0, 1, 0) | ||
| test__modti3(0, -1, 0) | ||
|
|
||
| test__modti3(5, 3, 2) | ||
| test__modti3(5, -3, 2) | ||
| test__modti3(-5, 3, -2) | ||
| test__modti3(-5, -3, -2) | ||
|
|
||
| test__modti3(make_ti(-9223372036854775808, 0x0), 1, 0) | ||
| test__modti3(make_ti(-9223372036854775808, 0x0), -1, 0) | ||
| test__modti3(make_ti(-9223372036854775808, 0x0), 2, 0) | ||
| test__modti3(make_ti(-9223372036854775808, 0x0), -2, 0) | ||
| test__modti3(make_ti(-9223372036854775808, 0x0), 3, -2) | ||
| test__modti3(make_ti(-9223372036854775808, 0x0), -3, -2) | ||
| end | ||
|
|
||
| describe "__udivti3" do | ||
| test__udivti3(0, 1, 0) | ||
| test__udivti3(2, 1, 2) | ||
|
|
||
| test__udivti3(make_tu(0x0, 0x8000000000000000), 1, make_tu(0x0, 0x8000000000000000)) | ||
| test__udivti3(make_tu(0x0, 0x8000000000000000), 2, make_tu(0x0, 0x4000000000000000)) | ||
| test__udivti3(make_tu(0xffffffffffffffff, 0xffffffffffffffff), 2, make_tu(0x7fffffffffffffff, 0xffffffffffffffff)) | ||
| end | ||
|
|
||
| describe "__umodti3" do | ||
| test__umodti3(0, 1, 0) | ||
| test__umodti3(2, 1, 0) | ||
|
|
||
| test__umodti3(make_tu(0x0, 0x8000000000000000), 1, 0) | ||
| test__umodti3(make_tu(0x0, 0x8000000000000000), 2, 0) | ||
| test__umodti3(make_tu(0xffffffffffffffff, 0xffffffffffffffff), 2, 1) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| require "spec" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/mulosi4_test.c | ||
|
|
||
| private def test__mulosi4(a : Int32, b : Int32, expected : Int32, expected_overflow : Int32, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual_overflow : Int32 = 0 | ||
| actual = __mulosi4(a, b, pointerof(actual_overflow)) | ||
| actual_overflow.should eq(expected_overflow), file: file, line: line | ||
| if !expected_overflow | ||
| actual.should eq(expected), file: file, line: line | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "__mulosi4" do | ||
| test__mulosi4(0, 0, 0, 0) | ||
| test__mulosi4(0, 1, 0, 0) | ||
| test__mulosi4(1, 0, 0, 0) | ||
| test__mulosi4(0, 10, 0, 0) | ||
| test__mulosi4(10, 0, 0, 0) | ||
| test__mulosi4(0, 0x1234567, 0, 0) | ||
| test__mulosi4(0x1234567, 0, 0, 0) | ||
|
|
||
| test__mulosi4(0, -1, 0, 0) | ||
| test__mulosi4(-1, 0, 0, 0) | ||
| test__mulosi4(0, -10, 0, 0) | ||
| test__mulosi4(-10, 0, 0, 0) | ||
| test__mulosi4(0, 0x1234567, 0, 0) | ||
| test__mulosi4(0x1234567, 0, 0, 0) | ||
|
|
||
| test__mulosi4(1, 1, 1, 0) | ||
| test__mulosi4(1, 10, 10, 0) | ||
| test__mulosi4(10, 1, 10, 0) | ||
| test__mulosi4(1, 0x1234567, 0x1234567, 0) | ||
| test__mulosi4(0x1234567, 1, 0x1234567, 0) | ||
|
|
||
| test__mulosi4(1, -1, -1, 0) | ||
| test__mulosi4(1, -10, -10, 0) | ||
| test__mulosi4(-10, 1, -10, 0) | ||
| test__mulosi4(1, -0x1234567, -0x1234567, 0) | ||
| test__mulosi4(-0x1234567, 1, -0x1234567, 0) | ||
|
|
||
| test__mulosi4(0x7FFFFFFF, -2, -0x7fffffff, 1) | ||
| test__mulosi4(-2, 0x7FFFFFFF, -0x7fffffff, 1) | ||
| test__mulosi4(0x7FFFFFFF, -1, -0x7fffffff, 0) | ||
| test__mulosi4(-1, 0x7FFFFFFF, -0x7fffffff, 0) | ||
| test__mulosi4(0x7FFFFFFF, 0, 0, 0) | ||
| test__mulosi4(0, 0x7FFFFFFF, 0, 0) | ||
| test__mulosi4(0x7FFFFFFF, 1, 0x7FFFFFFF, 0) | ||
| test__mulosi4(1, 0x7FFFFFFF, 0x7FFFFFFF, 0) | ||
| test__mulosi4(0x7FFFFFFF, 2, -0x7fffffff, 1) | ||
| test__mulosi4(2, 0x7FFFFFFF, -0x7fffffff, 1) | ||
|
|
||
| test__mulosi4(-0x80000000, -2, -0x80000000, 1) | ||
| test__mulosi4(-2, -0x80000000, -0x80000000, 1) | ||
| test__mulosi4(-0x80000000, -1, -0x80000000, 1) | ||
| test__mulosi4(-1, -0x80000000, -0x80000000, 1) | ||
| test__mulosi4(-0x80000000, 0, 0, 0) | ||
| test__mulosi4(0, -0x80000000, 0, 0) | ||
| test__mulosi4(-0x80000000, 1, -0x80000000, 0) | ||
| test__mulosi4(1, -0x80000000, -0x80000000, 0) | ||
| test__mulosi4(-0x80000000, 2, -0x80000000, 1) | ||
| test__mulosi4(2, -0x80000000, -0x80000000, 1) | ||
|
|
||
| test__mulosi4(-0x7fffffff, -2, -0x7fffffff, 1) | ||
| test__mulosi4(-2, -0x7fffffff, -0x7fffffff, 1) | ||
| test__mulosi4(-0x7fffffff, -1, 0x7FFFFFFF, 0) | ||
| test__mulosi4(-1, -0x7fffffff, 0x7FFFFFFF, 0) | ||
| test__mulosi4(-0x7fffffff, 0, 0, 0) | ||
| test__mulosi4(0, -0x7fffffff, 0, 0) | ||
| test__mulosi4(-0x7fffffff, 1, -0x7fffffff, 0) | ||
| test__mulosi4(1, -0x7fffffff, -0x7fffffff, 0) | ||
| test__mulosi4(-0x7fffffff, 2, -0x80000000, 1) | ||
| test__mulosi4(2, -0x7fffffff, -0x80000000, 1) | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| require "spec" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/muloti4_test.c | ||
|
|
||
| private def test__muloti4(a : Int128, b : Int128, expected : Int128, expected_overflow : Int32, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual_overflow : Int32 = 0 | ||
| actual = __muloti4(a, b, pointerof(actual_overflow)) | ||
| actual_overflow.should eq(expected_overflow), file: file, line: line | ||
| if !expected_overflow | ||
| actual.should eq(expected), file: file, line: line | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # TODO: Remove this helper in PR part 2 | ||
|
|
||
| private def make_ti(a : Int128, b : Int128) | ||
| (a << 64) + b | ||
| end | ||
|
|
||
| describe "__muloti4" do | ||
| test__muloti4(0, 0, 0, 0) | ||
| test__muloti4(0, 1, 0, 0) | ||
| test__muloti4(1, 0, 0, 0) | ||
| test__muloti4(0, 10, 0, 0) | ||
| test__muloti4(10, 0, 0, 0) | ||
| test__muloti4(0, 81985529216486895, 0, 0) | ||
| test__muloti4(81985529216486895, 0, 0, 0) | ||
| test__muloti4(0, -1, 0, 0) | ||
| test__muloti4(-1, 0, 0, 0) | ||
| test__muloti4(0, -10, 0, 0) | ||
| test__muloti4(-10, 0, 0, 0) | ||
| test__muloti4(0, -81985529216486895, 0, 0) | ||
| test__muloti4(-81985529216486895, 0, 0, 0) | ||
| test__muloti4(1, 1, 1, 0) | ||
| test__muloti4(1, 10, 10, 0) | ||
| test__muloti4(10, 1, 10, 0) | ||
| test__muloti4(1, 81985529216486895, 81985529216486895, 0) | ||
| test__muloti4(81985529216486895, 1, 81985529216486895, 0) | ||
| test__muloti4(1, -1, -1, 0) | ||
| test__muloti4(1, -10, -10, 0) | ||
| test__muloti4(-10, 1, -10, 0) | ||
| test__muloti4(1, -81985529216486895, -81985529216486895, 0) | ||
| test__muloti4(-81985529216486895, 1, -81985529216486895, 0) | ||
| test__muloti4(3037000499, 3037000499, 9223372030926249001, 0) | ||
| test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0) | ||
| test__muloti4(3037000499, -3037000499, -9223372030926249001, 0) | ||
| test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0) | ||
| test__muloti4(4398046511103, 2097152, 9223372036852678656, 0) | ||
| test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0) | ||
| test__muloti4(4398046511103, -2097152, -9223372036852678656, 0) | ||
| test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0) | ||
| test__muloti4(2097152, 4398046511103, 9223372036852678656, 0) | ||
| test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0) | ||
| test__muloti4(2097152, -4398046511103, -9223372036852678656, 0) | ||
| test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0) | ||
| test__muloti4(make_ti(0x00000000000000B5, 0x04F333F9DE5BE000), | ||
| make_ti(0x0000000000000000, 0x00B504F333F9DE5B), | ||
| make_ti(0x7FFFFFFFFFFFF328, 0xDF915DA296E8A000), 0) | ||
| test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| -2, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 1) | ||
| test__muloti4(-2, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 1) | ||
| test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| -1, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 0) | ||
| test__muloti4(-1, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 0) | ||
| test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| 0, | ||
| 0, 0) | ||
| test__muloti4(0, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| 0, 0) | ||
| test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| 1, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) | ||
| test__muloti4(1, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) | ||
| test__muloti4(make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| 2, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 1) | ||
| test__muloti4(2, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 1) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), | ||
| -2, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(-2, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), | ||
| -1, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(-1, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), | ||
| 0, | ||
| 0, 0) | ||
| test__muloti4(0, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), | ||
| 0, 0) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), | ||
| 1, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 0) | ||
| test__muloti4(1, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 0) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000000), | ||
| 2, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(2, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), | ||
| -2, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 1) | ||
| test__muloti4(-2, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 1) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), | ||
| -1, | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) | ||
| test__muloti4(-1, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), | ||
| make_ti(0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF), 0) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), | ||
| 0, | ||
| 0, 0) | ||
| test__muloti4(0, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), | ||
| 0, 0) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), | ||
| 1, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 0) | ||
| test__muloti4(1, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), | ||
| make_ti(0x8000000000000000, 0x0000000000000001), 0) | ||
| test__muloti4(make_ti(0x8000000000000000, 0x0000000000000001), | ||
| 2, | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| test__muloti4(2, | ||
| make_ti(0x8000000000000000, 0x0000000000000001), | ||
| make_ti(0x8000000000000000, 0x0000000000000000), 1) | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.