1 #include "softfloat_ext.hpp"
2 #include "zigendian.h"
3 
4 extern "C" {
5     #include "softfloat.h"
6 }
7 
f128M_abs(const float128_t * aPtr,float128_t * zPtr)8 void f128M_abs(const float128_t *aPtr, float128_t *zPtr) {
9     // Clear the sign bit.
10 #if ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN
11     zPtr->v[1] = aPtr->v[1] & ~(UINT64_C(1) << 63);
12     zPtr->v[0] = aPtr->v[0];
13 #elif ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN
14     zPtr->v[0] = aPtr->v[0] & ~(UINT64_C(1) << 63);
15     zPtr->v[1] = aPtr->v[1];
16 #else
17 #error Unsupported endian
18 #endif
19 }
20 
f128M_trunc(const float128_t * aPtr,float128_t * zPtr)21 void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {
22     float128_t zero_float;
23     ui32_to_f128M(0, &zero_float);
24     if (f128M_lt(aPtr, &zero_float)) {
25         f128M_roundToInt(aPtr, softfloat_round_max, false, zPtr);
26     } else {
27         f128M_roundToInt(aPtr, softfloat_round_min, false, zPtr);
28     }
29 }
30 
f16_neg(const float16_t a)31 float16_t f16_neg(const float16_t a) {
32     union { uint16_t ui; float16_t f; } uA;
33     // Toggle the sign bit.
34     uA.ui = a.v ^ (UINT16_C(1) << 15);
35     return uA.f;
36 }
37 
f128M_neg(const float128_t * aPtr,float128_t * zPtr)38 void f128M_neg(const float128_t *aPtr, float128_t *zPtr) {
39     // Toggle the sign bit.
40 #if ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN
41     zPtr->v[1] = aPtr->v[1] ^ (UINT64_C(1) << 63);
42     zPtr->v[0] = aPtr->v[0];
43 #elif ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN
44     zPtr->v[0] = aPtr->v[0] ^ (UINT64_C(1) << 63);
45     zPtr->v[1] = aPtr->v[1];
46 #else
47 #error Unsupported endian
48 #endif
49 }