Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
f128_to_f16.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 f128_to_f16.c:

Go to the source code of this file.

Functions

float16_t f128_to_f16 (float128_t a)
 

Function Documentation

◆ f128_to_f16()

float16_t f128_to_f16 ( float128_t a)

Definition at line 44 of file f128_to_f16.c.

45{
46 union ui128_f128 uA;
47 uint_fast64_t uiA64, uiA0;
48 bool sign;
49 int_fast32_t exp;
50 uint_fast64_t frac64;
51 struct commonNaN commonNaN;
52 uint_fast16_t uiZ, frac16;
53 union ui16_f16 uZ;
54
55 /*------------------------------------------------------------------------
56 *------------------------------------------------------------------------*/
57 uA.f = a;
58 uiA64 = uA.ui.v64;
59 uiA0 = uA.ui.v0;
60 sign = signF128UI64( uiA64 );
61 exp = expF128UI64( uiA64 );
62 frac64 = fracF128UI64( uiA64 ) | (uiA0 != 0);
63 /*------------------------------------------------------------------------
64 *------------------------------------------------------------------------*/
65 if ( exp == 0x7FFF ) {
66 if ( frac64 ) {
69 } else {
70 uiZ = packToF16UI( sign, 0x1F, 0 );
71 }
72 goto uiZ;
73 }
74 /*------------------------------------------------------------------------
75 *------------------------------------------------------------------------*/
76 frac16 = softfloat_shortShiftRightJam64( frac64, 34 );
77 if ( ! (exp | frac16) ) {
78 uiZ = packToF16UI( sign, 0, 0 );
79 goto uiZ;
80 }
81 /*------------------------------------------------------------------------
82 *------------------------------------------------------------------------*/
83 exp -= 0x3FF1;
84 if ( sizeof (int_fast16_t) < sizeof (int_fast32_t) ) {
85 if ( exp < -0x40 ) exp = -0x40;
86 }
87 return softfloat_roundPackToF16( sign, exp, frac16 | 0x4000 );
88 /*------------------------------------------------------------------------
89 *------------------------------------------------------------------------*/
90 uiZ:
91 uZ.ui = uiZ;
92 return uZ.f;
93
94}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
void softfloat_f128UIToCommonNaN(uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr)
#define softfloat_commonNaNToF16UI(aPtr)
Definition specialize.h:102
float16_t softfloat_roundPackToF16(bool, int_fast16_t, uint_fast16_t)
#define packToF16UI(sign, exp, sig)
Definition internals.h:86
uint64_t softfloat_shortShiftRightJam64(uint64_t a, uint_fast8_t dist)
uint16_t uint_fast16_t
Definition stdint.h:155
uint64_t uint_fast64_t
Definition stdint.h:157
int32_t int_fast32_t
Definition stdint.h:152
int16_t int_fast16_t
Definition stdint.h:151
float16_t f
Definition internals.h:45
Here is the call graph for this function: