Skip to content

Commit 03ccb6c

Browse files
committed
Implement f8 comparsion functions
1 parent 63dfd34 commit 03ccb6c

File tree

6 files changed

+258
-0
lines changed

6 files changed

+258
-0
lines changed

softfloat/f8_eq.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*============================================================================
2+
3+
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
4+
Package, Release 3d, by John R. Hauser.
5+
6+
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
7+
California. All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions, and the following disclaimer.
14+
15+
2. Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions, and the following disclaimer in the documentation
17+
and/or other materials provided with the distribution.
18+
19+
3. Neither the name of the University nor the names of its contributors may
20+
be used to endorse or promote products derived from this software without
21+
specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
24+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
26+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
=============================================================================*/
35+
36+
#include <stdbool.h>
37+
#include <stdint.h>
38+
#include "platform.h"
39+
#include "internals.h"
40+
#include "softfloat.h"
41+
#include "specialize.h"
42+
43+
bool f8_eq( float8_t a, float8_t b )
44+
{
45+
union ui8_f8 uA;
46+
uint_fast8_t uiA;
47+
union ui8_f8 uB;
48+
uint_fast8_t uiB;
49+
50+
uA.f = a;
51+
uiA = uA.ui;
52+
uB.f = b;
53+
uiB = uB.ui;
54+
if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) {
55+
softfloat_raiseFlags( softfloat_flag_invalid );
56+
return false;
57+
}
58+
return (uiA == uiB);
59+
}

softfloat/f8_le.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*============================================================================
2+
3+
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
4+
Package, Release 3d, by John R. Hauser.
5+
6+
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
7+
California. All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions, and the following disclaimer.
14+
15+
2. Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions, and the following disclaimer in the documentation
17+
and/or other materials provided with the distribution.
18+
19+
3. Neither the name of the University nor the names of its contributors may
20+
be used to endorse or promote products derived from this software without
21+
specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
24+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
26+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
=============================================================================*/
35+
36+
#include <stdbool.h>
37+
#include <stdint.h>
38+
#include "platform.h"
39+
#include "internals.h"
40+
#include "softfloat.h"
41+
#include "specialize.h"
42+
43+
bool f8_le( float8_t a, float8_t b )
44+
{
45+
union ui8_f8 uA;
46+
uint_fast8_t uiA;
47+
union ui8_f8 uB;
48+
uint_fast8_t uiB;
49+
bool signA, signB;
50+
51+
uA.f = a;
52+
uiA = uA.ui;
53+
uB.f = b;
54+
uiB = uB.ui;
55+
if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) {
56+
softfloat_raiseFlags( softfloat_flag_invalid );
57+
return false;
58+
}
59+
signA = signF8UI( uiA );
60+
signB = signF8UI( uiB );
61+
return
62+
(signA != signB) ? signA
63+
: (uiA == uiB) || (signA ^ (uiA < uiB));
64+
}

softfloat/f8_lt.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*============================================================================
2+
3+
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
4+
Package, Release 3d, by John R. Hauser.
5+
6+
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
7+
California. All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions, and the following disclaimer.
14+
15+
2. Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions, and the following disclaimer in the documentation
17+
and/or other materials provided with the distribution.
18+
19+
3. Neither the name of the University nor the names of its contributors may
20+
be used to endorse or promote products derived from this software without
21+
specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
24+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
26+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
=============================================================================*/
35+
36+
#include <stdbool.h>
37+
#include <stdint.h>
38+
#include "platform.h"
39+
#include "internals.h"
40+
#include "softfloat.h"
41+
#include "specialize.h"
42+
43+
bool f8_lt( float8_t a, float8_t b )
44+
{
45+
union ui8_f8 uA;
46+
uint_fast8_t uiA;
47+
union ui8_f8 uB;
48+
uint_fast8_t uiB;
49+
bool signA, signB;
50+
51+
uA.f = a;
52+
uiA = uA.ui;
53+
uB.f = b;
54+
uiB = uB.ui;
55+
if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) {
56+
softfloat_raiseFlags( softfloat_flag_invalid );
57+
return false;
58+
}
59+
signA = signF8UI( uiA );
60+
signB = signF8UI( uiB );
61+
return
62+
(signA != signB) ? signA
63+
: (uiA != uiB) && (signA ^ (uiA < uiB));
64+
}

softfloat/f8_lt_quiet.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*============================================================================
2+
3+
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
4+
Package, Release 3d, by John R. Hauser.
5+
6+
Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
7+
California. All rights reserved.
8+
9+
Redistribution and use in source and binary forms, with or without
10+
modification, are permitted provided that the following conditions are met:
11+
12+
1. Redistributions of source code must retain the above copyright notice,
13+
this list of conditions, and the following disclaimer.
14+
15+
2. Redistributions in binary form must reproduce the above copyright notice,
16+
this list of conditions, and the following disclaimer in the documentation
17+
and/or other materials provided with the distribution.
18+
19+
3. Neither the name of the University nor the names of its contributors may
20+
be used to endorse or promote products derived from this software without
21+
specific prior written permission.
22+
23+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
24+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
26+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
27+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+
34+
=============================================================================*/
35+
36+
#include <stdbool.h>
37+
#include <stdint.h>
38+
#include "platform.h"
39+
#include "internals.h"
40+
#include "softfloat.h"
41+
#include "specialize.h"
42+
43+
bool f8_lt_quiet( float8_t a, float8_t b )
44+
{
45+
union ui8_f8 uA;
46+
uint_fast8_t uiA;
47+
union ui8_f8 uB;
48+
uint_fast8_t uiB;
49+
bool signA, signB;
50+
51+
uA.f = a;
52+
uiA = uA.ui;
53+
uB.f = b;
54+
uiB = uB.ui;
55+
if ( isNaNF8UI( uiA ) || isNaNF8UI( uiB ) ) {
56+
return false;
57+
}
58+
signA = signF8UI( uiA );
59+
signB = signF8UI( uiB );
60+
return
61+
(signA != signB) ? signA
62+
: (uiA != uiB) && (signA ^ (uiA < uiB));
63+
}

softfloat/softfloat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ void i64_to_f128M( int64_t, float128_t * );
146146
/*----------------------------------------------------------------------------
147147
| 8-bit (half-precision) floating-point operations.
148148
*----------------------------------------------------------------------------*/
149+
bool f8_lt( float8_t, float8_t );
150+
bool f8_lt_quiet( float8_t, float8_t );
151+
bool f8_le( float8_t, float8_t );
152+
bool f8_eq( float8_t, float8_t );
149153
float8_t f8_mul( float8_t, float8_t );
150154
float8_t f8_div( float8_t, float8_t );
151155
float8_t f8_rsqrte7( float8_t );

softfloat/softfloat.mk.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ softfloat_c_srcs = \
4848
f16_lt_quiet.c \
4949
f16_mulAdd.c \
5050
f16_mul.c \
51+
f8_le.c \
52+
f8_lt.c \
53+
f8_lt_quiet.c \
54+
f8_eq.c \
5155
f8_classify.c \
5256
f8_add.c \
5357
f8_sub.c \

0 commit comments

Comments
 (0)