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

Use alignment hack to workaround luajit lightuserdata #243

Closed
wants to merge 1 commit into from

Conversation

daurnimator
Copy link
Collaborator

Idea from #241 (comment)

@vcunat please review?

@vcunat
Copy link
Contributor

vcunat commented Aug 31, 2020

🤔 cqueues seem to be using that mask on various static const int (defined inside functions), and there I don't see any guarantee that they will be placed at least 32 bytes apart.

I also don't know if the mentioned "negative pointers" are realistic; they would cause problems

0xFFF0000000000000 to 0xFFFFFFFFFFFFFFFF

– not just for uniqueness but they would still be over 47 bits in the code as written ATM.

@daurnimator
Copy link
Collaborator Author

thinking cqueues seem to be using that mask on various static const int (defined inside functions), and there I don't see any guarantee that they will be placed at least 32 bytes apart.

Ah yep... I wonder if results from lua_newuserdata are guaranteed to fit in a lightuserdata. But looks like we'll need to different methods.

I also don't know if the mentioned "negative pointers" are realistic; they would cause problems

0xFFF0000000000000 to 0xFFFFFFFFFFFFFFFF

– not just for uniqueness but they would still be over 47 bits in the code as written ATM.

ah right; we still need the mask.

Another thought: we should mix the high bits into the low bits to preserve uniqueness if we use multiple methods.

@vcunat
Copy link
Contributor

vcunat commented Sep 1, 2020

Uniqueness: if you shift by six bits and use a 47-bit mask, you'll get the "sign" bit in the most significant one. EDIT: so possibilities are there, but the overall space to cover might be a bit large.

@daurnimator
Copy link
Collaborator Author

re: uniqueness I was thinking of if you ended up with e.g.

0x0000001234567800 as cqueue__poll (imagining we shifted by 8)
and
0x0000000012345678 as something returned from lua_newuserdata

then they could collide.
so instead of shifting 0x0000001234567800 right by 8; we'd move the high bits to low: x | ((x & 52) >> (52 - 8)) or something

@vcunat
Copy link
Contributor

vcunat commented Sep 1, 2020

I didn't realize you want to avoid collisions with other values, too.

@vcunat
Copy link
Contributor

vcunat commented Sep 30, 2020

So... we give this up in favor of LuaJIT/LuaJIT@e9af1abec54 ?

@daurnimator
Copy link
Collaborator Author

So... we give this up in favor of LuaJIT/LuaJIT@e9af1ab ?

ooo, yeah that sounds like a reasonable idea.... does it all work well?

@vcunat
Copy link
Contributor

vcunat commented Sep 30, 2020

I haven't tried it yet, but on a quick look, the approach supports up to 256 37-bit segments, so that sounds like a nice compromise.

@daurnimator
Copy link
Collaborator Author

Closing as LuaJIT/LuaJIT@e9af1abec54 is the real fix.

We should remove the current 47bit hack code in the next release.

@daurnimator daurnimator closed this Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants