authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-21 18:43:22+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-04-21 22:07:55+02:00
log6cd71931cb43c775864553b5a232709fbc771689
tree458fe83a10f6f40dc778ebf4144f618b8b19de3a
parentc8753aceef07161aa9b7d2eab75524042bcbc8bb

stage1: Unbreak build on FreeBSD

It turns out that the endianness-detection header delivered with the softfloat library is extremely brittle and gives wrong results when targeting FreeBSD (long story short, _BIG_ENDIAN is always defined there and that breaks the #if defined() chain). Use our own endianness detection header to work around any potential problem.

1 files changed, 25 insertions(+), 14 deletions(-)

src/stage1/softfloat_ext.cpp+25-14
......@@ -1,19 +1,21 @@
11#include "softfloat_ext.hpp"
2#include "zigendian.h"
23
34extern "C" {
4 #include "platform.h"
5 #include "internals.h"
65 #include "softfloat.h"
76}
87
98void f128M_abs(const float128_t *aPtr, float128_t *zPtr) {
10 float128_t zero_float;
11 ui32_to_f128M(0, &zero_float);
12 if (f128M_lt(aPtr, &zero_float)) {
13 f128M_sub(&zero_float, aPtr, zPtr);
14 } else {
15 *zPtr = *aPtr;
16 }
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
1719}
1820
1921void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {
......@@ -27,12 +29,21 @@ void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {
2729}
2830
2931float16_t f16_neg(const float16_t a) {
30 union ui16_f16 uZ;
31 uZ.ui = a.v ^ (UINT16_C(1) << 15);
32 return uZ.f;
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;
3336}
3437
3538void f128M_neg(const float128_t *aPtr, float128_t *zPtr) {
36 zPtr->v[indexWord(2,1)] = aPtr->v[indexWord(2,1)] ^ (UINT64_C(1) << 63);
37 zPtr->v[indexWord(2,0)] = aPtr->v[indexWord(2,0)];
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
3849}
\ No newline at end of file