Skip to content
Permalink
Browse files

float literals now parse using musl's 128 bit float code

fixes float literals not having 128 bit precision
  • Loading branch information...
andrewrk committed Mar 22, 2019
1 parent 127bb12 commit 4615ed5ea003516c8235728ac3f5f0ee2ccea8a7
Showing with 1,090 additions and 25 deletions.
  1. +9 −7 CMakeLists.txt
  2. +4 −7 src/bigfloat.cpp
  3. +1 −1 src/bigfloat.hpp
  4. +1,038 −0 src/parse_f128.c
  5. +23 −0 src/parse_f128.h
  6. +2 −2 src/tokenizer.cpp
  7. +2 −2 test/compile_errors.zig
  8. +4 −4 test/stage1/behavior/eval.zig
  9. +7 −2 test/stage1/behavior/math.zig
@@ -313,6 +313,7 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f32_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/f64_to_f16.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/i32_to_f128M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_add256M.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addCarryM.c"
"${CMAKE_SOURCE_DIR}/deps/SoftFloat-3e/source/s_addComplCarryM.c"
@@ -427,11 +428,12 @@ set(ZIG_SOURCES
"${CMAKE_SOURCE_DIR}/src/range_set.cpp"
"${CMAKE_SOURCE_DIR}/src/target.cpp"
"${CMAKE_SOURCE_DIR}/src/tokenizer.cpp"
"${CMAKE_SOURCE_DIR}/src/util.cpp"
"${CMAKE_SOURCE_DIR}/src/translate_c.cpp"
"${CMAKE_SOURCE_DIR}/src/util.cpp"
)
set(BLAKE_SOURCES
set(OPTIMIZED_C_SOURCES
"${CMAKE_SOURCE_DIR}/src/blake2b.c"
"${CMAKE_SOURCE_DIR}/src/parse_f128.c"
)
set(ZIG_CPP_SOURCES
"${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
@@ -6600,7 +6602,7 @@ else()
endif()
endif()

set(BLAKE_CFLAGS "-std=c99")
set(OPTIMIZED_C_FLAGS "-std=c99 -O3")

set(EXE_LDFLAGS " ")
if(MINGW)
@@ -6626,9 +6628,9 @@ set_target_properties(zig_cpp PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
)

add_library(embedded_blake STATIC ${BLAKE_SOURCES})
set_target_properties(embedded_blake PROPERTIES
COMPILE_FLAGS "${BLAKE_CFLAGS} -O3"
add_library(opt_c_util STATIC ${OPTIMIZED_C_SOURCES})
set_target_properties(opt_c_util PROPERTIES
COMPILE_FLAGS "${OPTIMIZED_C_FLAGS}"
)

add_executable(zig ${ZIG_SOURCES})
@@ -6639,7 +6641,7 @@ set_target_properties(zig PROPERTIES

target_link_libraries(zig LINK_PUBLIC
zig_cpp
embedded_blake
opt_c_util
${SOFTFLOAT_LIBRARIES}
${CLANG_LIBRARIES}
${LLD_LIBRARIES}
@@ -9,6 +9,7 @@
#include "bigint.hpp"
#include "buffer.hpp"
#include "softfloat.hpp"
#include "parse_f128.h"
#include <stdio.h>
#include <math.h>
#include <errno.h>
@@ -65,22 +66,18 @@ void bigfloat_init_bigint(BigFloat *dest, const BigInt *op) {
}
}

int bigfloat_init_buf_base10(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len) {
Error bigfloat_init_buf(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len) {
char *str_begin = (char *)buf_ptr;
char *str_end;

errno = 0;
double value = strtod(str_begin, &str_end); // TODO actual f128 parsing
dest->value = parse_f128(str_begin, &str_end);
if (errno) {
return ErrorOverflow;
}

float64_t value_f64;
memcpy(&value_f64, &value, sizeof(double));
f64_to_f128M(value_f64, &dest->value);

assert(str_end <= ((char*)buf_ptr) + buf_len);
return 0;
return ErrorNone;
}

void bigfloat_add(BigFloat *dest, const BigFloat *op1, const BigFloat *op2) {
@@ -28,7 +28,7 @@ void bigfloat_init_64(BigFloat *dest, double x);
void bigfloat_init_128(BigFloat *dest, float128_t x);
void bigfloat_init_bigfloat(BigFloat *dest, const BigFloat *x);
void bigfloat_init_bigint(BigFloat *dest, const BigInt *op);
int bigfloat_init_buf_base10(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len);
Error bigfloat_init_buf(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len);

float16_t bigfloat_to_f16(const BigFloat *bigfloat);
float bigfloat_to_f32(const BigFloat *bigfloat);

0 comments on commit 4615ed5

Please sign in to comment.
You can’t perform that action at this time.