diff --git a/lib/float/interface.sail b/lib/float/interface.sail index 7edff5087..198d9c38f 100644 --- a/lib/float/interface.sail +++ b/lib/float/interface.sail @@ -37,5 +37,6 @@ $include $include $include $include +$include $endif diff --git a/lib/float/ne.sail b/lib/float/ne.sail new file mode 100644 index 000000000..db65890c5 --- /dev/null +++ b/lib/float/ne.sail @@ -0,0 +1,51 @@ +/*==========================================================================*/ +/* Sail */ +/* */ +/* Copyright 2024 Intel Corporation */ +/* Pan Li - pan2.li@intel.com */ +/* */ +/* 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_NE +$define _FLOAT_NE + +$include +$include +$include + +val float_is_ne : fp_bits_x2 -> fp_bool_and_flags +function float_is_ne ((op_0, op_1)) = { + let is_snan = float_is_snan (op_0) | float_is_snan (op_1); + let flags = if is_snan + then fp_eflag_invalid + else fp_eflag_none; + + let is_nan = float_is_nan (op_0) | float_is_nan (op_1); + let is_zero = float_is_zero (op_0) & float_is_zero (op_1); + let is_ne = is_nan == false & (op_0 != op_1) & is_zero == false; + + (is_ne, flags); +} + +$endif diff --git a/src/bin/dune b/src/bin/dune index 7fc0a2554..86f641111 100644 --- a/src/bin/dune +++ b/src/bin/dune @@ -159,6 +159,7 @@ (%{workspace_root}/lib/float/zero.sail as lib/float/zero.sail) (%{workspace_root}/lib/float/normal.sail as lib/float/normal.sail) (%{workspace_root}/lib/float/eq.sail as lib/float/eq.sail) + (%{workspace_root}/lib/float/ne.sail as lib/float/ne.sail) (%{workspace_root}/lib/float/interface.sail as lib/float/interface.sail) (%{workspace_root}/lib/reverse_endianness.sail as diff --git a/test/float/ne_test.sail b/test/float/ne_test.sail new file mode 100644 index 000000000..a712bc0bb --- /dev/null +++ b/test/float/ne_test.sail @@ -0,0 +1,82 @@ +/*==========================================================================*/ +/* Sail */ +/* */ +/* Copyright 2024 Intel Corporation */ +/* Pan Li - pan2.li@intel.com */ +/* */ +/* 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. */ +/*==========================================================================*/ + +default Order dec + +$include +$include +$include "tuple_equality.sail" + +function test_float_is_ne () -> unit = { + /* Half floating point */ + assert(float_is_ne((0x0001, 0x0011)) == (true, fp_eflag_none)); + assert(float_is_ne((0x0701, 0x0700)) == (true, fp_eflag_none)); + assert(float_is_ne((0x0000, 0x0001)) == (true, fp_eflag_none)); + assert(float_is_ne((0x7c00, 0xfc00)) == (true, fp_eflag_none)); + + assert(float_is_ne((0x0001, 0x0001)) == (false, fp_eflag_none)); + assert(float_is_ne((0x7c00, 0x7c00)) == (false, fp_eflag_none)); + assert(float_is_ne((0x0000, 0x8000)) == (false, fp_eflag_none)); + assert(float_is_ne((0x7ef1, 0x7ef1)) == (false, fp_eflag_none)); + + assert(float_is_ne((0x7c01, 0x7e0f)) == (false, fp_eflag_invalid)); + assert(float_is_ne((0xf021, 0x7c0f)) == (false, fp_eflag_invalid)); + + /* Single floating point */ + assert(float_is_ne((0x00001000, 0x80001000)) == (true, fp_eflag_none)); + assert(float_is_ne((0x80300000, 0x80301000)) == (true, fp_eflag_none)); + assert(float_is_ne((0x00000001, 0x80000000)) == (true, fp_eflag_none)); + assert(float_is_ne((0x7f800000, 0xff800000)) == (true, fp_eflag_none)); + + assert(float_is_ne((0x00001000, 0x00001000)) == (false, fp_eflag_none)); + assert(float_is_ne((0x80301000, 0x80301000)) == (false, fp_eflag_none)); + assert(float_is_ne((0x00000000, 0x80000000)) == (false, fp_eflag_none)); + assert(float_is_ne((0x7fc00000, 0x7fc00000)) == (false, fp_eflag_none)); + + assert(float_is_ne((0x7f800001, 0x01234000)) == (false, fp_eflag_invalid)); + assert(float_is_ne((0x7c800000, 0xff80000f)) == (false, fp_eflag_invalid)); + + /* Double floating point */ + assert(float_is_ne((0x8000000000000001, 0x0000000000000001)) == (true, fp_eflag_none)); + assert(float_is_ne((0x8f0000000000000f, 0x0f0000000000000f)) == (true, fp_eflag_none)); + assert(float_is_ne((0x8000000000000000, 0x0000000000000001)) == (true, fp_eflag_none)); + assert(float_is_ne((0x7ff0000000000000, 0xfff0000000000000)) == (true, fp_eflag_none)); + + assert(float_is_ne((0x0000000000000011, 0x0000000000000011)) == (false, fp_eflag_none)); + assert(float_is_ne((0x0fff00000000000f, 0x0fff00000000000f)) == (false, fp_eflag_none)); + assert(float_is_ne((0x0000000000000000, 0x8000000000000000)) == (false, fp_eflag_none)); + assert(float_is_ne((0x7ff8000000000100, 0x7ff8000000000100)) == (false, fp_eflag_none)); + + assert(float_is_ne((0x7ff7000000000000, 0x0000234db0000000)) == (false, fp_eflag_invalid)); + assert(float_is_ne((0x7ff0000000000001, 0xfff0000003000001)) == (false, fp_eflag_invalid)); +} + +function main () -> unit = { + test_float_is_ne(); +}