forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for fast math intrinsics (model-checking#804)
* Support for fast math intrinsics * Add (failing) positive test for `fadd_fast` * Undo change in `typecheck_binop_args` * Encode fast math intrinsics as regular binops * Add all tests for fast math intrinsics * Add tests for 32-bit values and compare results * Drop support for `frem_fast` * Add comment to `get_stmts`
- Loading branch information
1 parent
8daa33e
commit 48e6c12
Showing
22 changed files
with
369 additions
and
3 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
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.