forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#100556 - Alex-Velez:patch-1, r=scottmcm
Clamp Function for f32 and f64 I thought the clamp function could use a little improvement for readability purposes. The function now returns early in order to skip the extra bound checks. If there was a reason for binding `self` to `x` or if this code is incorrect, please correct me :)
- Loading branch information
Showing
3 changed files
with
37 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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 | ||
// compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel | ||
// only-x86_64 | ||
|
||
// 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 { | ||
// CHECK: movss xmm1 | ||
// CHECK-NEXT: maxss xmm1, xmm0 | ||
// CHECK-NEXT: movss xmm0 | ||
// CHECK-NEXT: minss xmm0, xmm1 | ||
// CHECK: ret | ||
a.clamp(1.0, 2.0) | ||
} |