-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Compiler-RT for 128bit integer support #8313
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
Closed
Closed
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
26f6ddc
Add Compiler-RT for 128bit integer support
jkthorne 15b0804
Add specs for Compiler-RT
jkthorne 3d21d8e
skip 32bits flag to compiler-rt specs
jkthorne c7abe38
Use record over struct; put info structs into same file;
jkthorne f86dd9c
change flags in specs; require info file
jkthorne b783fc3
revert struct to record
jkthorne 380fc90
used overflows in compiler-rt functions
jkthorne ca2592e
fix 32bit tests
jkthorne bd6a9d9
use extern for strructs
jkthorne 1663b66
use // in udivmodti
jkthorne 106f403
reorder the rt require functions
jkthorne a8ed506
update to use c structs
jkthorne 5887248
Merge branch 'master' into i128_compiler_rt
jkthorne 0f30e9e
cleanup unused fun
jkthorne 6c7828d
disable tests the require i128 parsing
jkthorne 9fdad45
re-enabled __mulodi4 specs
jkthorne 3ee5faf
revert format fix
jkthorne dcd39ea
Merge branch 'master' into i128_compiler_rt
jkthorne 6543eb3
add __umodti3 to compiler-rt
jkthorne 6aef69a
add udivti3 fun to compiler-rt
jkthorne 38acdb6
fix formatting
jkthorne 899b303
break up tests files
jkthorne 72c7c9b
break up test files for ci
jkthorne d780875
update rtinfo to use #all methos
jkthorne 534ca68
Merge branch 'master' into i128_compiler_rt
jkthorne 21d7a7e
update test_darwin to 11.1
jkthorne ed5841d
update xcode in circleci to 11.1.0
jkthorne 3e993f6
Apply suggestions from code review
jkthorne 88b7d88
Apply suggestions from code review
jkthorne f603253
update udivmodti4
jkthorne 83b58f4
revert xcode to 9.0
jkthorne 22226a2
Merge branch 'master' into i128_compiler_rt
jkthorne 8c5cf0f
remove puts statement
jkthorne c2ead94
use bits32 flag for compiler-rt files
jkthorne e351c94
first pass update on specs
jkthorne 3e89f07
first pass at test isolation
jkthorne c05dd49
first pass at test isolation
jkthorne e8b38d5
fix merge conflict
jkthorne 318c2cb
update udivmodti4 with tailing and leading zeros
jkthorne 66aa14b
comment out tests that cannot be run yet
jkthorne d78fa01
Merge branch 'master' into i128_compiler_rt
jkthorne 7b79a76
add comments to add tests for Int128 once support is added
jkthorne 1950827
add mulddi3
jkthorne 745d17b
fix positive integers for __multi3
jkthorne 3db6b74
move initializers around
jkthorne a585a05
update int struct
jkthorne 53ac00b
update muloti4
jkthorne adf6941
update multi3 style
jkthorne 42a34b5
enable umodti3 specs
jkthorne e6eb8b2
update int 128 info layout
jkthorne 4989978
add macros for i128 info structs
jkthorne 46c55d1
use macros for muloti3 specs
jkthorne a6c3fb0
update the constructors in int info
jkthorne 7a08b32
update divti3 and specs
jkthorne 337b362
update __modti3 and specs
jkthorne fa55680
update muloti4 and specs
jkthorne fe5a9e4
complete multi3 specs
jkthorne b6b8220
update umodti3 with new patterns
jkthorne e884358
add flag for compile RT specs
jkthorne 708bbb6
setup udivmodti4 for specs
jkthorne 61affcf
formatting change and cleanup udivmodti4 specs
jkthorne 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| {% skip_file unless flag?(:compile_rt) %} | ||
|
|
||
| require "spec" | ||
| require "../../../../src/crystal/compiler_rt/divti3" | ||
| require "../../../../src/crystal/compiler_rt/i128_info" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/divti3_test.c | ||
|
|
||
| private def test__divti3(a : (Int128 | Int128RT), b : (Int128 | Int128RT), expected : (Int128 | Int128RT), file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| __divti3(a.to_i128, b.to_i128).should eq(expected.to_i128), file, line | ||
| end | ||
| end | ||
|
|
||
| describe "__divti3" do | ||
| test__divti3(0_i128, 1_i128, 0_i128) | ||
| test__divti3(0_i128, Int128RT[1_i128].negate!, 0_i128) | ||
| test__divti3(2_i128, 1_i128, 2_i128) | ||
| test__divti3(2_i128, Int128RT[1_i128].negate!, Int128RT[2_i128].negate!) | ||
| test__divti3(Int128RT[2_i128].negate!, 1_i128, Int128RT[2_i128].negate!) | ||
| test__divti3(Int128RT[2_i128].negate!, Int128RT[1_i128].negate!, 2_i128) | ||
| test__divti3(Int128RT[-9223372036854775808_i64, 0_u64], 1_i128, Int128RT[-9223372036854775808_i64, 0_u64]) | ||
| test__divti3(Int128RT[-9223372036854775808_i64, 0_u64], Int128RT[1_i128].negate!, Int128RT[-9223372036854775808_i64, 0_u64]) | ||
| test__divti3(Int128RT[-9223372036854775808_i64, 0_u64], Int128RT[2_i128].negate!, Int128RT[4611686018427387904_i64, 0_u64]) | ||
| test__divti3(Int128RT[-9223372036854775808_i64, 0_u64], 2_i128, Int128RT[-4611686018427387904_i64, 0_u64]) | ||
| end |
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,28 @@ | ||
| {% skip_file unless flag?(:compile_rt) %} | ||
|
|
||
| require "spec" | ||
| require "../../../../src/crystal/compiler_rt/modti3" | ||
| require "../../../../src/crystal/compiler_rt/i128_info" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/modti3_test.c | ||
|
|
||
| private def test__modti3(a : (Int128 | Int128RT), b : (Int128 | Int128RT), expected : (Int128 | Int128RT), file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| __modti3(a.to_i128, b.to_i128).should eq(expected.to_i128), file, line | ||
| end | ||
| end | ||
|
|
||
| describe "__modti3" do | ||
| test__modti3(0_i128, 1_i128, 0_i128) | ||
| test__modti3(0_i128, Int128RT[1_i128].negate!, 0_i128) | ||
| test__modti3(5_i128, 3_i128, 2_i128) | ||
| test__modti3(5_i128, Int128RT[3_i128].negate!, 2_i128) | ||
| test__modti3(Int128RT[5_i128].negate!, 3_i128, Int128RT[2_i128].negate!) | ||
| test__modti3(Int128RT[5_i128].negate!, Int128RT[3_i128].negate!, Int128RT[2_i128].negate!) | ||
| test__modti3(Int128RT[-9223372036854775808_i64, 0_u64], 1_i128, 0_i128) | ||
| test__modti3(Int128RT[-9223372036854775808_i64, 0_u64], Int128RT[1_i128].negate!, 0_i128) | ||
| test__modti3(Int128RT[-9223372036854775808_i64, 0_u64], 2_i128, 0_i128) | ||
| test__modti3(Int128RT[-9223372036854775808_i64, 0_u64], Int128RT[2_i128].negate!, 0_i128) | ||
| # test__modti3(Int128RT[-9223372036854775808_i64, 0_u64], 3_i128, Int128RT[2_i128].negate!) | ||
| # test__modti3(Int128RT[-9223372036854775808_i64, 0_u64], Int128RT[3_i128].negate!, Int128RT[2_i128].negate!) | ||
| end |
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,95 @@ | ||
| {% skip_file unless flag?(:compile_rt) %} | ||
|
|
||
| require "spec" | ||
| require "../../../../src/crystal/compiler_rt/muloti4" | ||
| require "../../../../src/crystal/compiler_rt/i128_info" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/muloti4_test.c | ||
|
|
||
| private def test__muloti4(a : (Int128 | Int128RT), b : (Int128 | Int128RT), expected : (Int128 | Int128RT), expected_overflow : Int32, file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual_overflow : Int32 = 0 | ||
| actual = __muloti4(a.to_i128, b.to_i128, pointerof(actual_overflow)) | ||
| actual_overflow.should eq(expected_overflow), file, line | ||
| if !expected_overflow | ||
| actual.should eq(expected.to_i128), file, line | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "__muloti4" do | ||
| test__muloti4(0_i128, 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, 1_i128, 0_i128, 0) | ||
| test__muloti4(1_i128, 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, 10_i128, 0_i128, 0) | ||
| test__muloti4(10_i128, 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, 81985529216486895_i128, 0_i128, 0) | ||
| test__muloti4(81985529216486895_i128, 0, 0, 0) | ||
|
|
||
| test__muloti4(0_i128, Int128RT[1_i128].negate!, 0_i128, 0) | ||
| test__muloti4(Int128RT[1_i128].negate!, 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, Int128RT[10_i128].negate!, 0_i128, 0) | ||
| test__muloti4(Int128RT[10_i128].negate!, 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, Int128RT[81985529216486895_i128].negate!, 0_i128, 0) | ||
| test__muloti4(Int128RT[81985529216486895_i128].negate!, 0_i128, 0_i128, 0) | ||
|
|
||
| test__muloti4(1_i128, 1_i128, 1_i128, 0) | ||
| test__muloti4(1_i128, 10_i128, 10_i128, 0) | ||
| test__muloti4(10_i128, 1_i128, 10_i128, 0) | ||
| test__muloti4(1_i128, 81985529216486895_i128, 81985529216486895_i128, 0) | ||
| test__muloti4(81985529216486895_i128, 1_i128, 81985529216486895_i128, 0) | ||
|
|
||
| test__muloti4(1_i128, Int128RT[1_i128].negate!, Int128RT[1_i128].negate!, 0) | ||
| test__muloti4(1_i128, Int128RT[10_i128].negate!, Int128RT[10_i128].negate!, 0) | ||
| test__muloti4(Int128RT[10_i128].negate!, 1_i128, Int128RT[10_i128].negate!, 0) | ||
| test__muloti4(1_i128, Int128RT[81985529216486895_i128].negate!, Int128RT[81985529216486895_i128].negate!, 0) | ||
| test__muloti4(Int128RT[81985529216486895_i128].negate!, 1_i128, Int128RT[81985529216486895_i128].negate!, 0) | ||
|
|
||
| test__muloti4(3037000499_i128, 3037000499_i128, 9223372030926249001_i128, 0) | ||
| test__muloti4(Int128RT[3037000499_i128].negate!, 3037000499_i128, Int128RT[9223372030926249001_i128].negate!, 0) | ||
| test__muloti4(3037000499_i128, Int128RT[3037000499_i128].negate!, Int128RT[9223372030926249001_i128].negate!, 0) | ||
| test__muloti4(Int128RT[3037000499_i128].negate!, Int128RT[3037000499_i128].negate!, 9223372030926249001_i128, 0) | ||
|
|
||
| test__muloti4(4398046511103_i128, 2097152_i128, 9223372036852678656_i128, 0) | ||
| test__muloti4(Int128RT[4398046511103_i128].negate!, 2097152_i128, Int128RT[9223372036852678656_i128].negate!, 0) | ||
| test__muloti4(4398046511103_i128, Int128RT[2097152_i128].negate!, Int128RT[9223372036852678656_i128].negate!, 0) | ||
| test__muloti4(Int128RT[4398046511103_i128].negate!, Int128RT[2097152_i128].negate!, 9223372036852678656_i128, 0) | ||
|
|
||
| test__muloti4(2097152_i128, 4398046511103_i128, 9223372036852678656_i128, 0) | ||
| test__muloti4(Int128RT[2097152_i128].negate!, 4398046511103_i128, Int128RT[9223372036852678656_i128].negate!, 0) | ||
| test__muloti4(2097152_i128, Int128RT[4398046511103_i128].negate!, Int128RT[9223372036852678656_i128].negate!, 0) | ||
| test__muloti4(Int128RT[2097152_i128].negate!, Int128RT[4398046511103_i128].negate!, 9223372036852678656_i128, 0) | ||
|
|
||
| # test__muloti4(Int128RT[0x00000000000000B5_i64, 0x04F333F9DE5BE000_u64], Int128RT[0x0000000000000000_i64, 0x00B504F333F9DE5B_u64], Int128RT[0x7FFFFFFFFFFFF328_i64, 0xDF915DA296E8A000_u64], 0) | ||
| test__muloti4(Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], Int128RT[2_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1) | ||
| test__muloti4(Int128RT[2_i128].negate!, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1) | ||
| test__muloti4(Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], Int128RT[1_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 0) | ||
| test__muloti4(Int128RT[1_i128].negate!, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 0) | ||
| test__muloti4(Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 0_i128, 0) | ||
| test__muloti4(Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 1_i128, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 0) | ||
| test__muloti4(1_i128, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 0) | ||
| test__muloti4(Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 2_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1) | ||
| test__muloti4(2_i128, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1) | ||
| # test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], Int128RT[2_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| # test__muloti4(Int128RT[2_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| # test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], Int128RT[1_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| # test__muloti4(Int128RT[1_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 0_i128, 0) | ||
| test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 0) | ||
| test__muloti4(1_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 0) | ||
| # test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 2_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| # test__muloti4(2_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
|
|
||
| # test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], Int128RT[2_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1) | ||
| # test__muloti4(Int128RT[2_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1) | ||
| test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], Int128RT[1_i128].negate!, Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 0) | ||
| test__muloti4(Int128RT[1_i128].negate!, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], Int128RT[0x7FFFFFFFFFFFFFFF_i64, 0xFFFFFFFFFFFFFFFF_u64], 0) | ||
| test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 0_i128, 0_i128, 0) | ||
| test__muloti4(0_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 0_i128, 0) | ||
| test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 1_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 0) | ||
| test__muloti4(1_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 0) | ||
| # test__muloti4(Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], 2_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| # test__muloti4(2_i128, Int128RT[-9223372036854775808_i64, 0x0000000000000001_u64], Int128RT[-9223372036854775808_i64, 0x0000000000000000_u64], 1) | ||
| end | ||
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,51 @@ | ||
| {% skip_file unless flag?(:compile_rt) %} | ||
|
|
||
| require "spec" | ||
| require "../../../../src/crystal/compiler_rt/multi3.cr" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/multi3_test.c | ||
|
|
||
| private def test__multi3(a : (Int128 | Int128RT), b : (Int128 | Int128RT), expected : (Int128 | Int128RT), file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| __multi3(a.to_i128, b.to_i128).should eq(expected.to_i128), file, line | ||
| end | ||
| end | ||
|
|
||
| describe "__multi3" do | ||
| test__multi3(0_i128, 0_i128, 0_i128) | ||
| test__multi3(0_i128, 1_i128, 0_i128) | ||
| test__multi3(1_i128, 0_i128, 0_i128) | ||
| test__multi3(0_i128, 10_i128, 0_i128) | ||
| test__multi3(10_i128, 0_i128, 0_i128) | ||
| test__multi3(0_i128, 81985529216486895_i128, 0_i128) | ||
| test__multi3(81985529216486895_i128, 0_i128, 0_i128) | ||
| test__multi3(0_i128, Int128RT[1_i128].negate!, 0_i128) | ||
| test__multi3(Int128RT[1_i128].negate!, 0_i128, 0_i128) | ||
| test__multi3(0_i128, Int128RT[10_i128].negate!, 0_i128) | ||
| test__multi3(Int128RT[10_i128].negate!, 0_i128, 0_i128) | ||
| test__multi3(0_i128, Int128RT[81985529216486895_i128].negate!, 0_i128) | ||
| test__multi3(Int128RT[81985529216486895_i128].negate!, 0_i128, 0_i128) | ||
| test__multi3(1_i128, 1_i128, 1_i128) | ||
| test__multi3(1_i128, 10_i128, 10_i128) | ||
| test__multi3(10_i128, 1_i128, 10_i128) | ||
| test__multi3(1_i128, 81985529216486895_i128, 81985529216486895_i128) | ||
| test__multi3(81985529216486895_i128, 1_i128, 81985529216486895_i128) | ||
| test__multi3(1_i128, Int128RT[1_i128].negate!, Int128RT[1_i128].negate!) | ||
| test__multi3(1_i128, Int128RT[10_i128].negate!, Int128RT[10_i128].negate!) | ||
| test__multi3(Int128RT[10_i128].negate!, 1_i128, Int128RT[10_i128].negate!) | ||
| test__multi3(1_i128, Int128RT[81985529216486895_i128].negate!, Int128RT[81985529216486895_i128].negate!) | ||
| test__multi3(Int128RT[81985529216486895_i128].negate!, 1_i128, Int128RT[81985529216486895_i128].negate!) | ||
| test__multi3(3037000499_i128, 3037000499_i128, 9223372030926249001_i128) | ||
| test__multi3(Int128RT[3037000499_i128].negate!, 3037000499_i128, Int128RT[9223372030926249001_i128].negate!) | ||
| test__multi3(3037000499_i128, Int128RT[3037000499_i128].negate!, Int128RT[9223372030926249001_i128].negate!) | ||
| test__multi3(Int128RT[3037000499_i128].negate!, Int128RT[3037000499_i128].negate!, 9223372030926249001_i128) | ||
| test__multi3(4398046511103_i128, 2097152_i128, 9223372036852678656_i128) | ||
| test__multi3(Int128RT[4398046511103_i128].negate!, 2097152_i128, Int128RT[9223372036852678656_i128].negate!) | ||
| test__multi3(4398046511103_i128, Int128RT[2097152_i128].negate!, Int128RT[9223372036852678656_i128].negate!) | ||
| test__multi3(Int128RT[4398046511103_i128].negate!, Int128RT[2097152_i128].negate!, 9223372036852678656_i128) | ||
| test__multi3(2097152_i128, 4398046511103_i128, 9223372036852678656_i128) | ||
| test__multi3(Int128RT[2097152_i128].negate!, 4398046511103_i128, Int128RT[9223372036852678656_i128].negate!) | ||
| test__multi3(2097152_i128, Int128RT[4398046511103_i128].negate!, Int128RT[9223372036852678656_i128].negate!) | ||
| test__multi3(Int128RT[2097152_i128].negate!, Int128RT[4398046511103_i128].negate!, 9223372036852678656_i128) | ||
| test__multi3(Int128RT[0x00000000000000B5_i64, 0x04F333F9DE5BE000_u64].all, Int128RT[0x0000000000000000_i64, 0x00B504F333F9DE5B_u64].all, Int128RT[0x7FFFFFFFFFFFF328_i64, 0xDF915DA296E8A000_u64].all) | ||
| end |
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,28 @@ | ||
| {% skip_file unless flag?(:compile_rt) %} | ||
|
|
||
| require "spec" | ||
| require "../../../../src/crystal/compiler_rt/udivmodti4.cr" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/udivmodti4_test.c | ||
|
|
||
| private def test__udivmodti4(a : (UInt128 | UInt128RT), b : (UInt128 | UInt128RT), expected : (UInt128 | UInt128RT), expected_overflow : (UInt128 | UInt128RT), file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| actual_overflow = 0_u128 | ||
| actual = __udivmodti4(a.to_u128, b.to_u128, pointerof(actual_overflow)) | ||
| actual_overflow.should eq(expected_overflow.to_u128), file, line | ||
| if !expected_overflow.to_u128 | ||
| actual.should eq(expected.to_u128), file, line | ||
| end | ||
| end | ||
| end | ||
|
|
||
| private UDIVMODTI4_TESTS = StaticArray[ | ||
| StaticArray[UInt128RT[1_i128], UInt128RT[1_i128], UInt128RT[1_i128], UInt128RT[0_i128]], | ||
| # # TODO: this is a placeholder, remove when ready | ||
| ] | ||
|
|
||
| describe "__udivmodti4" do | ||
| UDIVMODTI4_TESTS.each do |tests| | ||
| test__udivmodti4(tests[0], tests[1], tests[2], tests[3]) | ||
| end | ||
| end |
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 @@ | ||
| {% skip_file unless flag?(:compile_rt) %} | ||
|
|
||
| require "spec" | ||
| require "../../../../src/crystal/compiler_rt/umodti3" | ||
|
|
||
| # Ported from compiler-rt:test/builtins/Unit/umodti3_test.c | ||
|
|
||
| private def test__umodti3(a : (UInt128 | UInt128RT), b : (UInt128 | UInt128RT), expected : (UInt128 | UInt128RT), file = __FILE__, line = __LINE__) | ||
| it "passes compiler-rt builtins unit tests" do | ||
| __umodti3(a.to_u128, b.to_u128).should eq(expected.to_u128), file, line | ||
| end | ||
| end | ||
|
|
||
| describe "__umodti3" do | ||
| test__umodti3(0_u128, 1_u128, 0_u128) | ||
| test__umodti3(2_u128, 1_u128, 0_u128) | ||
| test__umodti3(UInt128RT[0x0000000000000000_u64, 0x8000000000000000_u64], 1_u128, 0_u128) | ||
| test__umodti3(UInt128RT[0x0000000000000000_u64, 0x8000000000000000_u64], 2_u128, 0_u128) | ||
| test__umodti3(UInt128RT[0xFFFFFFFFFFFFFFFF_u64, 0xFFFFFFFFFFFFFFFF_u64], 2_u128, 1_u128) | ||
| end |
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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # Low Level Runtime Functions for LLVM. | ||
| # The function definitions and explinations can be found here. | ||
| # https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html#Libgcc | ||
|
|
||
| {% skip_file if flag?(:skip_crystal_compiler_rt) %} | ||
|
|
||
| require "./compiler_rt/mulodi4.cr" |
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,14 @@ | ||
| require "./udivmodti4" | ||
|
|
||
| # Function returning quotient for signed division eg `a / b` | ||
|
|
||
| fun __divti3(a : Int128, b : Int128) : Int128 | ||
| bits_in_tword_m1 = (sizeof(Int128) &* sizeof(Char)) &- 1 | ||
| s_a = a >> bits_in_tword_m1 | ||
| s_b = b >> bits_in_tword_m1 | ||
| a = (a ^ s_a) &- s_a | ||
| b = (b ^ s_b) &- s_b | ||
| s_a ^= s_b | ||
| r = 0_u128 | ||
| ((__udivmodti4(a.unsafe_as(UInt128), b.unsafe_as(UInt128), pointerof(r)) ^ s_a) &- s_a).unsafe_as(Int128) | ||
| end |
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,37 @@ | ||
| @[Extern] | ||
jkthorne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| struct Int128Info | ||
| property low : UInt64 = 0_u64 | ||
| property high : Int64 = 0_i64 | ||
| end | ||
|
|
||
| @[Extern(union: true)] | ||
| struct Int128RT | ||
| property all : Int128 = 0_i128 | ||
| property info : Int128Info = Int128Info.new | ||
|
|
||
| macro [](high, low) | ||
| %i_info = uninitialized Int128RT | ||
| %i_info.info.high = {{high}}.unsafe_as(Int64) | ||
| %i_info.info.low = {{low}}.unsafe_as(UInt64) | ||
| %i_info | ||
| end | ||
|
|
||
| macro [](high) | ||
| %i_info = uninitialized Int128RT | ||
| %i_info.all = {{high}}.unsafe_as(Int128) | ||
| %i_info | ||
| end | ||
|
|
||
| def negate! | ||
| self.all = self.all * -1 | ||
| self | ||
| end | ||
|
|
||
| def to_i128 | ||
| all | ||
| end | ||
|
|
||
| def debug | ||
| printf("%x:%x\n", info.high, info.low) | ||
| end | ||
| end | ||
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,14 @@ | ||
| require "./udivmodti4" | ||
|
|
||
| # Function return the remainder of the signed division eg. `a % b` | ||
|
|
||
| fun __modti3(a : Int128, b : Int128) : Int128 | ||
| bits_in_tword_m1 = sizeof(Int128) &* sizeof(Char) &- 1 | ||
| s = b >> bits_in_tword_m1 | ||
| b = (b ^ s) &- s | ||
| s = a >> bits_in_tword_m1 | ||
| a = (a ^ s) &- s | ||
| r = 0_u128 | ||
| __udivmodti4(a.unsafe_as(UInt128), b.unsafe_as(UInt128), pointerof(r)) | ||
| (r ^ s).unsafe_as(Int128) &- s # negate if s == -1 | ||
| end |
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,24 @@ | ||
| require "./i128_info" | ||
|
|
||
| # Functions for returning the product of signed integer multiplication eg. `a * b` | ||
|
|
||
| fun __mulddi3(a : UInt64, b : UInt64) : Int128 | ||
| r = Int128RT.new | ||
| bits_in_dword_2 = sizeof(UInt128) * sizeof(Char) // 2 | ||
| lower_mask = ~0_u64 >> bits_in_dword_2 | ||
|
|
||
| r.info.low = (a & lower_mask) &* (b & lower_mask) | ||
| t = r.info.low >> bits_in_dword_2 | ||
| r.info.low = r.info.low & lower_mask | ||
| t += (a >> bits_in_dword_2) &* (b & lower_mask) | ||
| r.info.low = (r.info.low &+ ((t & lower_mask) << bits_in_dword_2)) | ||
| r.info.high = (t >> bits_in_dword_2).unsafe_as(Int64) | ||
| t = r.info.low >> bits_in_dword_2 | ||
| r.info.low = r.info.low & lower_mask | ||
| t += (b >> bits_in_dword_2) &* (a & lower_mask) | ||
| r.info.low = (r.info.low &+ ((t & lower_mask) << bits_in_dword_2)) | ||
| r.info.high = r.info.high &+ (t >> bits_in_dword_2) | ||
| r.info.high = r.info.high &+ ((a >> bits_in_dword_2) &* (b >> bits_in_dword_2)) | ||
|
|
||
| r.all | ||
| end |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there so many commented out tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they are broken. The main problem is
__udivmodti4but it is hard to debug and I work on one failure at a time. I have gotten enough help from these PRs that I can close them and reopen them when I am closer if that helps.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is WIP, then could you please indicate that in the title?