Skip to content

Commit 4fc27fb

Browse files
committed
Implement f8_madd instruction in softfloat
1 parent aedb49c commit 4fc27fb

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

softfloat/f8_emulation.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4040
#include "specialize.h"
4141
#include "softfloat.h"
4242

43+
float8_t f8_emulation_3_operands(float8_t a8, float8_t b8, float8_t c8, float16_t (*operation)(float16_t, float16_t, float16_t)) {
44+
uint_fast8_t roundingMode = softfloat_roundingMode;
45+
softfloat_roundingMode = softfloat_round_odd;
46+
float16_t a16 = f8_to_f16(a8);
47+
float16_t b16 = f8_to_f16(b8);
48+
float16_t c16 = f8_to_f16(c8);
49+
float16_t z16 = operation(a16, b16, c16);
50+
softfloat_roundingMode = roundingMode;
51+
float8_t z = f16_to_f8(z16);
52+
return z;
53+
}
54+
4355
float8_t f8_emulation_2_operands(float8_t a8, float8_t b8, float16_t (*operation)(float16_t, float16_t)) {
4456
uint_fast8_t roundingMode = softfloat_roundingMode;
4557
softfloat_roundingMode = softfloat_round_odd;

softfloat/f8_mulAdd.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 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 "specialize.h"
41+
#include "softfloat.h"
42+
43+
float8_t f8_mulAdd( float8_t a, float8_t b, float8_t c )
44+
{
45+
return f8_emulation_3_operands(a, b, c, f16_mulAdd);
46+
}

softfloat/softfloat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ float8_t f8_sqrt( float8_t );
151151
float16_t f8_to_f16( float8_t );
152152
float8_t f8_sub( float8_t, float8_t );
153153
float8_t f8_add( float8_t, float8_t );
154+
float8_t f8_mulAdd( float8_t, float8_t , float8_t );
154155

156+
float8_t f8_emulation_3_operands(float8_t a8, float8_t b8, float8_t c8, float16_t (*operation)(float16_t, float16_t, float16_t));
155157
float8_t f8_emulation_2_operands(float8_t a8, float8_t b8, float16_t (*operation)(float16_t, float16_t));
156158
float8_t f8_emulation_1_operand(float8_t a8, float16_t (*operation)(float16_t));
157159

softfloat/softfloat.mk.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ softfloat_c_srcs = \
5151
f8_add.c \
5252
f8_sub.c \
5353
f8_mul.c \
54+
f8_mulAdd.c \
5455
f8_div.c \
5556
f8_sqrt.c \
5657
f8_emulation.c \

0 commit comments

Comments
 (0)