-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added equivalence checking extensions
- Loading branch information
Showing
5 changed files
with
510 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "smack.h" | ||
|
||
double c_trunc(double x) | ||
{ | ||
union {double f; unsigned long i;} u = {x}; | ||
__VERIFIER_equiv_store_unsigned_long(u.i, 0); | ||
int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12; | ||
unsigned long m; | ||
|
||
if (e >= 52 + 12) | ||
return x; | ||
if (e < 12) | ||
e = 1; | ||
m = -1ULL >> e; | ||
__VERIFIER_equiv_store_unsigned_long(m, 1); | ||
__VERIFIER_equiv_store_unsigned_long(u.i & m, 2); | ||
if ((u.i & m) == 0) | ||
return x; | ||
__VERIFIER_equiv_store_unsigned_long(~m, 3); | ||
__VERIFIER_equiv_store_unsigned_long(u.i & ~m, 4); | ||
u.i &= ~m; | ||
__VERIFIER_equiv_store_unsigned_long(u.i, 5); | ||
return u.f; | ||
} |
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,49 @@ | ||
// Modified version from https://github.com/rust-lang/libm/blob/master/src/math/trunc.rs | ||
|
||
#[macro_use] | ||
extern crate smack; | ||
use smack::*; | ||
|
||
extern crate core; | ||
use core::f64; | ||
|
||
pub fn trunc(x: f64) -> f64 { | ||
let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120f === 2 ^ 120 | ||
|
||
let mut i: u64 = x.to_bits(); | ||
verifier_equiv_assume_u64(i, 0); | ||
let mut e: i64 = (i >> 52 & 0x7ff) as i64 - 0x3ff + 12; | ||
let m: u64; | ||
|
||
if e >= 52 + 12 { | ||
return x; | ||
} | ||
if e < 12 { | ||
e = 1; | ||
} | ||
m = -1i64 as u64 >> e; | ||
verifier_equiv_assume_u64(m, 1); | ||
verifier_equiv_assume_u64(i & m, 2); | ||
|
||
if (i & m) == 0 { | ||
return x; | ||
} | ||
verifier_equiv_assume_u64(!m, 3); | ||
verifier_equiv_assume_u64(i & !m, 4); | ||
i &= !m; | ||
verifier_equiv_assume_u64(i, 5); | ||
f64::from_bits(i) | ||
} | ||
|
||
extern "C" { | ||
fn c_trunc(x: f64) -> f64; | ||
fn __isnan(x: f64) -> i32; | ||
} | ||
|
||
fn main() { | ||
let x = 0.0.verifier_nondet(); | ||
verifier_assume!(__isnan(x) == 0); | ||
let c_res = unsafe { c_trunc(x) }; | ||
let rust_res = trunc(x); | ||
verifier_assert!(rust_res == c_res); | ||
} |
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
Oops, something went wrong.