2022-08-14 21:06:01 -05:00
|
|
|
// Floating-point clamp is designed to be implementable as max+min,
|
|
|
|
// so check to make sure that's what it's actually emitting.
|
|
|
|
|
|
|
|
//@ assembly-output: emit-asm
|
2024-05-01 18:54:20 -05:00
|
|
|
// Set the base cpu explicitly, in case the default has been changed.
|
2024-05-01 17:25:26 -05:00
|
|
|
//@ compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel -C target-cpu=x86-64
|
2022-08-14 21:06:01 -05:00
|
|
|
//@ only-x86_64
|
2023-03-09 03:28:44 -06:00
|
|
|
//@ ignore-sgx
|
2022-08-14 21:06:01 -05:00
|
|
|
|
|
|
|
// CHECK-LABEL: clamp_demo:
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn clamp_demo(a: f32, x: f32, y: f32) -> f32 {
|
|
|
|
// CHECK: maxss
|
|
|
|
// CHECK: minss
|
|
|
|
a.clamp(x, y)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: clamp12_demo:
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn clamp12_demo(a: f32) -> f32 {
|
2022-08-16 20:39:22 -05:00
|
|
|
// CHECK: movss xmm1
|
2022-08-14 21:06:01 -05:00
|
|
|
// CHECK-NEXT: maxss xmm1, xmm0
|
|
|
|
// CHECK-NEXT: movss xmm0
|
|
|
|
// CHECK-NEXT: minss xmm0, xmm1
|
2022-08-20 16:08:56 -05:00
|
|
|
// CHECK: ret
|
2022-08-14 21:06:01 -05:00
|
|
|
a.clamp(1.0, 2.0)
|
|
|
|
}
|