Skip to content
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

Int128: fix how LLVM::Type.const_int emit 128 literals #7135

Merged
merged 1 commit into from
Dec 2, 2018

Conversation

bcardiff
Copy link
Member

@bcardiff bcardiff commented Dec 1, 2018

The llvm wrapper is not able to emit 128bits ints.

Instead of going the way #7093 did of using String. This will allow to use LLVMConstIntOfArbitraryPrecision method that accept the number as an array of UInt64.

@bcardiff bcardiff added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Dec 1, 2018
@bcardiff bcardiff added this to the 0.27.1 milestone Dec 1, 2018
@RX14 RX14 merged commit 4754d53 into crystal-lang:master Dec 2, 2018
if !value.is_a?(Int128) && !value.is_a?(UInt128) && int_width != 128
Value.new LibLLVM.const_int(self, value, 0)
else
encoded_value = UInt64[value & UInt64::MAX, (value >> 64) & UInt64::MAX]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this allocates memory. Why not use static_array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK the reference is kept in llvm side. I couldn't find where the pointer was used to duplicate the data so I assume a reference was used. I could be wrong the documentation didn't said much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's kept in LLVM side then we must keep a reference on our side, otherwise the GC will collect it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcardiff bcardiff deleted the feature/llvm-emit-128 branch December 2, 2018 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants