File: offset_from.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (36 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//@ compile-flags: -C opt-level=1
//@ only-64bit (because we're using [ui]size)

#![crate_type = "lib"]
#![feature(core_intrinsics)]

//! Basic optimizations are enabled because otherwise `x86_64-gnu-nopt` had an alloca.
//! Uses a type with non-power-of-two size to avoid normalizations to shifts.

use std::intrinsics::*;

type RGB = [u8; 3];

// CHECK-LABEL: @offset_from_odd_size
#[no_mangle]
pub unsafe fn offset_from_odd_size(a: *const RGB, b: *const RGB) -> isize {
    // CHECK: start
    // CHECK-NEXT: ptrtoint
    // CHECK-NEXT: ptrtoint
    // CHECK-NEXT: sub i64
    // CHECK-NEXT: sdiv exact i64 %{{[0-9]+}}, 3
    // CHECK-NEXT: ret i64
    ptr_offset_from(a, b)
}

// CHECK-LABEL: @offset_from_unsigned_odd_size
#[no_mangle]
pub unsafe fn offset_from_unsigned_odd_size(a: *const RGB, b: *const RGB) -> usize {
    // CHECK: start
    // CHECK-NEXT: ptrtoint
    // CHECK-NEXT: ptrtoint
    // CHECK-NEXT: sub nuw i64
    // CHECK-NEXT: udiv exact i64 %{{[0-9]+}}, 3
    // CHECK-NEXT: ret i64
    ptr_offset_from_unsigned(a, b)
}