-
Notifications
You must be signed in to change notification settings - Fork 894
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also add fxx_neg helper functions Signed-off-by: Chih-Min Chao <[email protected]>
- Loading branch information
1 parent
1263fb5
commit ad9238f
Showing
15 changed files
with
604 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include "platform.h" | ||
#include "internals.h" | ||
#include "specialize.h" | ||
#include "softfloat.h" | ||
|
||
uint_fast16_t bf16_classify( bfloat16_t a ) | ||
{ | ||
union ui16_f16 uA; | ||
uint_fast16_t uiA; | ||
|
||
uA.f = a; | ||
uiA = uA.ui; | ||
|
||
uint_fast16_t infOrNaN = expBF16UI( uiA ) == 0xFF; | ||
uint_fast16_t subnormalOrZero = expBF16UI( uiA ) == 0; | ||
bool sign = signBF16UI( uiA ); | ||
bool fracZero = fracBF16UI( uiA ) == 0; | ||
bool isNaN = isNaNBF16UI( uiA ); | ||
bool isSNaN = softfloat_isSigNaNBF16UI( uiA ); | ||
|
||
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
/*============================================================================ | ||
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 <stdbool.h> | ||
#include <stdint.h> | ||
#include "platform.h" | ||
#include "internals.h" | ||
#include "softfloat.h" | ||
|
||
bool bf16_eq( bfloat16_t a, bfloat16_t b ) | ||
{ | ||
float32_t f32A = { (uint_fast32_t)a.v << 16 }; | ||
float32_t f32B = { (uint_fast32_t)b.v << 16 }; | ||
|
||
return f32_eq ( f32A, f32B ); | ||
} | ||
|
||
bool bf16_le( bfloat16_t a, bfloat16_t b ) | ||
{ | ||
float32_t f32A = { (uint_fast32_t)a.v << 16 }; | ||
float32_t f32B = { (uint_fast32_t)b.v << 16 }; | ||
|
||
return f32_le ( f32A, f32B ); | ||
} | ||
|
||
bool bf16_lt( bfloat16_t a, bfloat16_t b ) | ||
{ | ||
float32_t f32A = { (uint_fast32_t)a.v << 16 }; | ||
float32_t f32B = { (uint_fast32_t)b.v << 16 }; | ||
|
||
return f32_lt ( f32A, f32B ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
/*============================================================================ | ||
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 <stdbool.h> | ||
#include <stdint.h> | ||
#include "platform.h" | ||
#include "internals.h" | ||
#include "specialize.h" | ||
#include "softfloat.h" | ||
|
||
int_fast32_t bf16_to_i32( bfloat16_t a, uint_fast8_t roundingMode, bool exact ) | ||
{ | ||
return f32_to_i32(bf16_to_f32(a), roundingMode, exact); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
/*============================================================================ | ||
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 <stdint.h> | ||
#include "specialize.h" | ||
#include "softfloat.h" | ||
|
||
int_fast8_t bf16_to_i8( bfloat16_t a, uint_fast8_t roundingMode, bool exact ) | ||
{ | ||
uint_fast8_t old_flags = softfloat_exceptionFlags; | ||
|
||
int_fast32_t sig32 = bf16_to_i32(a, roundingMode, exact); | ||
|
||
if (sig32 > INT8_MAX) { | ||
softfloat_exceptionFlags = old_flags | softfloat_flag_invalid; | ||
return i8_fromPosOverflow; | ||
} else if (sig32 < INT8_MIN) { | ||
softfloat_exceptionFlags = old_flags | softfloat_flag_invalid; | ||
return i8_fromNegOverflow; | ||
} else { | ||
return sig32; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
/*============================================================================ | ||
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 <stdbool.h> | ||
#include <stdint.h> | ||
#include "platform.h" | ||
#include "internals.h" | ||
#include "specialize.h" | ||
#include "softfloat.h" | ||
|
||
uint_fast32_t bf16_to_ui32( float16_t a, uint_fast8_t roundingMode, bool exact ) | ||
{ | ||
return f32_to_ui32(bf16_to_f32(a), roundingMode, exact); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
/*============================================================================ | ||
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 <stdint.h> | ||
#include "specialize.h" | ||
#include "softfloat.h" | ||
|
||
uint_fast8_t bf16_to_ui8( bfloat16_t a, uint_fast8_t roundingMode, bool exact ) | ||
{ | ||
uint_fast8_t old_flags = softfloat_exceptionFlags; | ||
|
||
uint_fast32_t sig32 = bf16_to_ui32(a, roundingMode, exact); | ||
|
||
if (sig32 > UINT8_MAX) { | ||
softfloat_exceptionFlags = old_flags | softfloat_flag_invalid; | ||
return ui8_fromPosOverflow; | ||
} else { | ||
return sig32; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, 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 <stdio.h> | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#include "platform.h" | ||
#include "internals.h" | ||
#include "specialize.h" | ||
#include "softfloat.h" | ||
|
||
bool bf16_neg( bfloat16_t a ) | ||
{ | ||
return signBF16UI(a.v); | ||
} | ||
|
||
bool f16_neg( float16_t a ) | ||
{ | ||
return signF16UI(a.v); | ||
} | ||
|
||
bool f32_neg( float32_t a ) | ||
{ | ||
return signF32UI(a.v); | ||
} | ||
|
||
bool f64_neg( float64_t a ) | ||
{ | ||
return signF64UI(a.v); | ||
} |
Oops, something went wrong.