]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/intrinsics/offset_from.rs
Auto merge of #98489 - cjgillot:naked-nohir, r=davidtwco,tmiasko
[rust.git] / src / test / codegen / intrinsics / offset_from.rs
1 // compile-flags: -C opt-level=1
2 // only-64bit (because we're using [ui]size)
3
4 #![crate_type = "lib"]
5 #![feature(core_intrinsics)]
6
7 //! Basic optimizations are enabled because otherwise `x86_64-gnu-nopt` had an alloca.
8 //! Uses a type with non-power-of-two size to avoid normalizations to shifts.
9
10 use std::intrinsics::*;
11
12 type RGB = [u8; 3];
13
14 // CHECK-LABEL: @offset_from_odd_size
15 #[no_mangle]
16 pub unsafe fn offset_from_odd_size(a: *const RGB, b: *const RGB) -> isize {
17     // CHECK: start
18     // CHECK-NEXT: ptrtoint
19     // CHECK-NEXT: ptrtoint
20     // CHECK-NEXT: sub i64
21     // CHECK-NEXT: sdiv exact i64 %{{[0-9]+}}, 3
22     // CHECK-NEXT: ret i64
23     ptr_offset_from(a, b)
24 }
25
26 // CHECK-LABEL: @offset_from_unsigned_odd_size
27 #[no_mangle]
28 pub unsafe fn offset_from_unsigned_odd_size(a: *const RGB, b: *const RGB) -> usize {
29     // CHECK: start
30     // CHECK-NEXT: ptrtoint
31     // CHECK-NEXT: ptrtoint
32     // CHECK-NEXT: sub nuw i64
33     // CHECK-NEXT: udiv exact i64 %{{[0-9]+}}, 3
34     // CHECK-NEXT: ret i64
35     ptr_offset_from_unsigned(a, b)
36 }