Skip to content

Intrinsic: Add ctlz and ctlz_nonzero intrinsics#4467

Open
moabo3li wants to merge 3 commits intoRust-GCC:masterfrom
moabo3li:ctlz_support
Open

Intrinsic: Add ctlz and ctlz_nonzero intrinsics#4467
moabo3li wants to merge 3 commits intoRust-GCC:masterfrom
moabo3li:ctlz_support

Conversation

@moabo3li
Copy link
Contributor

@moabo3li moabo3li commented Mar 7, 2026

This commit introduces the ctlz and ctlz_nonzero intrinsics for counting leading zeros in integer types.
The implementation includes handlers for both intrinsics, which validate input types and utilize GCC built-ins for the actual computation.

Addresses: #658

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc: Register ctlz and ctlz_nonzero intrinsics.
* backend/rust-intrinsic-handlers.cc (ctlz_handler): Implement ctlz_handler.
(ctlz_nonzero_handler): Implement ctlz_nonzero_handler.
* backend/rust-intrinsic-handlers.h (ctlz_handler): Add decl for ctlz_handler.
(ctlz_nonzero_handler): Add decl for ctlz_nonzero_handler.
* util/rust-intrinsic-values.h: map ctlz_nonzero to its name.

gcc/testsuite/ChangeLog:

* rust/compile/ctlz.rs: New test.
* rust/compile/ctlz_nonzero.rs: New test.
* rust/execute/torture/ctlz.rs: New test.
* rust/execute/torture/ctlz_nonzero.rs: New test.

@moabo3li
Copy link
Contributor Author

cc @P-E-P

@moabo3li moabo3li force-pushed the ctlz_support branch 5 times, most recently from ff9b24e to a80240c Compare March 19, 2026 13:00
This commit introduces the `ctlz` and `ctlz_nonzero` intrinsics for counting leading zeros
in integer types.
The implementation includes handlers for both intrinsics, which validate input types and utilize
GCC built-ins for the actual computation.

Addresses: Rust-GCC#658

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc: Register ctlz and ctlz_nonzero intrinsics.
	* backend/rust-intrinsic-handlers.cc (ctlz_handler): Implement ctlz_handler.
	(ctlz_nonzero_handler): Implement ctlz_nonzero_handler.
	* backend/rust-intrinsic-handlers.h (ctlz_handler): Add decl for ctlz_handler.
	(ctlz_nonzero_handler): Add decl for ctlz_nonzero_handler.
	* util/rust-intrinsic-values.h: map ctlz_nonzero to its name.

gcc/testsuite/ChangeLog:

	* rust/compile/ctlz.rs: New test.
	* rust/compile/ctlz_nonzero.rs: New test.
	* rust/execute/torture/ctlz.rs: New test.
	* rust/execute/torture/ctlz_nonzero.rs: New test.

Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
gcc/testsuite/ChangeLog:

	* rust/execute/torture/ctlz_i16.rs: New test.
	* rust/execute/torture/ctlz_i32.rs: New test.
	* rust/execute/torture/ctlz_i64.rs: New test.
	* rust/execute/torture/ctlz_i8.rs: New test.
	* rust/execute/torture/ctlz_nonzero_i16.rs: New test.
	* rust/execute/torture/ctlz_nonzero_i32.rs: New test.
	* rust/execute/torture/ctlz_nonzero_i64.rs: New test.
	* rust/execute/torture/ctlz_nonzero_i8.rs: New test.
	* rust/execute/torture/ctlz_nonzero_u16.rs: New test.
	* rust/execute/torture/ctlz_nonzero_u32.rs: New test.
	* rust/execute/torture/ctlz_nonzero_u64.rs: New test.
	* rust/execute/torture/ctlz_nonzero_u8.rs: New test.
	* rust/execute/torture/ctlz_u16.rs: New test.
	* rust/execute/torture/ctlz_u32.rs: New test.
	* rust/execute/torture/ctlz_u64.rs: New test.
	* rust/execute/torture/ctlz_u8.rs: New test.

Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
gcc/rust/ChangeLog:

	* lex/rust-lex.cc (Lexer::parse_non_decimal_int_literal): strtoull insted strtol

Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
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