diff --git a/softfloat/f16_to_f8.c b/softfloat/f16_to_f8.c new file mode 100644 index 0000000000..0b2a594e71 --- /dev/null +++ b/softfloat/f16_to_f8.c @@ -0,0 +1,104 @@ + +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f16_to_f8( float16_t a ) +{ + union ui16_f16 uA; + uint_fast16_t uiA; + bool sign; + int_fast8_t exp; + uint_fast16_t frac; + struct commonNaN commonNaN; + uint_fast8_t uiZ; + uint_fast16_t frac8; + union ui8_f8 uZ; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + uA.f = a; + uiA = uA.ui; + sign = signF16UI( uiA ); + exp = expF16UI( uiA ); + frac = fracF16UI( uiA ); + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( exp == 0xFF ) { + if ( frac ) { + softfloat_f16UIToCommonNaN( uiA, &commonNaN ); + switch ( softfloat_fp8Mode ) { + case softfloat_fp8_e4m3: + uiZ = softfloat_commonNaNToE4M3F8UI( &commonNaN ); + case softfloat_fp8_e5m2: + uiZ = softfloat_commonNaNToE5M2F8UI( &commonNaN ); + default: + uiZ = softfloat_commonNaNToF8UI( &commonNaN ); + } + } else { + switch ( softfloat_fp8Mode ) { + case softfloat_fp8_e4m3: + // Assuming overflow mode (Inf --> NaN) + uiZ = softfloat_commonNaNToE4M3F8UI( &commonNaN ); + case softfloat_fp8_e5m2: + uiZ = signInfE5M2F8UI( sign ); + default: + uiZ = signInfF8UI( sign ); + } + } + goto uiZ; + } + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + frac8 = frac>>2 | ((frac & 0x3) != 0); // Round and preserve sticky bit + if ( ! (exp | frac8) ) { + uiZ = packToF8UI( 0, 0, 0 ); // zero + goto uiZ; + } + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + return softfloat_roundPackToF8( sign, exp - 0xC, frac8 | 0x100 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f8_add.c b/softfloat/f8_add.c new file mode 100644 index 0000000000..c233e4ce4e --- /dev/null +++ b/softfloat/f8_add.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_add( float8_t a, float8_t b ) +{ + return f8_emulation_2_operands(a, b, f16_add); +} diff --git a/softfloat/f8_classify.c b/softfloat/f8_classify.c new file mode 100755 index 0000000000..15fa279879 --- /dev/null +++ b/softfloat/f8_classify.c @@ -0,0 +1,34 @@ +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +uint_fast16_t f8_classify( float8_t a ) +{ + union ui8_f8 uA; + uint_fast16_t uiA; + + uA.f = a; + uiA = uA.ui; + + uint_fast16_t infOrNaN = isInfF8UI(uiA) || isNaNF8UI(uiA); + uint_fast16_t subnormalOrZero = expF8UI( uiA ) == 0; + bool sign = signF8UI( uiA ); + bool fracZero = fracF8UI( uiA ) == 0; + bool isNaN = isNaNF8UI( uiA ); + bool isSNaN = false; + + return + ( sign && infOrNaN && fracZero ) << 0 | + ( sign && !infOrNaN && !subnormalOrZero ) << 1 | + ( sign && subnormalOrZero && !fracZero ) << 2 | + ( sign && subnormalOrZero && fracZero ) << 3 | + ( !sign && infOrNaN && fracZero ) << 7 | + ( !sign && !infOrNaN && !subnormalOrZero ) << 6 | + ( !sign && subnormalOrZero && !fracZero ) << 5 | + ( !sign && subnormalOrZero && fracZero ) << 4 | + ( isNaN && isSNaN ) << 8 | + ( isNaN && !isSNaN ) << 9; +} diff --git a/softfloat/f8_div.c b/softfloat/f8_div.c new file mode 100644 index 0000000000..222c6c3cfc --- /dev/null +++ b/softfloat/f8_div.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_div( float8_t a, float8_t b ) +{ + return f8_emulation_2_operands(a, b, f16_div); +} diff --git a/softfloat/f8_emulation.c b/softfloat/f8_emulation.c new file mode 100644 index 0000000000..4e9e0278ac --- /dev/null +++ b/softfloat/f8_emulation.c @@ -0,0 +1,74 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_emulation_3_operands(float8_t a8, float8_t b8, float8_t c8, float16_t (*operation)(float16_t, float16_t, float16_t)) { + uint_fast8_t roundingMode = softfloat_roundingMode; + softfloat_roundingMode = softfloat_round_odd; + float16_t a16 = f8_to_f16(a8); + float16_t b16 = f8_to_f16(b8); + float16_t c16 = f8_to_f16(c8); + float16_t z16 = operation(a16, b16, c16); + softfloat_roundingMode = roundingMode; + float8_t z = f16_to_f8(z16); + return z; +} + +float8_t f8_emulation_2_operands(float8_t a8, float8_t b8, float16_t (*operation)(float16_t, float16_t)) { + uint_fast8_t roundingMode = softfloat_roundingMode; + softfloat_roundingMode = softfloat_round_odd; + float16_t a16 = f8_to_f16(a8); + float16_t b16 = f8_to_f16(b8); + float16_t z16 = operation(a16, b16); + softfloat_roundingMode = roundingMode; + float8_t z = f16_to_f8(z16); + return z; +} + +float8_t f8_emulation_1_operand(float8_t a8, float16_t (*operation)(float16_t)) { + uint_fast8_t roundingMode = softfloat_roundingMode; + softfloat_roundingMode = softfloat_round_odd; + float16_t a16 = f8_to_f16(a8); + float16_t z16 = operation(a16); + softfloat_roundingMode = roundingMode; + float8_t z = f16_to_f8(z16); + return z; +} diff --git a/softfloat/f8_eq.c b/softfloat/f8_eq.c new file mode 100644 index 0000000000..512d12b232 --- /dev/null +++ b/softfloat/f8_eq.c @@ -0,0 +1,59 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" +#include "specialize.h" + +bool f8_eq( float8_t a, float8_t b ) +{ + union ui8_f8 uA; + uint_fast8_t uiA; + union ui8_f8 uB; + uint_fast8_t uiB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + return (uiA == uiB); +} diff --git a/softfloat/f8_le.c b/softfloat/f8_le.c new file mode 100644 index 0000000000..b15773d749 --- /dev/null +++ b/softfloat/f8_le.c @@ -0,0 +1,64 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" +#include "specialize.h" + +bool f8_le( float8_t a, float8_t b ) +{ + union ui8_f8 uA; + uint_fast8_t uiA; + union ui8_f8 uB; + uint_fast8_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + signA = signF8UI( uiA ); + signB = signF8UI( uiB ); + return + (signA != signB) ? signA + : (uiA == uiB) || (signA ^ (uiA < uiB)); +} diff --git a/softfloat/f8_lt.c b/softfloat/f8_lt.c new file mode 100644 index 0000000000..724673f12a --- /dev/null +++ b/softfloat/f8_lt.c @@ -0,0 +1,64 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" +#include "specialize.h" + +bool f8_lt( float8_t a, float8_t b ) +{ + union ui8_f8 uA; + uint_fast8_t uiA; + union ui8_f8 uB; + uint_fast8_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) { + softfloat_raiseFlags( softfloat_flag_invalid ); + return false; + } + signA = signF8UI( uiA ); + signB = signF8UI( uiB ); + return + (signA != signB) ? signA + : (uiA != uiB) && (signA ^ (uiA < uiB)); +} diff --git a/softfloat/f8_lt_quiet.c b/softfloat/f8_lt_quiet.c new file mode 100644 index 0000000000..af103625e0 --- /dev/null +++ b/softfloat/f8_lt_quiet.c @@ -0,0 +1,63 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" +#include "specialize.h" + +bool f8_lt_quiet( float8_t a, float8_t b ) +{ + union ui8_f8 uA; + uint_fast8_t uiA; + union ui8_f8 uB; + uint_fast8_t uiB; + bool signA, signB; + + uA.f = a; + uiA = uA.ui; + uB.f = b; + uiB = uB.ui; + if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) { + return false; + } + signA = signF8UI( uiA ); + signB = signF8UI( uiB ); + return + (signA != signB) ? signA + : (uiA != uiB) && (signA ^ (uiA < uiB)); +} diff --git a/softfloat/f8_mul.c b/softfloat/f8_mul.c new file mode 100644 index 0000000000..62eb229c1f --- /dev/null +++ b/softfloat/f8_mul.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_mul( float8_t a, float8_t b ) +{ + return f8_emulation_2_operands(a, b, f16_mul); +} diff --git a/softfloat/f8_mulAdd.c b/softfloat/f8_mulAdd.c new file mode 100644 index 0000000000..55d268b9f6 --- /dev/null +++ b/softfloat/f8_mulAdd.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_mulAdd( float8_t a, float8_t b, float8_t c ) +{ + return f8_emulation_3_operands(a, b, c, f16_mulAdd); +} diff --git a/softfloat/f8_sqrt.c b/softfloat/f8_sqrt.c new file mode 100644 index 0000000000..b3fc0c2730 --- /dev/null +++ b/softfloat/f8_sqrt.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_sqrt( float8_t a ) +{ + return f8_emulation_1_operand(a, f16_sqrt); +} diff --git a/softfloat/f8_sub.c b/softfloat/f8_sub.c new file mode 100644 index 0000000000..62fe199546 --- /dev/null +++ b/softfloat/f8_sub.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float8_t f8_sub( float8_t a, float8_t b ) +{ + return f8_emulation_2_operands(a, b, f16_sub); +} diff --git a/softfloat/f8_to_f16.c b/softfloat/f8_to_f16.c new file mode 100644 index 0000000000..47b5881850 --- /dev/null +++ b/softfloat/f8_to_f16.c @@ -0,0 +1,110 @@ + +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +float16_t f8_to_f16( float8_t a ) +{ + union ui8_f8 uA; + uint_fast8_t uiA; + bool sign; + int_fast8_t exp; + uint_fast8_t frac; + uint_fast16_t uiZ; + struct exp8_sig8 normExpSig; + union ui16_f16 uZ; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + uA.f = a; + uiA = uA.ui; + + sign = signF8UI( uiA ); + exp = expF8UI( uiA ); + frac = fracF8UI( uiA ); + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + switch ( softfloat_fp8Mode ) { + case softfloat_fp8_e4m3: + // No Infinity in E4M3 mode. + if ( isE4M3NaNF8UI( uiA ) ) { + uiZ = defaultNaNF16UI; + goto uiZ; + } + case softfloat_fp8_e5m2: + if ( isE5M2NaNF8UI( uiA ) ) { + uiZ = defaultNaNF16UI; + goto uiZ; + } + if ( isE5M2InfF8UI( uiA ) ) { + uiZ = packToF16UI( sign, 0x1F, 0 ); + goto uiZ; + } + default: + if ( isNaNF8UI(uiA) ) { + uiZ = defaultNaNF16UI; + goto uiZ; + } + if ( isInfF8UI(uiA) ) { + uiZ = packToF16UI( sign, 0x1F, 0 ); + goto uiZ; + } + } + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( ! exp ) { + if ( ! frac ) { + uiZ = packToF16UI( 0, 0, 0 ); + goto uiZ; + } + normExpSig = softfloat_normSubnormalF8Sig( frac ); + exp = normExpSig.exp - 1; + frac = normExpSig.sig; + } + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + uiZ = packToF16UI( sign, exp + 0xB, (uint_fast16_t) frac<<6 ); + uiZ: + uZ.ui = uiZ; + return uZ.f; + +} + diff --git a/softfloat/f8_to_i16.c b/softfloat/f8_to_i16.c new file mode 100644 index 0000000000..111bbf0016 --- /dev/null +++ b/softfloat/f8_to_i16.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +int_fast16_t f8_to_i16( float8_t a, uint_fast8_t roundingMode, bool exact ) +{ + return f16_to_i16(f8_to_f16(a), roundingMode, exact); +} diff --git a/softfloat/f8_to_i8.c b/softfloat/f8_to_i8.c new file mode 100644 index 0000000000..7761a5cf36 --- /dev/null +++ b/softfloat/f8_to_i8.c @@ -0,0 +1,55 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include "specialize.h" +#include "softfloat.h" + +int_fast8_t f8_to_i8( float8_t a, uint_fast8_t roundingMode, bool exact ) +{ + uint_fast8_t old_flags = softfloat_exceptionFlags; + + int_fast16_t sig16 = f8_to_i16(a, roundingMode, exact); + + if (sig16 > INT8_MAX) { + softfloat_exceptionFlags = old_flags | softfloat_flag_invalid; + return i8_fromPosOverflow; + } else if (sig16 < INT8_MIN) { + softfloat_exceptionFlags = old_flags | softfloat_flag_invalid; + return i8_fromNegOverflow; + } else { + return sig16; + } +} diff --git a/softfloat/f8_to_ui16.c b/softfloat/f8_to_ui16.c new file mode 100644 index 0000000000..b35b4ec4c1 --- /dev/null +++ b/softfloat/f8_to_ui16.c @@ -0,0 +1,46 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "specialize.h" +#include "softfloat.h" + +uint_fast16_t f8_to_ui16( float8_t a, uint_fast8_t roundingMode, bool exact ) +{ + return f16_to_ui16(f8_to_f16(a), roundingMode, exact); +} diff --git a/softfloat/f8_to_ui8.c b/softfloat/f8_to_ui8.c new file mode 100644 index 0000000000..dbc905620f --- /dev/null +++ b/softfloat/f8_to_ui8.c @@ -0,0 +1,52 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 The Regents of the +University of California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include "specialize.h" +#include "softfloat.h" + +uint_fast8_t f8_to_ui8( float8_t a, uint_fast8_t roundingMode, bool exact ) +{ + uint_fast8_t old_flags = softfloat_exceptionFlags; + + uint_fast16_t sig16 = f8_to_ui16(a, roundingMode, exact); + + if (sig16 > UINT8_MAX) { + softfloat_exceptionFlags = old_flags | softfloat_flag_invalid; + return ui8_fromPosOverflow; + } else { + return sig16; + } +} diff --git a/softfloat/fall_maxmin.c b/softfloat/fall_maxmin.c index 32a9ade59e..e487ab41a7 100644 --- a/softfloat/fall_maxmin.c +++ b/softfloat/fall_maxmin.c @@ -72,10 +72,12 @@ float ## bits ## _t f ## bits ## _min( float ## bits ## _t a, float ## bits ## _ } \ } +COMPARE_MAX(a, b, 8); COMPARE_MAX(a, b, 16); COMPARE_MAX(a, b, 32); COMPARE_MAX(a, b, 64); +COMPARE_MIN(a, b, 8); COMPARE_MIN(a, b, 16); COMPARE_MIN(a, b, 32); COMPARE_MIN(a, b, 64); diff --git a/softfloat/fall_reciprocal.c b/softfloat/fall_reciprocal.c index 1c96458935..cfd6f13a36 100644 --- a/softfloat/fall_reciprocal.c +++ b/softfloat/fall_reciprocal.c @@ -93,6 +93,11 @@ static inline uint64_t rsqrte7(uint64_t val, int e, int s, bool sub) { return (sign << (s+e)) | (out_exp << s) | out_sig; } +float8_t f8_rsqrte7(float8_t in) +{ + return f8_emulation_1_operand(in, f16_rsqrte7); +} + float16_t f16_rsqrte7(float16_t in) { union ui16_f16 uA; @@ -262,6 +267,11 @@ static inline uint64_t recip7(uint64_t val, int e, int s, int rm, bool sub, return (sign << (s+e)) | (out_exp << s) | out_sig; } +float8_t f8_recip7(float8_t in) +{ + return f8_emulation_1_operand(in, f16_recip7); +} + float16_t f16_recip7(float16_t in) { union ui16_f16 uA; diff --git a/softfloat/i32_to_f8.c b/softfloat/i32_to_f8.c new file mode 100644 index 0000000000..227148f39a --- /dev/null +++ b/softfloat/i32_to_f8.c @@ -0,0 +1,49 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014 The Regents of the University of California. +All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float8_t i32_to_f8( int32_t a ) +{ + bool sign; + uint_fast32_t absA; + sign = (a < 0); + absA = sign ? -(uint_fast32_t) a : (uint_fast32_t) a; + return sign_ui32_to_f8(absA, sign); +} diff --git a/softfloat/internals.h b/softfloat/internals.h index ae94427f07..042539a4a2 100644 --- a/softfloat/internals.h +++ b/softfloat/internals.h @@ -46,6 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. extern "C" { #endif +union ui8_f8 { uint8_t ui; float8_t f; }; union ui16_f16 { uint16_t ui; float16_t f; }; union ui32_f32 { uint32_t ui; float32_t f; }; union ui64_f64 { uint64_t ui; float64_t f; }; @@ -82,8 +83,25 @@ int_fast64_t int_fast64_t softfloat_roundMToI64( bool, uint32_t *, uint_fast8_t, bool ); #endif +/*---------------------------------------------------------------------------- +*---------------------------------------------------------------------------*/ +#define f8ExpWidth softfloat_fp8ExpWidths[softfloat_fp8Mode] +#define isE4M3NaNF8UI( a ) ((bool) ((((uint8_t) a) & 0x7F) == 0x7F)) +#define isE5M2NaNF8UI( a ) ((bool) ((((uint8_t) a) & 0x7C) > 0x7C)) +#define isE5M2InfF8UI( a ) ((bool) ((((uint8_t) a) & 0x7C) == 0x7C)) +#define signInfE5M2F8UI( sign ) (((uint8_t) (sign)<<7) | 0x7C) + /*---------------------------------------------------------------------------- *----------------------------------------------------------------------------*/ +#define isNaNF8UI( a ) ((bool) (((uint8_t) a) == defaultNaNF8UI)) +#define isInfF8UI( a ) ((bool) ((((uint8_t) a) & 0x7F) == 0x7F)) +#define signF8UI( a ) ((bool) ((uint16_t) (a)>>7)) +#define expF8UI( a ) ((int_fast8_t) ((a)>>(7-f8ExpWidth)) & ((0x1<>15)) #define expF16UI( a ) ((int_fast8_t) ((a)>>10) & 0x1F) #define fracF16UI( a ) ((a) & 0x03FF) @@ -96,9 +114,14 @@ int_fast64_t softfloat_roundMToI64( bool, uint32_t *, uint_fast8_t, bool ); #define isNaNF16UI( a ) (((~(a) & 0x7C00) == 0) && ((a) & 0x03FF)) +struct exp8_sig8 { int_fast8_t exp; uint_fast8_t sig; }; +struct exp8_sig8 softfloat_normSubnormalF8Sig( uint_fast8_t ); + struct exp8_sig16 { int_fast8_t exp; uint_fast16_t sig; }; struct exp8_sig16 softfloat_normSubnormalF16Sig( uint_fast16_t ); +float8_t softfloat_roundPackToF8( bool, int_fast8_t, uint_fast16_t ); + float16_t softfloat_roundPackToF16( bool, int_fast16_t, uint_fast16_t ); float16_t softfloat_normRoundPackToF16( bool, int_fast16_t, uint_fast16_t ); diff --git a/softfloat/s_normSubnormalF8Sig.c b/softfloat/s_normSubnormalF8Sig.c new file mode 100644 index 0000000000..9fc28239ee --- /dev/null +++ b/softfloat/s_normSubnormalF8Sig.c @@ -0,0 +1,51 @@ + +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of +California. All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include "platform.h" +#include "internals.h" + +struct exp8_sig8 softfloat_normSubnormalF8Sig( uint_fast8_t sig ) +{ + int_fast8_t shiftDist; + struct exp8_sig8 z; + + shiftDist = softfloat_countLeadingZeros8[sig] - 3; + z.exp = 1 - shiftDist; + z.sig = sig< +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float8_t + softfloat_roundPackToF8( bool sign, int_fast8_t exp, uint_fast16_t sig ) +{ + uint_fast8_t roundingMode; + bool roundNearEven; + uint_fast8_t roundIncrement, roundBits; + bool isTiny; + uint_fast8_t uiZ; + union ui8_f8 uZ; + + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + roundingMode = softfloat_roundingMode; + roundNearEven = (roundingMode == softfloat_round_near_even); + roundIncrement = 0x8; // How much to add to round, in this case 0x4 since we only need to round if gaurd bit it set + if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) { + roundIncrement = + (roundingMode + == (sign ? softfloat_round_min : softfloat_round_max)) + ? 0xF // Always round up + : 0; // Always round down + } + roundBits = sig & 0xF; + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + if ( exp < 0 ) { + isTiny = + (softfloat_detectTininess == softfloat_tininess_beforeRounding) + || (exp < -1)// If exp == -2 rounding doesn't matter, will be tiny regardless + || (sig + roundIncrement < 0x200); // make rounding won't increment exp + sig = softfloat_shiftRightJam32( sig, -exp ); // shift right and update sticky bit + exp = 0; // Set exponent to 0 for subnormal + roundBits = sig & 0xF; // GRS + if ( isTiny && roundBits ) { + softfloat_raiseFlags( softfloat_flag_underflow ); + } + /*---------------------------------------------------------------- + *----------------------------------------------------------------*/ + } else if ( (0x7 < exp) // Already too large + || ((0x200 <= sig + roundIncrement) && exp == 0x7)) { // At max exp but round up + softfloat_raiseFlags( + softfloat_flag_overflow | softfloat_flag_inexact ); + uiZ = signInfF8UI(sign) - ! roundIncrement; // TODO: confused + goto uiZ; + } + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + sig = (sig + roundIncrement)>>4; // Round and delete GSR bits + if ( roundBits ) { + softfloat_exceptionFlags |= softfloat_flag_inexact; +#ifdef SOFTFLOAT_ROUND_ODD + if ( roundingMode == softfloat_round_odd ) { + sig |= 1; + goto packReturn; + } +#endif + } + sig &= ~(uint_fast16_t) (! (roundBits ^ 8) & roundNearEven); + if ( ! sig ) { + exp = 0; + sign = 0; // Encode as zero + } + /*------------------------------------------------------------------------ + *------------------------------------------------------------------------*/ + packReturn: + uiZ = packToF8UI( sign, exp, (uint_fast8_t) sig); + uiZ: + uZ.ui = uiZ; + return uZ.f; +} diff --git a/softfloat/sign_ui32_to_f8.c b/softfloat/sign_ui32_to_f8.c new file mode 100644 index 0000000000..4a35f9dd31 --- /dev/null +++ b/softfloat/sign_ui32_to_f8.c @@ -0,0 +1,63 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014 The Regents of the University of California. +All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float8_t sign_ui32_to_f8( uint32_t absA, bool sign ) +{ + union ui8_f8 uZ; + uint_fast8_t leading_zeros; + uint_fast8_t shift_amnt; + uint_fast8_t exp; + + if ( ! absA ) { + uZ.ui = 0; + return uZ.f; + } + if (absA >= 0x10) { + softfloat_raiseFlags(softfloat_flag_overflow | softfloat_flag_inexact ); + uZ.ui = signInfF8UI(sign); + return uZ.f; + } + leading_zeros = softfloat_countLeadingZeros8[absA]; + exp = 11 - leading_zeros; + shift_amnt = 5 - leading_zeros; + uZ.ui = packToF8UI( sign, 0x7, (absA << shift_amnt) & 0xF ); + return uZ.f; +} diff --git a/softfloat/softfloat.h b/softfloat/softfloat.h index 81d63f3c60..d6dd0e350b 100644 --- a/softfloat/softfloat.h +++ b/softfloat/softfloat.h @@ -69,6 +69,20 @@ enum { softfloat_tininess_afterRounding = 1 }; +/*---------------------------------------------------------------------------- +| Software floating-point 8-bit mode. +*----------------------------------------------------------------------------*/ +extern THREAD_LOCAL uint_fast8_t softfloat_fp8Mode; +enum { + softfloat_fp8_8p5 = 0, + softfloat_fp8_8p4 = 1, + softfloat_fp8_8p3 = 2, + softfloat_fp8_e4m3 = 3, + softfloat_fp8_e5m2 = 4 +}; + +extern THREAD_LOCAL uint_fast8_t softfloat_fp8ExpWidths[5]; + /*---------------------------------------------------------------------------- | Software floating-point rounding mode. (Mode "odd" is supported only if | SoftFloat is compiled with macro 'SOFTFLOAT_ROUND_ODD' defined.) @@ -103,6 +117,8 @@ void softfloat_raiseFlags( uint_fast8_t ); /*---------------------------------------------------------------------------- | Integer-to-floating-point conversion routines. *----------------------------------------------------------------------------*/ +float8_t sign_ui32_to_f8( uint32_t, bool ); +float8_t ui32_to_f8( uint32_t ); float16_t ui32_to_f16( uint32_t ); float32_t ui32_to_f32( uint32_t ); float64_t ui32_to_f64( uint32_t ); @@ -121,6 +137,7 @@ float128_t ui64_to_f128( uint64_t ); #endif void ui64_to_extF80M( uint64_t, extFloat80_t * ); void ui64_to_f128M( uint64_t, float128_t * ); +float8_t i32_to_f8( int32_t ); float16_t i32_to_f16( int32_t ); float32_t i32_to_f32( int32_t ); float64_t i32_to_f64( int32_t ); @@ -140,6 +157,34 @@ float128_t i64_to_f128( int64_t ); void i64_to_extF80M( int64_t, extFloat80_t * ); void i64_to_f128M( int64_t, float128_t * ); +/*---------------------------------------------------------------------------- +| 8-bit (half-precision) floating-point operations. +*----------------------------------------------------------------------------*/ +bool f8_lt( float8_t, float8_t ); +bool f8_lt_quiet( float8_t, float8_t ); +bool f8_le( float8_t, float8_t ); +bool f8_eq( float8_t, float8_t ); +float8_t f8_mul( float8_t, float8_t ); +float8_t f8_div( float8_t, float8_t ); +float8_t f8_rsqrte7( float8_t ); +float8_t f8_recip7( float8_t ); +float8_t f8_sqrt( float8_t ); +float16_t f8_to_f16( float8_t ); +int_fast8_t f8_to_i8( float8_t, uint_fast8_t, bool ); +uint_fast8_t f8_to_ui8( float8_t, uint_fast8_t, bool ); +int_fast16_t f8_to_i16( float8_t, uint_fast8_t, bool ); +uint_fast16_t f8_to_ui16( float8_t, uint_fast8_t, bool ); +float8_t f8_sub( float8_t, float8_t ); +float8_t f8_add( float8_t, float8_t ); +float8_t f8_mulAdd( float8_t, float8_t , float8_t ); +uint_fast16_t f8_classify( float8_t ); +float8_t f8_max( float8_t, float8_t ); +float8_t f8_min( float8_t, float8_t ); + +float8_t f8_emulation_3_operands(float8_t a8, float8_t b8, float8_t c8, float16_t (*operation)(float16_t, float16_t, float16_t)); +float8_t f8_emulation_2_operands(float8_t a8, float8_t b8, float16_t (*operation)(float16_t, float16_t)); +float8_t f8_emulation_1_operand(float8_t a8, float16_t (*operation)(float16_t)); + /*---------------------------------------------------------------------------- | 16-bit (half-precision) floating-point operations. *----------------------------------------------------------------------------*/ @@ -155,6 +200,7 @@ uint_fast32_t f16_to_ui32_r_minMag( float16_t, bool ); uint_fast64_t f16_to_ui64_r_minMag( float16_t, bool ); int_fast32_t f16_to_i32_r_minMag( float16_t, bool ); int_fast64_t f16_to_i64_r_minMag( float16_t, bool ); +float8_t f16_to_f8( float16_t ); float32_t f16_to_f32( float16_t ); float64_t f16_to_f64( float16_t ); #ifdef SOFTFLOAT_FAST_INT64 diff --git a/softfloat/softfloat.mk.in b/softfloat/softfloat.mk.in index e6e3998e2b..7a49657e5c 100644 --- a/softfloat/softfloat.mk.in +++ b/softfloat/softfloat.mk.in @@ -48,11 +48,29 @@ softfloat_c_srcs = \ f16_lt_quiet.c \ f16_mulAdd.c \ f16_mul.c \ + f8_le.c \ + f8_lt.c \ + f8_lt_quiet.c \ + f8_eq.c \ + f8_classify.c \ + f8_add.c \ + f8_sub.c \ + f8_mul.c \ + f8_mulAdd.c \ + f8_div.c \ + f8_sqrt.c \ + f8_emulation.c \ f16_rem.c \ f16_roundToInt.c \ f16_sqrt.c \ f16_sub.c \ + f16_to_f8.c \ f16_to_f128.c \ + f8_to_i8.c \ + f8_to_ui8.c \ + f8_to_f16.c \ + f8_to_i16.c \ + f8_to_ui16.c \ f16_to_f32.c \ f16_to_f64.c \ f16_to_i8.c \ @@ -127,6 +145,7 @@ softfloat_c_srcs = \ f64_to_ui64_r_minMag.c \ fall_maxmin.c \ fall_reciprocal.c \ + i32_to_f8.c \ i32_to_f128.c \ i32_to_f16.c \ i32_to_f32.c \ @@ -173,10 +192,12 @@ softfloat_c_srcs = \ s_mulAddF64.c \ s_negXM.c \ s_normRoundPackToF128.c \ + s_roundPackToF8.c \ s_normRoundPackToF16.c \ s_normRoundPackToF32.c \ s_normRoundPackToF64.c \ s_normSubnormalF128Sig.c \ + s_normSubnormalF8Sig.c \ s_normSubnormalF16Sig.c \ s_normSubnormalF32Sig.c \ s_normSubnormalF64Sig.c \ @@ -227,6 +248,8 @@ softfloat_c_srcs = \ s_subMagsF32.c \ s_subMagsF64.c \ s_subM.c \ + sign_ui32_to_f8.c \ + ui32_to_f8.c \ ui32_to_f128.c \ ui32_to_f16.c \ ui32_to_f32.c \ diff --git a/softfloat/softfloat_state.c b/softfloat/softfloat_state.c index a105e6f647..73f24b09d8 100644 --- a/softfloat/softfloat_state.c +++ b/softfloat/softfloat_state.c @@ -44,6 +44,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define THREAD_LOCAL #endif +THREAD_LOCAL uint_fast8_t softfloat_fp8Mode = softfloat_fp8_8p5; +THREAD_LOCAL uint_fast8_t softfloat_fp8ExpWidths[5] = {3, 4, 5, 4, 5}; THREAD_LOCAL uint_fast8_t softfloat_roundingMode = softfloat_round_near_even; THREAD_LOCAL uint_fast8_t softfloat_detectTininess = init_detectTininess; THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags = 0; diff --git a/softfloat/softfloat_types.h b/softfloat/softfloat_types.h index 34c518f438..f2bf3d09d1 100644 --- a/softfloat/softfloat_types.h +++ b/softfloat/softfloat_types.h @@ -47,6 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | the types below may, if desired, be defined as aliases for the native types | (typically 'float' and 'double', and possibly 'long double'). *----------------------------------------------------------------------------*/ +typedef struct { uint8_t v; } float8_t; typedef struct { uint16_t v; } float16_t; typedef float16_t bfloat16_t; typedef struct { uint32_t v; } float32_t; diff --git a/softfloat/specialize.h b/softfloat/specialize.h index fb3761d7c7..0b6510e358 100644 --- a/softfloat/specialize.h +++ b/softfloat/specialize.h @@ -93,6 +93,11 @@ extern "C" { *----------------------------------------------------------------------------*/ struct commonNaN { char _unused; }; +/*---------------------------------------------------------------------------- +| The bit pattern for a default generated 8-bit floating-point NaN. +*----------------------------------------------------------------------------*/ +#define defaultNaNF8UI 0x80 + /*---------------------------------------------------------------------------- | The bit pattern for a default generated 16-bit floating-point NaN. *----------------------------------------------------------------------------*/ @@ -103,6 +108,14 @@ struct commonNaN { char _unused; }; *----------------------------------------------------------------------------*/ #define defaultNaNBF16UI 0x7FC0 +/*---------------------------------------------------------------------------- +| Converts the common NaN pointed to by `aPtr' into a 8-bit floating-point +| NaN, and returns the bit pattern of this value as an unsigned integer. +*----------------------------------------------------------------------------*/ +#define softfloat_commonNaNToF8UI( aPtr ) ((uint_fast8_t) defaultNaNF8UI) +#define softfloat_commonNaNToE4M3F8UI( aPtr ) ((uint_fast8_t) 0xFF) +#define softfloat_commonNaNToE5M2F8UI( aPtr ) ((uint_fast8_t) 0XFF) + /*---------------------------------------------------------------------------- | Returns true when 16-bit unsigned integer `uiA' has the bit pattern of a | 16-bit floating-point signaling NaN. diff --git a/softfloat/ui32_to_f8.c b/softfloat/ui32_to_f8.c new file mode 100644 index 0000000000..2e0a3bd9c6 --- /dev/null +++ b/softfloat/ui32_to_f8.c @@ -0,0 +1,45 @@ +/*============================================================================ + +This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic +Package, Release 3d, by John R. Hauser. + +Copyright 2011, 2012, 2013, 2014 The Regents of the University of California. +All rights reserved. + +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. + + 3. Neither the name of the University nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + +=============================================================================*/ + +#include +#include +#include "platform.h" +#include "internals.h" +#include "softfloat.h" + +float8_t ui32_to_f8( uint32_t a ) +{ + return sign_ui32_to_f8( a, false); +}