[gccrs,COMMIT,2/2] intrinsic: Add tests for cttz and cttz_nonzero
Checks
Commit Message
From: Mohamed Ali <mohmedali1462005@gmail.com>
gcc/testsuite/ChangeLog:
* rust/compile/cttz.rs: New test.
* rust/compile/cttz_nonzero.rs: New test.
* rust/execute/torture/cttz.rs: New test.
* rust/execute/torture/cttz_nonzero.rs: New test.
Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github: https://github.com/Rust-GCC/gccrs/commit/5c0e4d2c59c681f5f22d31173bf9c17202f60c80
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4511
gcc/testsuite/rust/compile/cttz.rs | 17 ++++
gcc/testsuite/rust/compile/cttz_nonzero.rs | 19 ++++
gcc/testsuite/rust/execute/torture/cttz.rs | 97 +++++++++++++++++++
.../rust/execute/torture/cttz_nonzero.rs | 74 ++++++++++++++
4 files changed, 207 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/cttz.rs
create mode 100644 gcc/testsuite/rust/compile/cttz_nonzero.rs
create mode 100644 gcc/testsuite/rust/execute/torture/cttz.rs
create mode 100644 gcc/testsuite/rust/execute/torture/cttz_nonzero.rs
new file mode 100644
@@ -0,0 +1,17 @@
+// { dg-do compile }
+#![feature(intrinsics, lang_items, no_core)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "copy"]
+pub trait Copy {}
+
+extern "rust-intrinsic" {
+ pub fn cttz<T>(x: T) -> u32; // { dg-error "cttz intrinsics can only be used with basic integer types .got 'bool'." }
+}
+
+fn main() {
+ let _ = cttz(true);
+}
new file mode 100644
@@ -0,0 +1,19 @@
+// { dg-do compile }
+#![feature(intrinsics, lang_items, no_core)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "copy"]
+pub trait Copy {}
+
+extern "rust-intrinsic" {
+ pub fn cttz_nonzero<T>(x: T) -> u32; // { dg-error "cttz intrinsics can only be used with basic integer types .got 'bool'." }
+}
+
+fn main() {
+ unsafe {
+ let _ = cttz_nonzero(true);
+ }
+}
new file mode 100644
@@ -0,0 +1,97 @@
+#![feature(no_core)]
+#![no_core]
+#![feature(intrinsics)]
+#![feature(lang_items)]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+extern "rust-intrinsic" {
+ pub fn cttz<T>(x: T) -> u32;
+ pub fn abort() -> !;
+}
+
+fn main() -> i32 {
+ // cttz(0) must return bit_size per the Rust reference
+ if cttz(0u8) != 8 {
+ abort();
+ }
+ if cttz(1u8) != 0 {
+ abort();
+ }
+ if cttz(0xFFu8) != 0 {
+ abort();
+ }
+
+ if cttz(0u16) != 16 {
+ abort();
+ }
+ if cttz(1u16) != 0 {
+ abort();
+ }
+ if cttz(0xFFFFu16) != 0 {
+ abort();
+ }
+
+ if cttz(0u32) != 32 {
+ abort();
+ }
+ if cttz(1u32) != 0 {
+ abort();
+ }
+ if cttz(0xFFFFFFFFu32) != 0 {
+ abort();
+ }
+
+ if cttz(0u64) != 64 {
+ abort();
+ }
+ if cttz(1u64) != 0 {
+ abort();
+ }
+ if cttz(!0u64) != 0 {
+ abort();
+ }
+
+ if cttz(0i8) != 8 {
+ abort();
+ }
+ if cttz(1i8) != 0 {
+ abort();
+ }
+ if cttz(-1i8) != 0 {
+ abort();
+ }
+
+ if cttz(0i16) != 16 {
+ abort();
+ }
+ if cttz(1i16) != 0 {
+ abort();
+ }
+ if cttz(-1i16) != 0 {
+ abort();
+ }
+
+ if cttz(0i32) != 32 {
+ abort();
+ }
+ if cttz(1i32) != 0 {
+ abort();
+ }
+ if cttz(-1i32) != 0 {
+ abort();
+ }
+
+ if cttz(0i64) != 64 {
+ abort();
+ }
+ if cttz(1i64) != 0 {
+ abort();
+ }
+ if cttz(-1i64) != 0 {
+ abort();
+ }
+
+ 0
+}
new file mode 100644
@@ -0,0 +1,74 @@
+#![feature(no_core)]
+#![no_core]
+#![feature(intrinsics)]
+#![feature(lang_items)]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+extern "rust-intrinsic" {
+ pub fn cttz_nonzero<T>(x: T) -> u32;
+ pub fn abort() -> !;
+}
+
+fn main() -> i32 {
+ unsafe {
+ if cttz_nonzero(1u8) != 0 {
+ abort();
+ }
+ if cttz_nonzero(0xFFu8) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1u16) != 0 {
+ abort();
+ }
+ if cttz_nonzero(0xFFFFu16) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1u32) != 0 {
+ abort();
+ }
+ if cttz_nonzero(0xFFFFFFFFu32) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1u64) != 0 {
+ abort();
+ }
+ if cttz_nonzero(!0u64) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1i8) != 0 {
+ abort();
+ }
+ if cttz_nonzero(-1i8) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1i16) != 0 {
+ abort();
+ }
+ if cttz_nonzero(-1i16) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1i32) != 0 {
+ abort();
+ }
+ if cttz_nonzero(-1i32) != 0 {
+ abort();
+ }
+
+ if cttz_nonzero(1i64) != 0 {
+ abort();
+ }
+ if cttz_nonzero(-1i64) != 0 {
+ abort();
+ }
+ }
+
+ 0
+}