about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-19 18:57:39 +0000
committerbors <bors@rust-lang.org>2022-11-19 18:57:39 +0000
commitc5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b (patch)
treed750ff6e8581c0f61102ea195f0409ca77bd2f39 /src
parent2a434286a96d61e9f55a3144004beec48206bb29 (diff)
parentc9c017dfb55e375800c3e424311939a7ba3d4deb (diff)
downloadrust-c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b.tar.gz
rust-c5d82ed7a4ad94a538bb87e5016e7d5ce0bd434b.zip
Auto merge of #102795 - lukas-code:constify-is-aligned-via-align-offset, r=oli-obk
Constify `is_aligned` via `align_offset`

Alternative to https://github.com/rust-lang/rust/pull/102753

Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`.

Tracking Issue: https://github.com/rust-lang/rust/issues/104203
Diffstat (limited to 'src')
-rw-r--r--src/test/assembly/is_aligned.rs58
-rw-r--r--src/tools/miri/src/shims/intrinsics/mod.rs5
2 files changed, 58 insertions, 5 deletions
diff --git a/src/test/assembly/is_aligned.rs b/src/test/assembly/is_aligned.rs
new file mode 100644
index 00000000000..04b5de83423
--- /dev/null
+++ b/src/test/assembly/is_aligned.rs
@@ -0,0 +1,58 @@
+// assembly-output: emit-asm
+// min-llvm-version: 14.0
+// only-x86_64
+// revisions: opt-speed opt-size
+// [opt-speed] compile-flags: -Copt-level=1
+// [opt-size] compile-flags: -Copt-level=s
+#![crate_type="rlib"]
+
+#![feature(core_intrinsics)]
+#![feature(pointer_is_aligned)]
+
+// CHECK-LABEL: is_aligned_to_unchecked
+// CHECK: decq
+// CHECK-NEXT: testq
+// CHECK-NEXT: sete
+// CHECK: retq
+#[no_mangle]
+pub unsafe fn is_aligned_to_unchecked(ptr: *const u8, align: usize) -> bool {
+    unsafe {
+        std::intrinsics::assume(align.is_power_of_two())
+    }
+    ptr.is_aligned_to(align)
+}
+
+// CHECK-LABEL: is_aligned_1
+// CHECK: movb $1
+// CHECK: retq
+#[no_mangle]
+pub fn is_aligned_1(ptr: *const u8) -> bool {
+    ptr.is_aligned()
+}
+
+// CHECK-LABEL: is_aligned_2
+// CHECK: testb $1
+// CHECK-NEXT: sete
+// CHECK: retq
+#[no_mangle]
+pub fn is_aligned_2(ptr: *const u16) -> bool {
+    ptr.is_aligned()
+}
+
+// CHECK-LABEL: is_aligned_4
+// CHECK: testb $3
+// CHECK-NEXT: sete
+// CHECK: retq
+#[no_mangle]
+pub fn is_aligned_4(ptr: *const u32) -> bool {
+    ptr.is_aligned()
+}
+
+// CHECK-LABEL: is_aligned_8
+// CHECK: testb $7
+// CHECK-NEXT: sete
+// CHECK: retq
+#[no_mangle]
+pub fn is_aligned_8(ptr: *const u64) -> bool {
+    ptr.is_aligned()
+}
diff --git a/src/tools/miri/src/shims/intrinsics/mod.rs b/src/tools/miri/src/shims/intrinsics/mod.rs
index 6004e2078ad..5ea82adb9c6 100644
--- a/src/tools/miri/src/shims/intrinsics/mod.rs
+++ b/src/tools/miri/src/shims/intrinsics/mod.rs
@@ -368,11 +368,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
             }
 
             // Other
-            "exact_div" => {
-                let [num, denom] = check_arg_count(args)?;
-                this.exact_div(&this.read_immediate(num)?, &this.read_immediate(denom)?, dest)?;
-            }
-
             "breakpoint" => {
                 let [] = check_arg_count(args)?;
                 // normally this would raise a SIGTRAP, which aborts if no debugger is connected