Skip to content

Commit

Permalink
Float: Refactor the test data to avoid duplication
Browse files Browse the repository at this point in the history
* Add new file to hold all test data.
* Leverage the test data instead of hard code for testing.

Signed-off-by: Pan Li <[email protected]>
  • Loading branch information
Incarnation-p-lee authored and Alasdair committed Jun 27, 2024
1 parent af30f9c commit b81e282
Show file tree
Hide file tree
Showing 9 changed files with 611 additions and 404 deletions.
141 changes: 141 additions & 0 deletions test/float/data.sail
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*==========================================================================*/
/* Sail */
/* */
/* Copyright 2024 Intel Corporation */
/* Pan Li - [email protected] */
/* */
/* Redistribution and use in source and binary forms, with or without */
/* modification, are permitted provided that the following conditions are */
/* met: */
/* */
/* 1. Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* 2. Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the */
/* documentation and/or other materials provided with the distribution. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A */
/* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR */
/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/*==========================================================================*/

$ifndef _FLOAT_DATA
$define _FLOAT_DATA

/* Half floating point */
let fp16_pos_snan_0 = 0x7c01
let fp16_pos_snan_1 = 0x7d10
let fp16_neg_snan_0 = 0xfc01
let fp16_neg_snan_1 = 0xfd10

let fp16_pos_qnan_0 = 0x7e00
let fp16_pos_qnan_1 = 0x7e01
let fp16_neg_qnan_0 = 0xfe00
let fp16_neg_qnan_1 = 0xfe01

let fp16_pos_inf = 0x7c00
let fp16_neg_inf = 0xfc00

let fp16_pos_zero = 0x0000
let fp16_neg_zero = 0x8000

let fp16_pos_denormal_0 = 0x0200
let fp16_pos_denormal_1 = 0x02f0
let fp16_neg_denormal_0 = 0x8200
let fp16_neg_denormal_1 = 0x82f0

let fp16_pos_normal_0 = 0x7a00
let fp16_pos_normal_1 = 0x71ff
let fp16_neg_normal_0 = 0xfa00
let fp16_neg_normal_1 = 0xf1ff

/* Single floating point */
let fp32_pos_snan_0 = 0x7f800001
let fp32_pos_snan_1 = 0x7f8f0000
let fp32_neg_snan_0 = 0xff800001
let fp32_neg_snan_1 = 0xff8f0000

let fp32_pos_qnan_0 = 0x7fc00000
let fp32_pos_qnan_1 = 0x7fc00001
let fp32_neg_qnan_0 = 0xffc00000
let fp32_neg_qnan_1 = 0xffc00001

let fp32_pos_inf = 0x7f800000
let fp32_neg_inf = 0xff800000

let fp32_pos_zero = 0x00000000
let fp32_neg_zero = 0x80000000

let fp32_pos_denormal_0 = 0x00700000
let fp32_pos_denormal_1 = 0x0010ff01
let fp32_neg_denormal_0 = 0x80700000
let fp32_neg_denormal_1 = 0x8010ff01

let fp32_pos_normal_0 = 0x1a000000
let fp32_pos_normal_1 = 0x0100002f
let fp32_neg_normal_0 = 0x9a000000
let fp32_neg_normal_1 = 0x8100002f

/* Double floating point */
let fp64_pos_snan_0 = 0x7ff0000000000001
let fp64_pos_snan_1 = 0x7ff7000000000000
let fp64_neg_snan_0 = 0xfff0000000000001
let fp64_neg_snan_1 = 0xfff7000000000000

let fp64_pos_qnan_0 = 0x7ff8000000000000
let fp64_pos_qnan_1 = 0x7fff000000000000
let fp64_neg_qnan_0 = 0xfff8000000000000
let fp64_neg_qnan_1 = 0xffff000000000000

let fp64_pos_inf = 0x7ff0000000000000
let fp64_neg_inf = 0xfff0000000000000

let fp64_pos_zero = 0x0000000000000000
let fp64_neg_zero = 0x8000000000000000

let fp64_pos_denormal_0 = 0x000f000000000000
let fp64_pos_denormal_1 = 0x0000000fff000000
let fp64_neg_denormal_0 = 0x800f000000000000
let fp64_neg_denormal_1 = 0x8000000fff000000

let fp64_pos_normal_0 = 0x1000000000000000
let fp64_pos_normal_1 = 0x0100001111000000
let fp64_neg_normal_0 = 0x9000000000000000
let fp64_neg_normal_1 = 0x8100001111000000

/* Quad floating point */
let fp128_pos_snan_0 = 0x7fff0000000000000000000000000001
let fp128_pos_snan_1 = 0x7fff000000000000ff00000000000000
let fp128_neg_snan_0 = 0xffff0000000000000000000000000001
let fp128_neg_snan_1 = 0xffff000000000000ff00000000000000

let fp128_pos_qnan_0 = 0x7fff8000000000000000000000000001
let fp128_pos_qnan_1 = 0x7fff8d00000000000000000000000000
let fp128_neg_qnan_0 = 0xffff8000000000000000000000000001
let fp128_neg_qnan_1 = 0xffff8d00000000000000000000000000

let fp128_pos_inf = 0x7fff0000000000000000000000000000
let fp128_neg_inf = 0xffff0000000000000000000000000000

let fp128_pos_zero = 0x00000000000000000000000000000000
let fp128_neg_zero = 0x80000000000000000000000000000000

let fp128_pos_denormal_0 = 0x0000f000000000000000000000000000
let fp128_pos_denormal_1 = 0x0000000fff0000000000000000000000
let fp128_neg_denormal_0 = 0x8000f000000000000000000000000000
let fp128_neg_denormal_1 = 0x8000000fff0000000000000000000000

let fp128_pos_normal_0 = 0x10000000000000000000000000000000
let fp128_pos_normal_1 = 0x01000011110000000000000000000000
let fp128_neg_normal_0 = 0x90000000000000000000000000000000
let fp128_neg_normal_1 = 0x81000011110000000000000000000000

$endif
81 changes: 41 additions & 40 deletions test/float/eq_test.sail
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,64 @@ default Order dec
$include <prelude.sail>
$include <float/eq.sail>
$include "tuple_equality.sail"
$include "data.sail"

function test_float_is_eq () -> unit = {
/* Half floating point */
assert(float_is_eq((0x0001, 0x0001)) == (true, fp_eflag_none));
assert(float_is_eq((0x0700, 0x0700)) == (true, fp_eflag_none));
assert(float_is_eq((0x0000, 0x8000)) == (true, fp_eflag_none));
assert(float_is_eq((0x7c00, 0x7c00)) == (true, fp_eflag_none));
assert(float_is_eq((fp16_pos_denormal_0, fp16_pos_denormal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp16_neg_normal_0, fp16_neg_normal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp16_neg_inf, fp16_neg_inf)) == (true, fp_eflag_none));
assert(float_is_eq((fp16_pos_zero, fp16_neg_zero)) == (true, fp_eflag_none));

assert(float_is_eq((0x0001, 0x8001)) == (false, fp_eflag_none));
assert(float_is_eq((0x7c00, 0xfc00)) == (false, fp_eflag_none));
assert(float_is_eq((0x7e01, 0x7a01)) == (false, fp_eflag_none));
assert(float_is_eq((0x7ef1, 0x7ef1)) == (false, fp_eflag_none));
assert(float_is_eq((fp16_pos_denormal_0, fp16_neg_normal_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp16_pos_inf, fp16_neg_inf)) == (false, fp_eflag_none));
assert(float_is_eq((fp16_pos_qnan_0, fp16_neg_qnan_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp16_pos_qnan_0, fp16_pos_qnan_1)) == (false, fp_eflag_none));

assert(float_is_eq((0x7c01, 0x7e0f)) == (false, fp_eflag_invalid));
assert(float_is_eq((0xf021, 0x7c0f)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp16_pos_snan_0, fp16_pos_normal_0)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp16_pos_snan_1, fp16_neg_zero)) == (false, fp_eflag_invalid));

/* Single floating point */
assert(float_is_eq((0x00001000, 0x00001000)) == (true, fp_eflag_none));
assert(float_is_eq((0x80301000, 0x80301000)) == (true, fp_eflag_none));
assert(float_is_eq((0x00000000, 0x80000000)) == (true, fp_eflag_none));
assert(float_is_eq((0x7f800000, 0x7f800000)) == (true, fp_eflag_none));
assert(float_is_eq((fp32_pos_denormal_0, fp32_pos_denormal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp32_neg_normal_0, fp32_neg_normal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp32_neg_inf, fp32_neg_inf)) == (true, fp_eflag_none));
assert(float_is_eq((fp32_pos_zero, fp32_neg_zero)) == (true, fp_eflag_none));

assert(float_is_eq((0x00001000, 0x80001000)) == (false, fp_eflag_none));
assert(float_is_eq((0x7fc00000, 0x80301000)) == (false, fp_eflag_none));
assert(float_is_eq((0x7fc00001, 0x01234000)) == (false, fp_eflag_none));
assert(float_is_eq((0x7f800000, 0xff800000)) == (false, fp_eflag_none));
assert(float_is_eq((fp32_pos_denormal_0, fp32_neg_normal_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp32_pos_inf, fp32_neg_inf)) == (false, fp_eflag_none));
assert(float_is_eq((fp32_pos_qnan_0, fp32_neg_qnan_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp32_pos_qnan_0, fp32_pos_qnan_1)) == (false, fp_eflag_none));

assert(float_is_eq((0x7f800001, 0x01234000)) == (false, fp_eflag_invalid));
assert(float_is_eq((0x7c800000, 0xff80000f)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp32_pos_snan_0, fp32_pos_normal_0)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp32_pos_snan_1, fp32_neg_zero)) == (false, fp_eflag_invalid));

/* Double floating point */
assert(float_is_eq((0x0000000000000001, 0x0000000000000001)) == (true, fp_eflag_none));
assert(float_is_eq((0x0f0000000000000f, 0x0f0000000000000f)) == (true, fp_eflag_none));
assert(float_is_eq((0x8000000000000000, 0x0000000000000000)) == (true, fp_eflag_none));
assert(float_is_eq((0x7ff0000000000000, 0x7ff0000000000000)) == (true, fp_eflag_none));
assert(float_is_eq((fp64_pos_denormal_0, fp64_pos_denormal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp64_neg_normal_0, fp64_neg_normal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp64_neg_inf, fp64_neg_inf)) == (true, fp_eflag_none));
assert(float_is_eq((fp64_pos_zero, fp64_neg_zero)) == (true, fp_eflag_none));

assert(float_is_eq((0x0000000000000001, 0x8000000000000001)) == (false, fp_eflag_none));
assert(float_is_eq((0x0f0000000000000f, 0x3f0000000000000f)) == (false, fp_eflag_none));
assert(float_is_eq((0x7ff8000000000000, 0x0000234db0000000)) == (false, fp_eflag_none));
assert(float_is_eq((0x7ff8000000000000, 0xfff8000000000000)) == (false, fp_eflag_none));
assert(float_is_eq((fp64_pos_denormal_0, fp64_neg_normal_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp64_pos_inf, fp64_neg_inf)) == (false, fp_eflag_none));
assert(float_is_eq((fp64_pos_qnan_0, fp64_neg_qnan_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp64_pos_qnan_0, fp64_pos_qnan_1)) == (false, fp_eflag_none));

assert(float_is_eq((0x7ff7000000000000, 0x0000234db0000000)) == (false, fp_eflag_invalid));
assert(float_is_eq((0x7ff0000000000001, 0xfff0000003000001)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp64_pos_snan_0, fp64_pos_normal_0)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp64_pos_snan_1, fp64_neg_zero)) == (false, fp_eflag_invalid));

/* Quad floating point */
assert(float_is_eq((0x00000000000000000000000000000001, 0x00000000000000000000000000000001)) == (true, fp_eflag_none));
assert(float_is_eq((0x0f00000000000000000000000000000f, 0x0f00000000000000000000000000000f)) == (true, fp_eflag_none));
assert(float_is_eq((0x80000000000000000000000000000000, 0x00000000000000000000000000000000)) == (true, fp_eflag_none));
assert(float_is_eq((0x7fff0000000000000000000000000000, 0x7fff0000000000000000000000000000)) == (true, fp_eflag_none));
assert(float_is_eq((fp128_pos_denormal_0, fp128_pos_denormal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp128_neg_normal_0, fp128_neg_normal_0)) == (true, fp_eflag_none));
assert(float_is_eq((fp128_neg_inf, fp128_neg_inf)) == (true, fp_eflag_none));
assert(float_is_eq((fp128_pos_zero, fp128_neg_zero)) == (true, fp_eflag_none));

assert(float_is_eq((0x00000000000000000000000000000001, 0x80000000000000000000000000000001)) == (false, fp_eflag_none));
assert(float_is_eq((0x0f00000000000000000000000000000f, 0x3f00000000000000000000000000000f)) == (false, fp_eflag_none));
assert(float_is_eq((0x7fff8000000000000000000000000000, 0x0000234db00000000000000000000000)) == (false, fp_eflag_none));
assert(float_is_eq((0x7fff8000000000000000000000000000, 0xffff8000000000000000000000000000)) == (false, fp_eflag_none));
assert(float_is_eq((fp128_pos_denormal_0, fp128_neg_normal_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp128_pos_inf, fp128_neg_inf)) == (false, fp_eflag_none));
assert(float_is_eq((fp128_pos_qnan_0, fp128_neg_qnan_0)) == (false, fp_eflag_none));
assert(float_is_eq((fp128_pos_qnan_0, fp128_pos_qnan_1)) == (false, fp_eflag_none));

assert(float_is_eq((0x7fff7000000000000000000000000000, 0x0000234db00000000000000000000000)) == (false, fp_eflag_invalid));
assert(float_is_eq((0x7fff0000000000000000000000000001, 0xfff00000030000000000000000000001)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp128_pos_snan_0, fp128_pos_normal_0)) == (false, fp_eflag_invalid));
assert(float_is_eq((fp128_pos_snan_1, fp128_neg_zero)) == (false, fp_eflag_invalid));
}

function main () -> unit = {
Expand Down
65 changes: 33 additions & 32 deletions test/float/inf_test.sail
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,52 @@ default Order dec

$include <prelude.sail>
$include <float/inf.sail>
$include "data.sail"

function test_float_is_inf () -> unit = {
/* Half floating point */
assert(float_is_inf(0x7c00));
assert(float_is_inf(0xfc00));
assert(float_is_inf(fp16_pos_inf));
assert(float_is_inf(fp16_neg_inf));

assert(float_is_inf(0x7a00) == false);
assert(float_is_inf(0x7b00) == false);
assert(float_is_inf(0x7e00) == false);
assert(float_is_inf(0xca00) == false);
assert(float_is_inf(0xdb00) == false);
assert(float_is_inf(0xfe00) == false);
assert(float_is_inf(fp16_pos_snan_0) == false);
assert(float_is_inf(fp16_neg_qnan_0) == false);
assert(float_is_inf(fp16_pos_zero) == false);
assert(float_is_inf(fp16_neg_zero) == false);
assert(float_is_inf(fp16_pos_denormal_0) == false);
assert(float_is_inf(fp16_neg_normal_0) == false);

/* Single floating point */
assert(float_is_inf(0x7f800000));
assert(float_is_inf(0xff800000));
assert(float_is_inf(fp32_pos_inf));
assert(float_is_inf(fp32_neg_inf));

assert(float_is_inf(0x7fc00000) == false);
assert(float_is_inf(0x7f000001) == false);
assert(float_is_inf(0x7e800000) == false);
assert(float_is_inf(0xffc00000) == false);
assert(float_is_inf(0xff000001) == false);
assert(float_is_inf(0xfe800000) == false);
assert(float_is_inf(fp32_pos_snan_0) == false);
assert(float_is_inf(fp32_neg_qnan_0) == false);
assert(float_is_inf(fp32_pos_zero) == false);
assert(float_is_inf(fp32_neg_zero) == false);
assert(float_is_inf(fp32_pos_denormal_0) == false);
assert(float_is_inf(fp32_neg_normal_0) == false);

/* Double floating point */
assert(float_is_inf(0x7ff0000000000000));
assert(float_is_inf(0xfff0000000000000));
assert(float_is_inf(fp64_pos_inf));
assert(float_is_inf(fp64_neg_inf));

assert(float_is_inf(0x7ff8000000000000) == false);
assert(float_is_inf(0x7ff0000000000001) == false);
assert(float_is_inf(0x7fc0000000000000) == false);
assert(float_is_inf(0xfff8000000000000) == false);
assert(float_is_inf(0xfff0000000000001) == false);
assert(float_is_inf(0xffc0000000000000) == false);
assert(float_is_inf(fp64_pos_snan_0) == false);
assert(float_is_inf(fp64_neg_qnan_0) == false);
assert(float_is_inf(fp64_pos_zero) == false);
assert(float_is_inf(fp64_neg_zero) == false);
assert(float_is_inf(fp64_pos_denormal_0) == false);
assert(float_is_inf(fp64_neg_normal_0) == false);

/* Quad floating point */
assert(float_is_inf(0x7fff0000000000000000000000000000));
assert(float_is_inf(0xffff0000000000000000000000000000));
assert(float_is_inf(fp128_pos_inf));
assert(float_is_inf(fp128_neg_inf));

assert(float_is_inf(0x7fff8000000000000000000000000000) == false);
assert(float_is_inf(0x7fff0000000000000000000000000001) == false);
assert(float_is_inf(0x7ffc0000000000000000000000000000) == false);
assert(float_is_inf(0xffff8000000000000000000000000000) == false);
assert(float_is_inf(0xffff0000000000000000000000000001) == false);
assert(float_is_inf(0xfffc0000000000000000000000000000) == false);
assert(float_is_inf(fp128_pos_snan_0) == false);
assert(float_is_inf(fp128_neg_qnan_0) == false);
assert(float_is_inf(fp128_pos_zero) == false);
assert(float_is_inf(fp128_neg_zero) == false);
assert(float_is_inf(fp128_pos_denormal_0) == false);
assert(float_is_inf(fp128_neg_normal_0) == false);
}

function main () -> unit = {
Expand Down
Loading

0 comments on commit b81e282

Please sign in to comment.