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 @@...@@ -1,19 +1,21 @@
1#include "softfloat_ext.hpp"1#include "softfloat_ext.hpp"
2#include "zigendian.h"
23
3extern "C" {4extern "C" {
4 #include "platform.h"
5 #include "internals.h"
6 #include "softfloat.h"5 #include "softfloat.h"
7}6}
87
9void f128M_abs(const float128_t *aPtr, float128_t *zPtr) {8void f128M_abs(const float128_t *aPtr, float128_t *zPtr) {
10 float128_t zero_float;9 // Clear the sign bit.
11 ui32_to_f128M(0, &zero_float);10#if ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN
12 if (f128M_lt(aPtr, &zero_float)) {11 zPtr->v[1] = aPtr->v[1] & ~(UINT64_C(1) << 63);
13 f128M_sub(&zero_float, aPtr, zPtr);12 zPtr->v[0] = aPtr->v[0];
14 } else {13#elif ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN
15 *zPtr = *aPtr;14 zPtr->v[0] = aPtr->v[0] & ~(UINT64_C(1) << 63);
16 } 15 zPtr->v[1] = aPtr->v[1];
16#else
17#error Unsupported endian
18#endif
17}19}
1820
19void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {21void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {
...@@ -27,12 +29,21 @@ void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {...@@ -27,12 +29,21 @@ void f128M_trunc(const float128_t *aPtr, float128_t *zPtr) {
27}29}
2830
29float16_t f16_neg(const float16_t a) {31float16_t f16_neg(const float16_t a) {
30 union ui16_f16 uZ;32 union { uint16_t ui; float16_t f; } uA;
31 uZ.ui = a.v ^ (UINT16_C(1) << 15);33 // Toggle the sign bit.
32 return uZ.f;34 uA.ui = a.v ^ (UINT16_C(1) << 15);
35 return uA.f;
33}36}
3437
35void f128M_neg(const float128_t *aPtr, float128_t *zPtr) {38void f128M_neg(const float128_t *aPtr, float128_t *zPtr) {
36 zPtr->v[indexWord(2,1)] = aPtr->v[indexWord(2,1)] ^ (UINT64_C(1) << 63);39 // Toggle the sign bit.
37 zPtr->v[indexWord(2,0)] = aPtr->v[indexWord(2,0)];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
38}49}
\ No newline at end of file