-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support U/Int128 parsing and U/Int128 literals #11111
Conversation
I ❤️ this. I would love to see U/Int128 support in Crystal. |
A lot of checks seem to fail because they try to run the specs with the current release of crystal. When I run |
I just noticed there is a little breaking change:
I could easily change that behaviour however. |
I think you might need specs. I took a few swings at specs in some older PRs but I think you would probably want to take a slightly different approach. Probably convert the test cases into the base10 number and do the assertions. Also when I last worked on this I had to update some code in the symantics and syntax. Have you tried using the Int128 in a program. Does it work as expected? |
I have added specs (compiler specs and std specs), but I have only tested some basic math operations, nothing complicated. I'll probably need to do that. EDIT: Oh I just saw that there are specs for compiler-rt aswell.. I will probably need specs there too. |
Now there are specs for the new compiler-rt methods! |
Everything should work now, specs are also there. |
Suggestion by Sija Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
…into int128-parsing
The only issue right now is the windows CI. Could someone who knows anything about crystal windows support look into this? |
Alright.. after some testing it seems like windows is a major obstacle. Here's a demonstration to show how bad the situation is (both crystal-master + my branch): C:\crystal>crystal eval "puts 4_i128"
0 |
Windows really doesn't like my division/modulo implementation.
But at least I know where to search for errors now.. |
Okay, appearantly windows doesn't call my compiler-rt methods.
|
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
I think I found a fix in rust's combiler-builtins repo: |
It seems like msvc passes the u/int128's using a pointer to compiler-rt. The only problem now is that I have no clue how to return the calculated numbers. |
Thanks for this PR @BlobCodes, it's really awesome! In order to get this merged, we'll have to split it into two stages. The first stage adding compiler support and all the stdlib requirements for that. Only after that's been merged and released we can then merge the changes that actually make use of those compiler features. I wouldn't worry too much about windows support for now. It seems more complicated to work our. We can defer that after merging the feature for other platforms. It's not a requirement. You can just use flags to disable failing pieces on win32. There should be more unit test for overflowing multiplication. There is already |
Thanks, that's helpful! |
Superseded by #11196 |
@straight-shoota I honestly think the most fair thing to do is for us, core team members, to take care of i128 support, at least for multiplying them. And that can be in a separate PR. Mixing that with parsing Int128 doesn't feel right. Why don't we break them appart? |
Not sure if that's particularly fair, but yes of course, we can take care of that. But I have the impression that @BlobCodes has fun working on this, so why take it away? But as long as others want to work on something, I think our role should be primarly to support them to get their patches ready and merged. In summary, my understanding of the core team's responsibility is to help other make contributions and take on those tasks that nobody else does =) |
Regarding the specific note about i128 arithmetics, I think that's really already completed in #11196. Except for windows support which I suggested to postpone (and I'm happy to work on afterwards, if nobody else is interested). |
Supporting the int128 arithmetics is not the problem. Basically, we'd need to do this: {% if flag?(:win32) %}
# Windows
@[SIMD]
record U64x2, a : UInt64, b : UInt64
fun __divti3(a : Int128*, b : Int128*) : U64x2
{% else %}
# Unix
fun __divti3(a : Int128, b : Int128) : Int128
{% end %} It would be really nice if the core members could add this, because I have no clue about crystal codegen and llvm (I think there was already a implementation in a crystal issue) |
@BlobCodes It seems SIMD in llvm is represented by the vector type: https://llvm.org/docs/LangRef.html#vector-type . It's almost like a StaticArray, except that it uses a different internal representation. I guess creating a type for it should be pretty easy. The hardest part will be to come up with a name for it 😁 But I was talking about how to dissect this PR. The interpreter doesn't work right now in linux because multiplication between Int128 doesn't work. I think a PR that just tackles that makes sense. It has nothing to do with parsing Int128. That's all I was saying. And for that, there's no need for you, @BlobCodes, to do it. The code is already in some of these PRs. One core team member could extract those changes and add specs on their own. |
This PR adds:
With this you can do crazy things like:
To not introduce breaking changes, the method
deduce_integer_kind
now uses the following priority:Int32 > Int64 > UInt64 > Int128 > UInt128
. I don't know if this should be changed.Requires/Includes #11093
Related to #8373
Supersedes #10975
Closes #9516
Closes #10962
Closes #7915
Related to #5545