Skip to content

Commit 863cca1

Browse files
committed
Implement f8_to_(u)i16 in softfloat
1 parent 4fc27fb commit 863cca1

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

softfloat/f8_to_i16.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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, 2016, 2017 The Regents of the
7+
University of 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 "specialize.h"
41+
#include "softfloat.h"
42+
43+
int_fast16_t f8_to_i16( float8_t a, uint_fast8_t roundingMode, bool exact )
44+
{
45+
return f16_to_i16(f8_to_f16(a), roundingMode, exact);
46+
}

softfloat/f8_to_ui16.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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, 2016, 2017 The Regents of the
7+
University of 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 "specialize.h"
41+
#include "softfloat.h"
42+
43+
uint_fast16_t f8_to_ui16( float8_t a, uint_fast8_t roundingMode, bool exact )
44+
{
45+
return f16_to_ui16(f8_to_f16(a), roundingMode, exact);
46+
}

softfloat/softfloat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ float8_t f8_rsqrte7( float8_t );
149149
float8_t f8_recip7( float8_t );
150150
float8_t f8_sqrt( float8_t );
151151
float16_t f8_to_f16( float8_t );
152+
int_fast16_t f8_to_i16( float8_t, uint_fast8_t, bool );
153+
uint_fast16_t f8_to_ui16( float8_t, uint_fast8_t, bool );
152154
float8_t f8_sub( float8_t, float8_t );
153155
float8_t f8_add( float8_t, float8_t );
154156
float8_t f8_mulAdd( float8_t, float8_t , float8_t );

softfloat/softfloat.mk.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ softfloat_c_srcs = \
6262
f16_to_f8.c \
6363
f16_to_f128.c \
6464
f8_to_f16.c \
65+
f8_to_i16.c \
66+
f8_to_ui16.c \
6567
f16_to_f32.c \
6668
f16_to_f64.c \
6769
f16_to_i8.c \

0 commit comments

Comments
 (0)