Skip to content

Implement bitwise builtin variants (l, ll) and improve constant evaluation#945

Open
bungcip wants to merge 1 commit intomainfrom
feat/bitwise-builtins-variants-13042398019651368740
Open

Implement bitwise builtin variants (l, ll) and improve constant evaluation#945
bungcip wants to merge 1 commit intomainfrom
feat/bitwise-builtins-variants-13042398019651368740

Conversation

@bungcip
Copy link
Copy Markdown
Owner

@bungcip bungcip commented Mar 28, 2026

I have implemented the long and long long variants for the core bitwise builtins (popcount, clz, ctz, ffs) in the Cendol compiler. This implementation spans the entire compiler pipeline, from parsing to code generation, and includes bit-width aware constant evaluation and expanded __has_builtin support. Comprehensive tests were added to verify correctness.


PR created automatically by Jules for task 13042398019651368740 started by @bungcip

This commit implements the missing `long` (`l`) and `long long` (`ll`)
variants for the following bitwise builtins:
- `__builtin_popcount`
- `__builtin_clz`
- `__builtin_ctz`
- `__builtin_ffs`

Key changes:
- Added specific AST variants for each builtin in `ParsedNodeKind` and `NodeKind`.
- Updated the parser to distinguish between these variants.
- Implemented proper type checking in the semantic analyzer, ensuring arguments
  are correctly promoted to `unsigned long` or `unsigned long long` where
  appropriate, while results remain `int`.
- Enhanced constant evaluation to be bit-width aware. Specifically, `clz`
  now correctly accounts for the bit-width of its argument type (32 for `int`,
  64 for `long long`).
- Updated MIR generation to lower these builtins to their corresponding
  integer operations.
- Expanded `__has_builtin` support in the preprocessor to include all
  newly implemented variants and other existing supported builtins.
- Added comprehensive unit tests in `src/tests/bitwise_builtins.rs` covering
  constant evaluation and runtime behavior.

Co-authored-by: bungcip <72723+bungcip@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant