Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
f16_mul.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "specialize.h"
#include "softfloat.h"
Include dependency graph for f16_mul.c:

Go to the source code of this file.

Functions

float16_t f16_mul (float16_t a, float16_t b)
 

Function Documentation

◆ f16_mul()

float16_t f16_mul ( float16_t a,
float16_t b )

Definition at line 44 of file f16_mul.c.

45{
46 union ui16_f16 uA;
47 uint_fast16_t uiA;
48 bool signA;
49 int_fast8_t expA;
50 uint_fast16_t sigA;
51 union ui16_f16 uB;
52 uint_fast16_t uiB;
53 bool signB;
54 int_fast8_t expB;
55 uint_fast16_t sigB;
56 bool signZ;
57 uint_fast16_t magBits;
58 struct exp8_sig16 normExpSig;
59 int_fast8_t expZ;
60 uint_fast32_t sig32Z;
61 uint_fast16_t sigZ, uiZ;
62 union ui16_f16 uZ;
63
64 /*------------------------------------------------------------------------
65 *------------------------------------------------------------------------*/
66 uA.f = a;
67 uiA = uA.ui;
68 signA = signF16UI( uiA );
69 expA = expF16UI( uiA );
70 sigA = fracF16UI( uiA );
71 uB.f = b;
72 uiB = uB.ui;
73 signB = signF16UI( uiB );
74 expB = expF16UI( uiB );
75 sigB = fracF16UI( uiB );
76 signZ = signA ^ signB;
77 /*------------------------------------------------------------------------
78 *------------------------------------------------------------------------*/
79 if ( expA == 0x1F ) {
80 if ( sigA || ((expB == 0x1F) && sigB) ) goto propagateNaN;
81 magBits = expB | sigB;
82 goto infArg;
83 }
84 if ( expB == 0x1F ) {
85 if ( sigB ) goto propagateNaN;
86 magBits = expA | sigA;
87 goto infArg;
88 }
89 /*------------------------------------------------------------------------
90 *------------------------------------------------------------------------*/
91 if ( ! expA ) {
92 if ( ! sigA ) goto zero;
93 normExpSig = softfloat_normSubnormalF16Sig( sigA );
94 expA = normExpSig.exp;
95 sigA = normExpSig.sig;
96 }
97 if ( ! expB ) {
98 if ( ! sigB ) goto zero;
99 normExpSig = softfloat_normSubnormalF16Sig( sigB );
100 expB = normExpSig.exp;
101 sigB = normExpSig.sig;
102 }
103 /*------------------------------------------------------------------------
104 *------------------------------------------------------------------------*/
105 expZ = expA + expB - 0xF;
106 sigA = (sigA | 0x0400)<<4;
107 sigB = (sigB | 0x0400)<<5;
108 sig32Z = (uint_fast32_t) sigA * sigB;
109 sigZ = sig32Z>>16;
110 if ( sig32Z & 0xFFFF ) sigZ |= 1;
111 if ( sigZ < 0x4000 ) {
112 --expZ;
113 sigZ <<= 1;
114 }
115 return softfloat_roundPackToF16( signZ, expZ, sigZ );
116 /*------------------------------------------------------------------------
117 *------------------------------------------------------------------------*/
118 propagateNaN:
119 uiZ = softfloat_propagateNaNF16UI( uiA, uiB );
120 goto uiZ;
121 /*------------------------------------------------------------------------
122 *------------------------------------------------------------------------*/
123 infArg:
124 if ( ! magBits ) {
126 uiZ = defaultNaNF16UI;
127 } else {
128 uiZ = packToF16UI( signZ, 0x1F, 0 );
129 }
130 goto uiZ;
131 /*------------------------------------------------------------------------
132 *------------------------------------------------------------------------*/
133 zero:
134 uiZ = packToF16UI( signZ, 0, 0 );
135 uiZ:
136 uZ.ui = uiZ;
137 return uZ.f;
138
139}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
uint_fast16_t softfloat_propagateNaNF16UI(uint_fast16_t uiA, uint_fast16_t uiB)
void softfloat_raiseFlags(uint_fast8_t flags)
#define defaultNaNF16UI
Definition specialize.h:88
#define expF16UI(a)
Definition internals.h:84
#define signF16UI(a)
Definition internals.h:83
float16_t softfloat_roundPackToF16(bool, int_fast16_t, uint_fast16_t)
#define fracF16UI(a)
Definition internals.h:85
struct exp8_sig16 softfloat_normSubnormalF16Sig(uint_fast16_t)
#define packToF16UI(sign, exp, sig)
Definition internals.h:86
@ softfloat_flag_invalid
Definition softfloat.h:89
uint16_t uint_fast16_t
Definition stdint.h:155
int8_t int_fast8_t
Definition stdint.h:150
uint32_t uint_fast32_t
Definition stdint.h:156
float16_t f
Definition internals.h:45
Here is the call graph for this function: