forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#135760 - scottmcm:disjoint-bitor, r=WaffleLapkin
Add `unchecked_disjoint_bitor` per ACP373 Following the names from libs-api in rust-lang/libs-team#373 (comment) Includes a fallback implementation so this doesn't have to update cg_clif or cg_gcc, and overrides it in cg_llvm to use `or disjoint`, which [is available in LLVM 18](https://releases.llvm.org/18.1.0/docs/LangRef.html#or-instruction) so hopefully we don't need any version checks.
- Loading branch information
Showing
14 changed files
with
205 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![feature(core_intrinsics)] | ||
fn main() { | ||
// one bit in common | ||
unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) }; //~ ERROR: Undefined Behavior | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tools/miri/tests/fail/intrinsics/disjoint_bitor.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: `assume` called with `false` | ||
--> tests/fail/intrinsics/disjoint_bitor.rs:LL:CC | ||
| | ||
LL | unsafe { std::intrinsics::disjoint_bitor(0b01101001_u8, 0b10001110) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `assume` called with `false` | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE: | ||
= note: inside `main` at tests/fail/intrinsics/disjoint_bitor.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ compile-flags: -C opt-level=3 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(bigint_helper_methods)] | ||
|
||
// CHECK-LABEL: @u32_carrying_add | ||
#[no_mangle] | ||
pub fn u32_carrying_add(a: u32, b: u32, c: bool) -> (u32, bool) { | ||
// CHECK: @llvm.uadd.with.overflow.i32 | ||
// CHECK: @llvm.uadd.with.overflow.i32 | ||
// CHECK: or disjoint i1 | ||
u32::carrying_add(a, b, c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::disjoint_bitor; | ||
|
||
// CHECK-LABEL: @disjoint_bitor_signed | ||
#[no_mangle] | ||
pub unsafe fn disjoint_bitor_signed(x: i32, y: i32) -> i32 { | ||
// CHECK: or disjoint i32 %x, %y | ||
disjoint_bitor(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @disjoint_bitor_unsigned | ||
#[no_mangle] | ||
pub unsafe fn disjoint_bitor_unsigned(x: u64, y: u64) -> u64 { | ||
// CHECK: or disjoint i64 %x, %y | ||
disjoint_bitor(x, y) | ||
} | ||
|
||
// CHECK-LABEL: @disjoint_bitor_literal | ||
#[no_mangle] | ||
pub unsafe fn disjoint_bitor_literal() -> u8 { | ||
// This is a separate check because even without any passes, | ||
// LLVM will fold so it's not an instruction, which can assert in LLVM. | ||
|
||
// CHECK: store i8 3 | ||
disjoint_bitor(1, 2) | ||
} |