-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for fast math intrinsics #804
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
08fe4b6
Support for fast math intrinsics
adpaco-aws ab75385
Add (failing) positive test for `fadd_fast`
adpaco-aws b4893e2
Undo change in `typecheck_binop_args`
adpaco-aws 38d030c
Encode fast math intrinsics as regular binops
adpaco-aws 93586e8
Add all tests for fast math intrinsics
adpaco-aws c532dfc
Add tests for 32-bit values and compare results
adpaco-aws b074099
Drop support for `frem_fast`
adpaco-aws e76b8d4
Add comment to `get_stmts`
adpaco-aws 4efbfa7
Merge branch 'main' into fast-math
adpaco-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,21 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fadd_fast` overflow checks pass with suitable assumptions | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f32 = kani::any(); | ||
let y: f32 = kani::any(); | ||
|
||
kani::assume(x.is_finite()); | ||
kani::assume(y.is_finite()); | ||
match (x.is_sign_positive(), y.is_sign_positive()) { | ||
(true, true) => kani::assume(x < f32::MAX - y), | ||
(false, false) => kani::assume(x > f32::MIN - y), | ||
_ => (), | ||
} | ||
let z = unsafe { std::intrinsics::fadd_fast(x, y) }; | ||
let w = x + y; | ||
assert!(z == w); | ||
} |
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,19 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fadd_fast` overflow checks pass with suitable assumptions | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f64 = kani::any(); | ||
let y: f64 = kani::any(); | ||
|
||
kani::assume(x.is_finite()); | ||
kani::assume(y.is_finite()); | ||
match (x.is_sign_positive(), y.is_sign_positive()) { | ||
(true, true) => kani::assume(x < f64::MAX - y), | ||
(false, false) => kani::assume(x > f64::MIN - y), | ||
_ => (), | ||
} | ||
let _z = unsafe { std::intrinsics::fadd_fast(x, y) }; | ||
} |
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,12 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fadd_fast` triggers overflow checks | ||
// kani-verify-fail | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f32 = kani::any(); | ||
let y: f32 = kani::any(); | ||
let _z = unsafe { std::intrinsics::fadd_fast(x, y) }; | ||
} |
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,12 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fadd_fast` triggers overflow checks | ||
// kani-verify-fail | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f64 = kani::any(); | ||
let y: f64 = kani::any(); | ||
let _z = unsafe { std::intrinsics::fadd_fast(x, y) }; | ||
} |
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,36 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fdiv_fast` overflow checks pass with suitable assumptions | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
// Unconstrained floating point values will cause performance issues in this | ||
// operation. To avoid them, we assume values within a moderate range. | ||
const MIN_FP_VALUE: f32 = 0.1; | ||
const MAX_FP_VALUE: f32 = 100.0; | ||
|
||
fn assume_fp_range(val: f32) { | ||
if val.is_sign_positive() { | ||
kani::assume(val > MIN_FP_VALUE); | ||
kani::assume(val < MAX_FP_VALUE); | ||
} else { | ||
kani::assume(val < -MIN_FP_VALUE); | ||
kani::assume(val > -MAX_FP_VALUE); | ||
} | ||
} | ||
|
||
fn main() { | ||
let x: f32 = kani::any(); | ||
let y: f32 = kani::any(); | ||
|
||
kani::assume(x.is_finite()); | ||
kani::assume(y.is_finite()); | ||
assume_fp_range(x); | ||
assume_fp_range(y); | ||
|
||
// Comparing `z` and `w` below causes serious performance issues | ||
// https://github.com/model-checking/kani/issues/809 | ||
let z = unsafe { std::intrinsics::fdiv_fast(x, y) }; | ||
// let w = x / y; | ||
// assert!(z == w); | ||
} |
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,32 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fdiv_fast` overflow checks pass with suitable assumptions | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
// Unconstrained floating point values will cause performance issues in this | ||
// operation. To avoid them, we assume values within a moderate range. | ||
const MIN_FP_VALUE: f64 = 0.1; | ||
const MAX_FP_VALUE: f64 = 100.0; | ||
|
||
fn assume_fp_range(val: f64) { | ||
if val.is_sign_positive() { | ||
kani::assume(val > MIN_FP_VALUE); | ||
kani::assume(val < MAX_FP_VALUE); | ||
} else { | ||
kani::assume(val < -MIN_FP_VALUE); | ||
kani::assume(val > -MAX_FP_VALUE); | ||
} | ||
} | ||
|
||
fn main() { | ||
let x: f64 = kani::any(); | ||
let y: f64 = kani::any(); | ||
|
||
kani::assume(x.is_finite()); | ||
kani::assume(y.is_finite()); | ||
assume_fp_range(x); | ||
assume_fp_range(y); | ||
|
||
let _z = unsafe { std::intrinsics::fdiv_fast(x, y) }; | ||
} |
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,12 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fdiv_fast` triggers overflow checks | ||
// kani-verify-fail | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f32 = kani::any(); | ||
let y: f32 = kani::any(); | ||
let _z = unsafe { std::intrinsics::fdiv_fast(x, y) }; | ||
} |
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,12 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fdiv_fast` triggers overflow checks | ||
// kani-verify-fail | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f64 = kani::any(); | ||
let y: f64 = kani::any(); | ||
let _z = unsafe { std::intrinsics::fdiv_fast(x, y) }; | ||
} |
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,33 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fmul_fast` overflow checks pass with suitable assumptions | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
// Unconstrained floating point values will cause performance issues in this | ||
// operation. To avoid them, we assume values within a moderate range. | ||
const MAX_FP_VALUE: f32 = 100.0; | ||
|
||
fn assume_fp_range(val: f32) { | ||
if val.is_sign_positive() { | ||
kani::assume(val < MAX_FP_VALUE); | ||
} else { | ||
kani::assume(val > -MAX_FP_VALUE); | ||
} | ||
} | ||
|
||
fn main() { | ||
let x: f32 = kani::any(); | ||
let y: f32 = kani::any(); | ||
|
||
kani::assume(x.is_finite()); | ||
kani::assume(y.is_finite()); | ||
assume_fp_range(x); | ||
assume_fp_range(y); | ||
|
||
// Comparing `z` and `w` below causes serious performance issues | ||
// https://github.com/model-checking/kani/issues/809 | ||
let z = unsafe { std::intrinsics::fmul_fast(x, y) }; | ||
// let w = x * y; | ||
// assert!(z == w); | ||
} |
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,29 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fmul_fast` overflow checks pass with suitable assumptions | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
// Unconstrained floating point values will cause performance issues in this | ||
// operation. To avoid them, we assume values within a moderate range. | ||
const MAX_FP_VALUE: f64 = 100.0; | ||
|
||
fn assume_fp_range(val: f64) { | ||
if val.is_sign_positive() { | ||
kani::assume(val < MAX_FP_VALUE); | ||
} else { | ||
kani::assume(val > -MAX_FP_VALUE); | ||
} | ||
} | ||
|
||
fn main() { | ||
let x: f64 = kani::any(); | ||
let y: f64 = kani::any(); | ||
|
||
kani::assume(x.is_finite()); | ||
kani::assume(y.is_finite()); | ||
assume_fp_range(x); | ||
assume_fp_range(y); | ||
|
||
let _z = unsafe { std::intrinsics::fmul_fast(x, y) }; | ||
} |
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,12 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Check that `fmul_fast` triggers overflow checks | ||
// kani-verify-fail | ||
|
||
#![feature(core_intrinsics)] | ||
|
||
fn main() { | ||
let x: f32 = kani::any(); | ||
let y: f32 = kani::any(); | ||
let _z = unsafe { std::intrinsics::fmul_fast(x, y) }; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is part of an earlier version where the intrinsics where encoded in a block statement, so I needed to retrieve statements within in order to prepend the finite checks. This version does not use it, but I figured it could be useful for something else. We can remove it otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you do keep it, can you please add a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.