Skip to content

Commit b96f984

Browse files
committed
Use softfloat f80 for x87 fpu
This fixes several long-standing issues with x87 float emulation, in particular: - 80 bit precision floats, fixing Haiku after its switch to musl libc (hrev53728) - the precision bit in the x87 control word - fucom and fucomi (unordered comparisons) - aliasing of x87 and mmx registers - rounding during conversion to integers Operations that are not implemented in softfloat were implemented by converting to f64 (sine, pow, ln, etc.) and thus operate with lower precision. Softfloat has been combined into a single file using a script [0] and checked into the repository. [0] https://github.com/facebook/zstd/blob/57df21e2eb2e95053f63304f8f9b9bbf9ab7e3db/contrib/single_file_libs/combine.sh
1 parent 1d22abd commit b96f984

File tree

16 files changed

+33343
-670
lines changed

16 files changed

+33343
-670
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ CARGO_FLAGS=\
7171
-- \
7272
-C linker=tools/rust-lld-wrapper \
7373
-C link-args="--import-table --global-base=262144 $(STRIP_DEBUG_FLAG)" \
74+
-C link-args="build/softfloat.o" \
7475
--verbose
7576

7677
CORE_FILES=const.js config.js io.js main.js lib.js ide.js pci.js floppy.js \
@@ -154,20 +155,26 @@ src/rust/gen/analyzer.rs: $(ANALYZER_DEPENDENCIES)
154155
src/rust/gen/analyzer0f.rs: $(ANALYZER_DEPENDENCIES)
155156
./gen/generate_analyzer.js --output-dir build/ --table analyzer0f
156157

157-
build/v86.wasm: $(RUST_FILES) Cargo.toml
158+
build/v86.wasm: $(RUST_FILES) build/softfloat.o Cargo.toml
158159
mkdir -p build/
159160
-ls -lh build/v86.wasm
160161
cargo +nightly rustc --release $(CARGO_FLAGS)
161162
mv build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm
162163
ls -lh build/v86.wasm
163164

164-
build/v86-debug.wasm: $(RUST_FILES) Cargo.toml
165+
build/v86-debug.wasm: $(RUST_FILES) build/softfloat.o Cargo.toml
165166
mkdir -p build/
166167
-ls -lh build/v86-debug.wasm
167168
cargo +nightly rustc $(CARGO_FLAGS)
168169
mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm
169170
ls -lh build/v86-debug.wasm
170171

172+
build/softfloat.o: lib/softfloat/softfloat.c
173+
clang -c \
174+
--target=wasm32 -Os -flto -nostdlib -fvisibility=hidden -ffunction-sections -fdata-sections \
175+
-DSOFTFLOAT_FAST_INT64 -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32 \
176+
-O2 -o build/softfloat.o lib/softfloat/softfloat.c
177+
171178
clean:
172179
-rm build/libv86.js
173180
-rm build/libv86-debug.js
@@ -177,6 +184,7 @@ clean:
177184
-rm $(INSTRUCTION_TABLES)
178185
-rm build/*.map
179186
-rm build/*.wast
187+
-rm build/*.o
180188
$(MAKE) -C $(NASM_TEST_DIR) clean
181189

182190
run:

0 commit comments

Comments
 (0)