Commit graph

182 commits

Author SHA1 Message Date
Fabian 6352bfe3ed Multi-page wasm modules 2020-12-31 19:14:32 -06:00
Fabian 9f54954cb5 Delete some code 2020-12-31 19:14:32 -06:00
Fabian f2759f72d2 Move mem8 to memory.rs 2020-12-31 19:14:32 -06:00
Fabian 8c7413d896 Remove profiler_instrument cargo flag (merged into profiler) 2020-12-31 19:14:32 -06:00
Fabian b96f984963 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] 57df21e2eb/contrib/single_file_libs/combine.sh
2020-12-31 19:14:32 -06:00
Fabian 7be85004c6 Remove tlb_data from global pointers 2020-12-31 19:14:32 -06:00
Fabian 6a18618e76 jit cmpxchg8b 2020-12-31 19:14:32 -06:00
Fabian 9b79278bb9 Much simpler implementation of jit cache 2020-12-31 19:14:32 -06:00
Fabian 51b09ade51 jit clc/stc (F8/F9) 2020-12-31 19:14:32 -06:00
Fabian d93308f7d8 Remove code duplication (global pointers) 2020-12-31 19:14:32 -06:00
Fabian 56272ca397 s/cpu2/cpu 2020-12-31 19:14:32 -06:00
Fabian c916e59dcb Simplify 2020-12-31 19:14:31 -06:00
Fabian 584c1e93ac Avoid aliasing reg128 structs (fixes pshuf*) 2020-12-31 19:14:31 -06:00
Fabian ab46fe4f37 Refactor modrm decoding for jit 2020-12-31 19:14:31 -06:00
Fabian 0dd6740526 Refactor 2020-12-31 19:14:31 -06:00
Fabian d6c7078c46 Move code around 2020-12-31 19:14:31 -06:00
Fabian 5251ab11e5 refactor: Move function calling into wasm builder (part 2) 2020-12-31 19:14:31 -06:00
Fabian e9cceb76bc refactor: Move function calling into wasm builder (part 1) 2020-12-31 19:14:31 -06:00
Fabian 5dd03792c2 jit RDTSC 2020-12-31 19:14:31 -06:00
Fabian 770f90feae Rename load_*_from_stack 2020-12-31 19:14:31 -06:00
Fabian a3dbd9ad5f Rename wasm functions loading from fixed address 2020-12-31 19:14:31 -06:00
Fabian bf661f0829 Add some helper functions 2020-12-31 19:14:31 -06:00
Fabian 2d59a5a082 Refactor 2020-12-31 19:14:31 -06:00
Fabian 240c4d0457 loop/loopz/loopnz: Move side-effects into function 2020-12-31 19:14:31 -06:00
Fabian 4860c6f461 jit 0F7E/0F7F mmx movd/movq 2020-12-31 19:14:31 -06:00
Fabian 44974370af jit 0F6E/0F6F mmx movd/movq 2020-12-31 19:14:31 -06:00
Fabian c5eea8a8d1 Jit POPF 2020-12-31 19:14:30 -06:00
Fabian 0edc821618 Jit DIV/IDIV 2020-12-31 19:14:30 -06:00
Fabian 3026e985fa Jit BT 2020-12-31 19:14:30 -06:00
Fabian fc43119406 Optimise returns and indirect jumps/calls into same page 2020-12-31 19:14:30 -06:00
Fabian ee542c5f84 Optimise lazy flag handling
- remove last_add_result and last_op2 from arithmetic instructions
- optimise getcf
2020-12-31 19:14:30 -06:00
Fabian 27a1f00657 Simplify 2020-12-31 19:14:30 -06:00
Fabian fdaf79eaa9 jit jo, jno, js, jns, jl, jnl, jle, jnle (the remaining arithmetic bits) 2020-12-31 19:14:30 -06:00
Fabian 88613c3f27 Remove page_fault 2020-12-31 19:14:30 -06:00
Fabian d31e0edb5a Improved code generation for jitted memory reads and writes 2020-12-31 19:14:30 -06:00
Fabian 46671b5354 Jit inc16/dec16 2020-12-31 19:14:30 -06:00
Fabian ce0f34eff2 Jit cmp8/test8 2020-12-31 19:14:30 -06:00
Fabian 6557445653 Generate less debug code in release 2020-12-31 19:14:30 -06:00
Fabian 9da94d5438 Move wasm ops to WasmBuilder 2020-12-31 19:14:30 -06:00
Fabian 97205c67a2 Rename to wasm_builder 2020-12-31 19:14:30 -06:00
Fabian e1f8a563ad Simplify (remove c_api) 2020-12-31 19:14:30 -06:00
Fabian 3a473aad79 Remove prefix handling from jit and exceptions 2020-12-31 19:14:30 -06:00
Fabian a73988a817 Make loop, loopz, loopnz and jcxz custom generated 2020-12-31 19:14:30 -06:00
Fabian 764879bad1 s/reg32s/reg32 2020-12-31 19:14:29 -06:00
Fabian 4bfd024366 Simplify gen_safe_read_write by removing fallback function 2020-12-31 19:14:29 -06:00
Fabian f058037006 Fix exception eip in #ud and #gp in jitted code 2020-12-31 19:14:29 -06:00
Fabian 6f366b1277 Refactor: Use gen_set_previous_eip_offset_from_eip_with_low_bits in gen_safe_read_write 2020-12-31 19:14:29 -06:00
Fabian e2eecc7295 task_switch_test*_jit: assert that jit agrees 2020-12-31 19:14:29 -06:00
Fabian 492a2cf78e Update previous_ip only if page fault is going to happen 2020-12-31 19:14:29 -06:00
Fabian 0d76a7e99a Correctly set previous_ip before #nm (fixes segfaults in Linux) 2020-12-31 19:14:29 -06:00
Fabian 4e9fa5e783 refactor 2020-12-31 19:14:29 -06:00
Fabian c47b4b252c Optimise cr0 access in task_switch_test (only low byte needed) 2020-12-31 19:14:29 -06:00
Fabian c207400922 Fix Rust warnings 2020-12-31 19:14:29 -06:00
Fabian c97600f5cb Also prepare gen_safe_read{64,128} for later optimisations 2020-12-31 19:14:29 -06:00
Fabian b23c4a9db2 Optimise pop reg 2020-12-31 19:14:29 -06:00
Fabian c5cd93678e Pass local to gen_safe_read, add single function for modrm_resolve and gen_safe_read (preparation for later optimisations) 2020-12-31 19:14:29 -06:00
Fabian f620aceb5d Use LocalOrImmediate for other arithmetic instructions 2020-12-31 19:14:28 -06:00
Fabian 0e8c8a1dda More opstats 2020-12-31 19:14:28 -06:00
Fabian 970739f60b Generate custom code for getzf/getcf/test_be 2020-12-31 19:14:28 -06:00
Fabian 701d59e0dd Custom codegen for absolute cli (FA) 2020-12-31 19:14:28 -06:00
Fabian b5a72061fb Custom codegen for absolute jmp/call (FF_2/FF_4) 2020-12-31 19:14:28 -06:00
Fabian 091b2324d9 Custom codegen for 8C 2020-12-31 19:14:28 -06:00
Fabian fdd1dc377d Custom codegen for xadd (0FC1) 2020-08-30 19:37:15 -05:00
Fabian 874818866a Codegen for mul32 + custom mul/imul (F7_[45]) 2020-08-30 19:37:15 -05:00
Fabian 2a3e4bfa86 Minor: Remove unused 2020-08-30 19:37:15 -05:00
Fabian b774db3f81 Fix: Clear prefixes when leaving instruction early 2020-08-30 19:37:15 -05:00
Fabian ac9ef7d447 gen_pop/gen_push: Avoid some unnecessary locals after registers-in-locals 2020-08-30 19:37:15 -05:00
Fabian 724090b319 Reduce code size by removing register restoring around safe_{read,write}*_jit 2020-08-30 19:37:15 -05:00
Fabian 723f78c14f Reduce code size by creating a block to jump to that handles the page fault case 2020-08-30 19:37:15 -05:00
Fabian a8308b988d Store registers in locals
This changes registers to be temporarily stored in wasm locals, across
each complete wasm module. Registers are moved from memory to locals
upon entering the wasm module and moved from locals to memory upon
leaving. Additionally, calls to functions that modify registers are
wrapped between moving registers to memory before and moving back to
locals after. This affects:

1. All non-custom instructions
2. safe_{read,write}_slow, since it may page fault (the slow path of all memory accesses)
3. task_switch_test* and trigger_ud
4. All block boundaries
5. The fallback functions of gen_safe_read_write (read-modify-write memory accesses)

The performance benefits are currently mostly eaten up by 1. and 4. (if
one calculates the total number of read/writes to registers in memory,
they are higher after this patch, as each instructions of typ 1. or 4.
requires moving all 8 register twice). This can be improved later by the
relatively mechanical work of making instructions custom (not
necessarily full code generation, only the part of the instruction where
registers are accessed). Multi-page wasm module generation will
significantly reduce the number of type 4. instructions.

Due to 2., the overall code size has significantly increased. This case
(the slow path of memory access) is often generated but rarely executed.
These moves can be removed in a later patch by a different scheme for
safe_{read,write}_slow, which has been left out of this patch for
simplicity of reviewing.

This also simplifies our code generation for storing registers, as

    instructions_body.const_i32(register_offset);
    // some computations ...
    instruction_body.store_i32();

turns into:

    // some computations ...
    write_register(register_index);

I.e., a prefix is not necessary anymore as locals are indexed directly.

Further patches will allow getting rid of some temporary locals, as
registers now can be used directly.
2020-08-30 19:37:15 -05:00
Fabian 56dc1af7cc Split SAFE_WRITE stat into WRITE and READ_WRITE 2020-08-30 19:37:15 -05:00
Fabian 32f988a08d Pass JitContext to gen_get_reg* (preparation for registers-in-locals) 2020-08-30 19:37:15 -05:00
Fabian 0c42ea0d1f Custom code generation for leave (C9) 2020-08-30 19:37:15 -05:00
Fabian 837e6ff362 Custom code generation for ret imm (C2) 2020-08-30 19:37:15 -05:00
Fabian aef22e38ad Add missing tracking of jit exit points 2020-08-30 19:37:15 -05:00
Fabian 69b834c8de Move condition function generation into codegen module and use it for cmovcc/setcc 2020-08-30 19:37:15 -05:00
Fabian 2837ccd06b Support for gen_safe_read128 and code generation for MOVDQU (F30F6F) 2020-08-30 19:37:15 -05:00
Fabian 440b67eda5 Support for gen_safe_write128 and code generation for MOVAPS/MOVDQA (0F29/660F7F) 2020-08-30 19:37:15 -05:00
Fabian e2ab5eabdd Code generation for missing memory operations (8-bit shifts, shrd, shld, xadd) 2020-08-30 19:37:15 -05:00
Fabian fdce557820 Codegen for fpu instructions (memory stores: fst/fstp/fist/fistp) (D9_[23], DB_[23], DD_[23], DF_[237]) 2020-08-30 19:37:15 -05:00
Fabian b11b2725bb Use i64 locals for gen_safe_write64 2020-08-30 19:37:15 -05:00
Fabian c452c357dd Codegen for fpu instructions (DE group) 2020-08-30 19:37:15 -05:00
Fabian 21caefbffd Codegen for fpu instructions (DC group) 2020-08-30 19:37:15 -05:00
Fabian f797ce10c9 64-bit operations for gen_safe_{read,write,read_write} 2020-08-30 19:37:15 -05:00
Fabian ec059a9f27 Codegen for fpu instructions (D8 group) 2020-08-30 19:37:15 -05:00
Fabian 48e6843a87 Remove S_ prefix from profiler 2020-08-30 19:29:54 -05:00
Fabian 7e1d398e05 Track last executed jump instruction, check for missed entry points while looking for compiled code 2020-08-30 19:29:54 -05:00
Fabian 7e3f1ad401 gen_fn: Accept wasm builder, not jit context 2020-08-30 19:29:54 -05:00
Fabian 2635ed71b4 jit memory access for 8-bit read-modify-write operations 2020-08-30 19:29:54 -05:00
Fabian 83febd1376 Remove duplicated constants (TLB_*) 2020-08-30 19:29:54 -05:00
Fabian bf895ff1b2 profiler: Keep track of fast/slow path for jitted memory access 2020-08-30 19:29:54 -05:00
Fabian b70a5c081a Allow fast path for memory reads from pages that contain code 2020-08-30 19:29:54 -05:00
Awal Garg 54151e2306 jit 0x0FBF 2020-08-30 19:29:54 -05:00
Fabian 295985e8e0 Remove code section: Only a single buffer is used for generating code 2020-08-30 19:29:54 -05:00
Fabian 41b60d278c Accept builder in gen_jmp_rel16, simplifying 2020-08-30 19:29:54 -05:00
Fabian fa958d95c3 Fix warnings: Remove unused stuff 2020-08-30 19:29:54 -05:00
Fabian fa50294b47 Generate code for read-modify-write instructions (C1/D1/D3: Shifts and rotates) 2020-08-30 19:29:54 -05:00
Fabian 3706bcac12 Use jit for read-modify-write arithmetic instructions 2020-08-30 19:29:54 -05:00
Fabian cfb9cd8abe Partial custom implementation for arithmethic instructions with read-memory 2020-08-30 19:29:54 -05:00
Fabian 1d24c5952d Cleanup of codegen api 2020-08-30 19:29:54 -05:00