Skip to content

Additional arithmetic and bitwise primops #13000

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

Open
2 tasks done
spacekitteh opened this issue Apr 10, 2025 · 0 comments
Open
2 tasks done

Additional arithmetic and bitwise primops #13000

spacekitteh opened this issue Apr 10, 2025 · 0 comments
Labels
feature Feature request or proposal

Comments

@spacekitteh
Copy link

spacekitteh commented Apr 10, 2025

Is your feature request related to a problem?

Now that #11188 has made integer overflow an error instead of undefined behavior (which would manifest itself as just wrapping around), performing operations on IP and MAC addresses has become much more difficult. Additionally, until #11188, it had to be performed using an incredibly slow pure Nix implementation, which would make any non-trivial usage of such operations easily dominate the evaluation time of a NixOS configuration (e.g. #10387)

Proposed solution

  1. Implement more built-ins for bit manipulation, including left and right shifts. This can be implemented quite easily; e.g. this Lix patch is quite small, with about half of lines of code changed just being documentation and makefile updates.

  2. Implement a power function built-in. This would be very slightly trickier (but still trivial) due to checking whether the arguments are ints or floats. Ideally, it would also include a modulo argument.

Alternative solutions

One alternative to work around the specific issues in the linked issues/PRs would be to implement arbitrary-sized integers, e.g. by using the GNU MP library; but an ideal implementation of this would end up exposing the aforementioned built-ins anyway.

Additional context

Checklist


Add 👍 to issues you find important.

@spacekitteh spacekitteh added the feature Feature request or proposal label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

1 participant