Skip to content

Commit aaf59b8

Browse files
sayantnfolkertdev
andcommitted
Add funnel_sh{l,r} functions and intrinsics
- Add a fallback implementation for the intrinsics - Add LLVM backend support for funnel shifts Co-Authored-By: folkertdev <[email protected]>
1 parent c070d27 commit aaf59b8

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(core_intrinsics, funnel_shifts)]
2+
3+
fn main() {
4+
unsafe {
5+
std::intrinsics::unchecked_funnel_shl(1_u32, 2, 32); //~ ERROR: Undefined Behavior
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/funnel_shl.rs:LL:CC
3+
|
4+
LL | std::intrinsics::unchecked_funnel_shl(1_u32, 2, 32);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/funnel_shl.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![feature(core_intrinsics, funnel_shifts)]
2+
3+
fn main() {
4+
unsafe {
5+
std::intrinsics::unchecked_funnel_shr(1_u32, 2, 32); //~ ERROR: Undefined Behavior
6+
}
7+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: Undefined Behavior: `assume` called with `false`
2+
--> tests/fail/intrinsics/funnel_shr.rs:LL:CC
3+
|
4+
LL | std::intrinsics::unchecked_funnel_shr(1_u32, 2, 32);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
= note: BACKTRACE:
10+
= note: inside `main` at tests/fail/intrinsics/funnel_shr.rs:LL:CC
11+
12+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
13+
14+
error: aborting due to 1 previous error
15+

tests/pass/intrinsics/integer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT OR Apache-2.0
22
// SPDX-FileCopyrightText: The Rust Project Developers (see https://thanks.rust-lang.org)
33

4-
#![feature(core_intrinsics)]
4+
#![feature(core_intrinsics, funnel_shifts)]
55
use std::intrinsics::*;
66

77
pub fn main() {
@@ -143,5 +143,11 @@ pub fn main() {
143143

144144
assert_eq!(unchecked_mul(6u8, 7), 42);
145145
assert_eq!(unchecked_mul(13, -5), -65);
146+
147+
assert_eq!(unchecked_funnel_shl(1_u32, 2, 5), 32);
148+
assert_eq!(unchecked_funnel_shl(1_u32, 2, 31), 0x80000001);
149+
150+
assert_eq!(unchecked_funnel_shr(1_u32, 2, 5), 0x08000000);
151+
assert_eq!(unchecked_funnel_shr(1_u32, 2, 31), 2);
146152
}
147153
}

0 commit comments

Comments
 (0)