Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SSE3 support in V86 #906

Merged
merged 180 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
fd5842e
Update x86_table.js
spetterman66 Sep 1, 2023
da44d54
Update instructions_0f.rs
spetterman66 Sep 1, 2023
e6663a1
Update jit_instructions.rs
spetterman66 Sep 1, 2023
aeba09a
Update jit_instructions.rs
spetterman66 Sep 1, 2023
fc9631f
Update instructions_0f.rs
spetterman66 Sep 1, 2023
f51f230
Update instructions_0f.rs
spetterman66 Sep 1, 2023
b789f9a
Update x86_table.js
spetterman66 Sep 2, 2023
023798f
Update instructions_0f.rs
spetterman66 Sep 2, 2023
c4237fb
Update instructions_0f.rs
spetterman66 Sep 2, 2023
2ec1fb0
Update x86_table.js
spetterman66 Sep 2, 2023
25525d7
Update x86_table.js
spetterman66 Sep 2, 2023
a8911db
Update x86_table.js
spetterman66 Sep 2, 2023
883b4d4
Update x86_table.js
spetterman66 Sep 2, 2023
c15cc35
Update x86_table.js
spetterman66 Sep 2, 2023
8c417d6
Update x86_table.js
spetterman66 Sep 2, 2023
011b42d
Update x86_table.js
spetterman66 Sep 2, 2023
45f9ae6
Update x86_table.js
spetterman66 Sep 2, 2023
a7dcb9d
Update x86_table.js
spetterman66 Sep 2, 2023
b553831
Update x86_table.js
spetterman66 Sep 2, 2023
c475939
Update x86_table.js
spetterman66 Sep 2, 2023
a4617d0
Update x86_table.js
spetterman66 Sep 2, 2023
bf487bb
Update jit_instructions.rs
spetterman66 Sep 2, 2023
d5908f7
Update jit_instructions.rs
spetterman66 Sep 2, 2023
30d62b2
Update x86_table.js
spetterman66 Sep 4, 2023
23ef03a
Update instructions.rs
spetterman66 Sep 4, 2023
7a6e5c2
Update instructions.rs
spetterman66 Sep 4, 2023
55488da
Update instructions.rs
spetterman66 Sep 4, 2023
23a0a0a
Update instructions.rs
spetterman66 Sep 4, 2023
27f747c
Update instructions.rs
spetterman66 Sep 4, 2023
f0c1685
Update instructions.rs
spetterman66 Sep 4, 2023
32e8f07
Update instructions.rs
spetterman66 Sep 4, 2023
9d7ddba
Update instructions.rs
spetterman66 Sep 4, 2023
ddbbd06
Update instructions.rs
spetterman66 Sep 4, 2023
de68f10
Update instructions.rs
spetterman66 Sep 4, 2023
428f80d
Update instructions.rs
spetterman66 Sep 4, 2023
b6a32fa
Update instructions.rs
spetterman66 Sep 5, 2023
4e418b9
Update instructions.rs
spetterman66 Sep 5, 2023
a8b6ae5
Update instructions.rs
spetterman66 Sep 5, 2023
373855a
Update instructions.rs
spetterman66 Sep 5, 2023
ff42c6e
Update instructions.rs
spetterman66 Sep 5, 2023
639d9df
Update instructions.rs
spetterman66 Sep 5, 2023
c74b7f3
Update instructions_0f.rs
spetterman66 Sep 5, 2023
9822ed3
Update jit_instructions.rs
spetterman66 Sep 6, 2023
99f069c
Update jit_instructions.rs
spetterman66 Sep 6, 2023
b133aa4
Update instructions_0f.rs
spetterman66 Sep 6, 2023
a7e9a09
Update fpu.rs
spetterman66 Sep 7, 2023
721282a
Update x86_table.js
spetterman66 Sep 7, 2023
6dd06e9
Update instructions.rs
spetterman66 Sep 7, 2023
ff03f07
Update jit_instructions.rs
spetterman66 Sep 7, 2023
8ff8a8a
Update fpu.rs
spetterman66 Sep 8, 2023
3d4cd78
Update fpu.rs
spetterman66 Sep 8, 2023
17445d9
Update fpu.rs
spetterman66 Sep 8, 2023
d83b032
Update instructions.rs
spetterman66 Sep 8, 2023
6b55c47
Update instructions.rs
spetterman66 Sep 8, 2023
9be79e8
Update instructions.rs
spetterman66 Sep 8, 2023
f55af43
Update fpu.rs
spetterman66 Sep 8, 2023
026aa7e
Update instructions.rs
spetterman66 Sep 8, 2023
b2acd54
Update instructions.rs
spetterman66 Sep 8, 2023
5e1985f
Update fpu.rs
spetterman66 Sep 8, 2023
506e90f
Update jit_instructions.rs
spetterman66 Sep 9, 2023
8586b53
Update x86_table.js\
spetterman66 Sep 9, 2023
f584d7b
Update jit_instructions.rs
spetterman66 Sep 9, 2023
a758541
Update instructions_0f.rs
spetterman66 Sep 10, 2023
fa892cc
Update instructions_0f.rs
spetterman66 Sep 10, 2023
6865409
Update Readme.md
spetterman66 Sep 11, 2023
261bfe2
Update fpu.rs
spetterman66 Sep 12, 2023
36eab71
Update fpu.rs
spetterman66 Sep 12, 2023
03b8872
Update fpu.rs
spetterman66 Sep 12, 2023
f34f3fd
Update fpu.rs
spetterman66 Sep 12, 2023
ddabf77
Update fpu.rs
spetterman66 Sep 12, 2023
7cae48b
Update fpu.rs
spetterman66 Sep 12, 2023
05aefa2
Update instructions_0f.rs
spetterman66 Sep 12, 2023
04e3c5d
Update jit_instructions.rs\
spetterman66 Sep 12, 2023
0a3cde1
Update instructions_0f.rs
spetterman66 Sep 12, 2023
8293d43
Update instructions_0f.rs
spetterman66 Sep 12, 2023
a60aacf
Update instructions_0f.rs
spetterman66 Sep 12, 2023
445ae92
Update instructions_0f.rs
spetterman66 Sep 12, 2023
062beab
Update instructions_0f.rs
spetterman66 Sep 12, 2023
814446b
Update instructions_0f.rs
spetterman66 Sep 12, 2023
cfc7274
Update instructions_0f.rs
spetterman66 Sep 12, 2023
a571b4d
Update fpu.rs
spetterman66 Sep 12, 2023
6598bd2
Update fpu.rs
spetterman66 Sep 12, 2023
1b377ed
Update instructions_0f.rs
spetterman66 Sep 12, 2023
c6e902a
Update instructions_0f.rs
spetterman66 Sep 12, 2023
6e56f1a
Update instructions_0f.rs
spetterman66 Sep 12, 2023
e72da4d
Update instructions_0f.rs
spetterman66 Sep 12, 2023
e21376a
Update instructions_0f.rs
spetterman66 Sep 12, 2023
942dc20
Update instructions_0f.rs
spetterman66 Sep 12, 2023
c0c9826
Update instructions_0f.rs
spetterman66 Sep 12, 2023
7ed6ac0
Update instructions_0f.rs
spetterman66 Sep 12, 2023
79822ea
Update instructions_0f.rs
spetterman66 Sep 12, 2023
06944b0
Update instructions_0f.rs
spetterman66 Sep 12, 2023
9142373
Update instructions_0f.rs
spetterman66 Sep 12, 2023
6a076d9
Update instructions_0f.rs
spetterman66 Sep 12, 2023
c41226c
Update instructions_0f.rs
spetterman66 Sep 12, 2023
7a9ea67
Update instructions_0f.rs
spetterman66 Sep 12, 2023
92f7ca1
Update instructions_0f.rs
spetterman66 Sep 12, 2023
d49d32b
Update instructions_0f.rs
spetterman66 Sep 12, 2023
d8b307a
Update instructions_0f.rs
spetterman66 Sep 12, 2023
aeaa1f2
Update instructions_0f.rs
spetterman66 Sep 12, 2023
f6871d8
Update instructions_0f.rs
spetterman66 Sep 12, 2023
9e4816e
Update instructions_0f.rs
spetterman66 Sep 12, 2023
039cf9c
Update instructions_0f.rs
spetterman66 Sep 12, 2023
143b3b4
Update instructions_0f.rs
spetterman66 Sep 13, 2023
5a18e65
Update instructions_0f.rs
spetterman66 Sep 13, 2023
6f56245
Update instructions_0f.rs
spetterman66 Sep 13, 2023
e724a3c
Update instructions_0f.rs
spetterman66 Sep 13, 2023
eae5042
Update instructions_0f.rs
spetterman66 Sep 13, 2023
fbb8aee
Update instructions_0f.rs
spetterman66 Sep 13, 2023
100ff3d
Update instructions_0f.rs
spetterman66 Sep 13, 2023
94e4a77
Update instructions_0f.rs
spetterman66 Sep 13, 2023
d58e119
Update instructions_0f.rs
spetterman66 Sep 13, 2023
daf180e
Update instructions_0f.rs
spetterman66 Sep 13, 2023
d901901
Update instructions_0f.rs
spetterman66 Sep 13, 2023
9db6850
Update instructions_0f.rs
spetterman66 Sep 13, 2023
028a958
Update instructions_0f.rs
spetterman66 Sep 13, 2023
4512d22
Update instructions_0f.rs
spetterman66 Sep 13, 2023
586fc83
Update instructions_0f.rs
spetterman66 Sep 13, 2023
72210ac
Update instructions_0f.rs
spetterman66 Sep 13, 2023
43a0142
Update instructions_0f.rs
spetterman66 Sep 13, 2023
0b6cf41
Update instructions_0f.rs
spetterman66 Sep 13, 2023
8c5b141
Update instructions_0f.rs
spetterman66 Sep 13, 2023
7c23424
Update instructions_0f.rs
spetterman66 Sep 13, 2023
a29798f
Update instructions_0f.rs
spetterman66 Sep 13, 2023
f2a531c
Update instructions_0f.rs
spetterman66 Sep 13, 2023
b915efd
Update instructions_0f.rs
spetterman66 Sep 13, 2023
07c6d81
Update instructions_0f.rs
spetterman66 Sep 13, 2023
a10090b
Update instructions_0f.rs
spetterman66 Sep 13, 2023
d782317
Update instructions_0f.rs
spetterman66 Sep 13, 2023
3426055
Update instructions_0f.rs
spetterman66 Sep 13, 2023
11c874b
Update instructions_0f.rs
spetterman66 Sep 13, 2023
158a4d2
Update instructions_0f.rs
spetterman66 Sep 14, 2023
aaf305d
Update instructions_0f.rs
spetterman66 Sep 14, 2023
63423b3
Update instructions_0f.rs
spetterman66 Sep 14, 2023
7a454cd
Update instructions_0f.rs
spetterman66 Sep 14, 2023
d054300
Update lib.rs
spetterman66 Sep 14, 2023
65c8698
Update lib.rs
spetterman66 Sep 14, 2023
d277af3
Update lib.rs
spetterman66 Sep 14, 2023
d2f08f8
Update lib.rs
spetterman66 Sep 14, 2023
dcd4b13
Update instructions.rs
spetterman66 Sep 14, 2023
47b1cf6
Update x86_table.js
spetterman66 Sep 14, 2023
cd39497
Update instructions_0f.rs
spetterman66 Sep 14, 2023
8e531f5
Update instructions_0f.rs
spetterman66 Sep 14, 2023
1e443a4
Update instructions_0f.rs
spetterman66 Sep 14, 2023
63cbca2
Update instructions_0f.rs
spetterman66 Sep 14, 2023
c5a52ea
Update instructions_0f.rs
spetterman66 Sep 14, 2023
4163c12
Update instructions_0f.rs
spetterman66 Sep 14, 2023
72bde3a
Update instructions_0f.rs
spetterman66 Sep 14, 2023
59b1b66
Update instructions_0f.rs
spetterman66 Sep 14, 2023
a2a1428
Update instructions_0f.rs
spetterman66 Sep 14, 2023
6f9d834
Update instructions_0f.rs
spetterman66 Sep 14, 2023
59586b7
Update instructions_0f.rs
spetterman66 Sep 14, 2023
0546588
Update instructions_0f.rs
spetterman66 Sep 15, 2023
40a72ca
Update instructions_0f.rs
spetterman66 Sep 15, 2023
1ce6002
Update instructions_0f.rs
spetterman66 Sep 15, 2023
4f0a797
Update instructions_0f.rs
spetterman66 Sep 15, 2023
2bb13ac
Update instructions_0f.rs
spetterman66 Sep 15, 2023
f442d08
Update instructions_0f.rs
spetterman66 Sep 15, 2023
b6cf834
Update instructions_0f.rs
spetterman66 Sep 15, 2023
d7ef854
Update instructions_0f.rs
spetterman66 Sep 15, 2023
cf5629f
Update instructions_0f.rs
spetterman66 Sep 15, 2023
d76a05b
Update instructions_0f.rs
spetterman66 Sep 15, 2023
df16927
Update instructions_0f.rs
spetterman66 Sep 15, 2023
b03640e
Update instructions_0f.rs
spetterman66 Sep 15, 2023
f868ecc
Update instructions_0f.rs
spetterman66 Sep 15, 2023
ab53f26
Update instructions_0f.rs
spetterman66 Sep 15, 2023
c1cb511
Update instructions_0f.rs
spetterman66 Sep 15, 2023
a869575
Update instructions_0f.rs
spetterman66 Sep 15, 2023
90efc9f
Update instructions_0f.rs
spetterman66 Sep 15, 2023
f8bf9b8
Update instructions_0f.rs
spetterman66 Sep 15, 2023
1da2d1f
Update instructions_0f.rs
spetterman66 Sep 15, 2023
2c3798a
Update instructions_0f.rs
spetterman66 Sep 15, 2023
b347961
Update instructions_0f.rs
spetterman66 Sep 15, 2023
a45b953
Update instructions_0f.rs
spetterman66 Sep 15, 2023
463aa88
Update instructions_0f.rs
spetterman66 Sep 15, 2023
5d2b9f5
Update instructions_0f.rs
spetterman66 Sep 15, 2023
860ef95
Update instructions_0f.rs
spetterman66 Sep 15, 2023
5653e48
Update instructions_0f.rs
spetterman66 Sep 15, 2023
1ec9248
Update instructions_0f.rs
spetterman66 Sep 15, 2023
1a38137
fix
copy Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WebAssembly modules at runtime in order to achieve decent performance. Here's a
list of emulated hardware:

- An x86-compatible CPU. The instruction set is around Pentium 4 level,
including full SSE2 support. Some features are missing, in particular:
including full SSE3 support. Some features are missing, in particular:
- Task gates, far calls in protected mode
- Some 16 bit protected mode features
- Single stepping (trap flag, debug registers)
Expand All @@ -25,7 +25,7 @@ list of emulated hardware:
- A generic VGA card with SVGA support and Bochs VBE Extensions.
- A PCI bus. This one is partly incomplete and not used by every device.
- An IDE disk controller.
- An NE2000 (8390) PCI network card.
- An NE2000 (RTL8390) PCI network card.
- A virtio filesystem.
- A SoundBlaster 16 sound card.

Expand Down Expand Up @@ -81,8 +81,7 @@ Here's an overview of the operating systems supported in v86:
- FreeDOS, Windows 1.01 and MS-DOS run very well.
- KolibriOS works.
- Haiku works.
- Android x86 1.6-r2 works if one selects VESA mode at the boot prompt. Newer
versions may work if compiled without SSE3. See [#224](https://github.com/copy/v86/issues/224).
- Android-x86 works up to 4.4-r2, if you select VESA mode at the boot prompt.
- Windows 1, 3.x, 95, 98, ME, NT and 2000 work reasonably well.
- In Windows 2000 and higher the PC type has to be changed from ACPI PC to Standard PC
- There are some known boot issues ([#250](https://github.com/copy/v86/issues/250), [#433](https://github.com/copy/v86/issues/433), [#507](https://github.com/copy/v86/issues/507), [#555](https://github.com/copy/v86/issues/555), [#620](https://github.com/copy/v86/issues/620), [#645](https://github.com/copy/v86/issues/645))
Expand Down
21 changes: 12 additions & 9 deletions gen/x86_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const encodings = [
{ opcode: 0xDA, e: 1, fixed_g: 7, custom: 1, is_fpu: 1, task_switch_test: 1, },

{ opcode: 0xDB, e: 1, fixed_g: 0, custom: 1, is_fpu: 1, task_switch_test: 1, },
{ opcode: 0xDB, e: 1, fixed_g: 1, custom: 0, is_fpu: 1, task_switch_test: 1, skip_mem: 1, }, // unimplemented: fisttp (sse3)
{ opcode: 0xDB, e: 1, fixed_g: 1, custom: 0, is_fpu: 1, task_switch_test: 1, }, // fisttp (sse3)
{ opcode: 0xDB, e: 1, fixed_g: 2, custom: 1, is_fpu: 1, task_switch_test: 1, },
{ opcode: 0xDB, e: 1, fixed_g: 3, custom: 1, is_fpu: 1, task_switch_test: 1, },
{ opcode: 0xDB, e: 1, fixed_g: 4, custom: 0, is_fpu: 1, task_switch_test: 1, },
Expand All @@ -324,7 +324,7 @@ const encodings = [
{ opcode: 0xDC, e: 1, fixed_g: 7, custom: 1, is_fpu: 1, task_switch_test: 1, },

{ opcode: 0xDD, e: 1, fixed_g: 0, custom: 1, is_fpu: 1, task_switch_test: 1, os: 1, },
{ opcode: 0xDD, e: 1, fixed_g: 1, custom: 0, is_fpu: 1, task_switch_test: 1, os: 1, skip_mem: 1, }, // unimplemented: fisttp (sse3)
{ opcode: 0xDD, e: 1, fixed_g: 1, custom: 0, is_fpu: 1, task_switch_test: 1, os: 1, }, // fisttp (sse3)
{ opcode: 0xDD, e: 1, fixed_g: 2, custom: 1, is_fpu: 1, task_switch_test: 1, os: 1, },
{ opcode: 0xDD, e: 1, fixed_g: 3, custom: 1, is_fpu: 1, task_switch_test: 1, os: 1, },
{ opcode: 0xDD, e: 1, fixed_g: 4, custom: 0, is_fpu: 1, task_switch_test: 1, os: 1, skip_mem: 1 }, // frstor
Expand All @@ -342,7 +342,7 @@ const encodings = [
{ opcode: 0xDE, e: 1, fixed_g: 7, custom: 1, is_fpu: 1, task_switch_test: 1, },

{ opcode: 0xDF, e: 1, fixed_g: 0, custom: 0, is_fpu: 1, task_switch_test: 1 },
{ opcode: 0xDF, e: 1, fixed_g: 1, custom: 0, is_fpu: 1, task_switch_test: 1, skip_mem: 1 }, // unimplemented: fisttp (sse3)
{ opcode: 0xDF, e: 1, fixed_g: 1, custom: 0, is_fpu: 1, task_switch_test: 1 }, // fisttp (sse3)
{ opcode: 0xDF, e: 1, fixed_g: 2, custom: 1, is_fpu: 1, task_switch_test: 1 },
{ opcode: 0xDF, e: 1, fixed_g: 3, custom: 1, is_fpu: 1, task_switch_test: 1 },
{ opcode: 0xDF, e: 1, fixed_g: 4, custom: 1, is_fpu: 1, task_switch_test: 1, skip_mem: 1 }, // unimplemented: Binary Coded Decimals
Expand Down Expand Up @@ -477,7 +477,7 @@ const encodings = [
{ opcode: 0x0F36, skip: 1, block_boundary: 1, }, // ud
{ opcode: 0x0F37, skip: 1, block_boundary: 1, }, // getsec

// sse3+
// ssse3+
{ opcode: 0x0F38, skip: 1, block_boundary: 1, },
{ opcode: 0x0F39, skip: 1, block_boundary: 1, },
{ opcode: 0x0F3A, skip: 1, block_boundary: 1, },
Expand Down Expand Up @@ -616,7 +616,7 @@ const encodings = [


// mmx, sse
// - skipped or missing are sse3+
// - skipped or missing are ssse3+

{ sse: 1, opcode: 0x0F10, e: 1, custom: 1 },
{ sse: 1, opcode: 0xF30F10, e: 1, custom: 1 },
Expand All @@ -628,8 +628,8 @@ const encodings = [
{ sse: 1, opcode: 0xF20F11, e: 1, custom: 1 },
{ sse: 1, opcode: 0x0F12, e: 1, custom: 1 },
{ sse: 1, opcode: 0x660F12, reg_ud: 1, e: 1, custom: 1 },
{ sse: 1, opcode: 0xF20F12, e: 1, skip: 1, block_boundary: 1, }, // sse3
{ sse: 1, opcode: 0xF30F12, e: 1, skip: 1, block_boundary: 1, }, // sse3
{ sse: 1, opcode: 0xF20F12, e: 1, custom: 1 }, // sse3
{ sse: 1, opcode: 0xF30F12, e: 1, custom: 1 }, // sse3
{ sse: 1, opcode: 0x0F13, reg_ud: 1, e: 1, custom: 1 },
{ sse: 1, opcode: 0x660F13, reg_ud: 1, e: 1, custom: 1 },
{ sse: 1, opcode: 0x0F14, e: 1, custom: 1 },
Expand All @@ -638,7 +638,7 @@ const encodings = [
{ sse: 1, opcode: 0x660F15, e: 1, custom: 1 },
{ sse: 1, opcode: 0x0F16, e: 1, custom: 1 },
{ sse: 1, opcode: 0x660F16, reg_ud: 1, e: 1, custom: 1 },
{ sse: 1, opcode: 0xF30F16, skip: 1, e: 1, block_boundary: 1, }, // sse3
{ sse: 1, opcode: 0xF30F16, e: 1, custom: 1 }, // sse3
{ sse: 1, opcode: 0x0F17, reg_ud: 1, e: 1, custom: 1 },
{ sse: 1, opcode: 0x660F17, reg_ud: 1, e: 1, custom: 1 },

Expand Down Expand Up @@ -699,7 +699,10 @@ const encodings = [
{ sse: 1, opcode: 0x660F59, e: 1, custom: 1 },
{ sse: 1, opcode: 0xF20F59, e: 1, custom: 1 },
{ sse: 1, opcode: 0xF30F59, e: 1, custom: 1 },
{ sse: 1, opcode: 0xF20F7C, e: 1, custom: 1 },
{ sse: 1, opcode: 0x660F7C, e: 1, custom: 1 }, // sse3
{ sse: 1, opcode: 0xF20F7C, e: 1, custom: 1 }, // sse3
{ sse: 1, opcode: 0x660F7D, e: 1, custom: 1 }, // sse3
{ sse: 1, opcode: 0xF20F7D, e: 1, custom: 1 }, // sse3

{ sse: 1, opcode: 0x0F5A, e: 1, custom: 1 },
{ sse: 1, opcode: 0x660F5A, e: 1, custom: 1 },
Expand Down
43 changes: 43 additions & 0 deletions src/rust/cpu/fpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,23 @@ pub unsafe fn fpu_fistm16p(addr: i32) {
safe_write16(addr, v as i32).unwrap();
fpu_pop();
}
#[no_mangle]
pub unsafe fn fpu_truncate_to_i16(f: F80) -> i16 {
let st0 = fpu_truncate_to_i32(f);
if st0 < -0x8000 || st0 > 0x7FFF {
fpu_invalid_arithmetic();
-0x8000
}
else {
st0 as i16
}
}
pub unsafe fn fpu_fisttpm16(addr: i32) {
return_on_pagefault!(writable_or_pagefault(addr, 2));
let v = fpu_truncate_to_i16(fpu_get_st0());
safe_write16(addr, v as i32).unwrap();
fpu_pop();
}

#[no_mangle]
pub unsafe fn fpu_convert_to_i32(f: F80) -> i32 {
Expand All @@ -353,6 +370,19 @@ pub unsafe fn fpu_fistm32p(addr: i32) {
safe_write32(addr, v).unwrap();
fpu_pop();
}
#[no_mangle]
pub unsafe fn fpu_truncate_to_i32(f: F80) -> i32 {
F80::clear_exception_flags();
let x = f.truncate_to_i32();
*fpu_status_word |= F80::get_exception_flags() as u16;
x
}
pub unsafe fn fpu_fisttpm32(addr: i32) {
return_on_pagefault!(writable_or_pagefault(addr, 4));
let v = fpu_truncate_to_i32(fpu_get_st0());
safe_write32(addr, v).unwrap();
fpu_pop();
}

#[no_mangle]
pub unsafe fn fpu_convert_to_i64(f: F80) -> i64 {
Expand All @@ -368,6 +398,19 @@ pub unsafe fn fpu_fistm64p(addr: i32) {
safe_write64(addr, v as u64).unwrap();
fpu_pop();
}
#[no_mangle]
pub unsafe fn fpu_truncate_to_i64(f: F80) -> i64 {
F80::clear_exception_flags();
let x = f.truncate_to_i64();
*fpu_status_word |= F80::get_exception_flags() as u16;
x
}
pub unsafe fn fpu_fisttpm64(addr: i32) {
return_on_pagefault!(writable_or_pagefault(addr, 8));
let v = fpu_truncate_to_i64(fpu_get_st0());
safe_write64(addr, v as u64).unwrap();
fpu_pop();
}

#[no_mangle]
pub unsafe fn fpu_fldcw(addr: i32) {
Expand Down
15 changes: 3 additions & 12 deletions src/rust/cpu/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1821,10 +1821,7 @@ pub unsafe fn instr_DA_7_reg(_r: i32) { trigger_ud(); }

pub unsafe fn instr_DB_0_mem(addr: i32) { fpu_fildm32(addr); }
#[no_mangle]
pub unsafe fn instr_DB_1_mem(_addr: i32) {
dbg_log!("fisttp");
fpu_unimpl();
}
pub unsafe fn instr_DB_1_mem(addr: i32) { fpu_fisttpm32(addr); }
pub unsafe fn instr_DB_2_mem(addr: i32) { fpu_fistm32(addr); }
pub unsafe fn instr_DB_3_mem(addr: i32) { fpu_fistm32p(addr); }
#[no_mangle]
Expand Down Expand Up @@ -1880,10 +1877,7 @@ pub unsafe fn instr_DC_7_reg(r: i32) { fpu_fdivr(r, fpu_get_sti(r)); }

pub unsafe fn instr16_DD_0_mem(addr: i32) { fpu_fldm64(addr); }
#[no_mangle]
pub unsafe fn instr16_DD_1_mem(_addr: i32) {
dbg_log!("fisttp");
fpu_unimpl();
}
pub unsafe fn instr16_DD_1_mem(addr: i32) { fpu_fisttpm64(addr); }
pub unsafe fn instr16_DD_2_mem(addr: i32) { fpu_fstm64(addr); }
pub unsafe fn instr16_DD_3_mem(addr: i32) { fpu_fstm64p(addr); }
#[no_mangle]
Expand Down Expand Up @@ -1994,10 +1988,7 @@ pub unsafe fn instr_DE_7_reg(r: i32) {
#[no_mangle]
pub unsafe fn instr_DF_0_mem(addr: i32) { fpu_fildm16(addr) }
#[no_mangle]
pub unsafe fn instr_DF_1_mem(_addr: i32) {
dbg_log!("fisttp");
fpu_unimpl();
}
pub unsafe fn instr_DF_1_mem(addr: i32) { fpu_fisttpm16(addr); }
pub unsafe fn instr_DF_2_mem(addr: i32) { fpu_fistm16(addr); }
pub unsafe fn instr_DF_3_mem(addr: i32) { fpu_fistm16p(addr); }
pub unsafe fn instr_DF_4_mem(_addr: i32) {
Expand Down
140 changes: 109 additions & 31 deletions src/rust/cpu/instructions_0f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,30 @@ pub unsafe fn instr_660F12_mem(addr: i32, r: i32) {
write_xmm64(r, data);
}
#[no_mangle]
pub unsafe fn instr_F20F12_mem(_addr: i32, _r: i32) { unimplemented_sse(); }
#[no_mangle]
pub unsafe fn instr_F20F12_reg(_r1: i32, _r2: i32) { unimplemented_sse(); }
#[no_mangle]
pub unsafe fn instr_F30F12_mem(_addr: i32, _r: i32) { unimplemented_sse(); }
#[no_mangle]
pub unsafe fn instr_F30F12_reg(_r1: i32, _r2: i32) { unimplemented_sse(); }

pub unsafe fn instr_F20F12(source: u64, r: i32) {
// movddup xmm1, xmm2/m64
write_xmm_reg128(r, reg128 { u64: [source, source] });
}
pub unsafe fn instr_F20F12_reg(r1: i32, r2: i32) { instr_F20F12(read_xmm64s(r1), r2); }
pub unsafe fn instr_F20F12_mem(addr: i32, r: i32) {
instr_F20F12(return_on_pagefault!(safe_read64s(addr)), r);
}
#[no_mangle]
pub unsafe fn instr_F30F12(source: reg128, r: i32) {
// movsldup xmm1, xmm2/m128
write_xmm_reg128(r, reg128 {
u32: [
source.u32[0],
source.u32[0],
source.u32[2],
source.u32[2],
],
});
}
pub unsafe fn instr_F30F12_reg(r1: i32, r2: i32) { instr_F30F12(read_xmm128s(r1), r2); }
pub unsafe fn instr_F30F12_mem(addr: i32, r: i32) {
instr_F30F12(return_on_pagefault!(safe_read128s(addr)), r);
}
pub unsafe fn instr_0F13_mem(addr: i32, r: i32) {
// movlps m64, xmm
movl_r128_m64(addr, r);
Expand Down Expand Up @@ -658,10 +674,21 @@ pub unsafe fn instr_660F16_mem(addr: i32, r: i32) {
}
pub unsafe fn instr_660F16_reg(_r1: i32, _r2: i32) { trigger_ud(); }
#[no_mangle]
pub unsafe fn instr_F30F16_reg(_r1: i32, _r2: i32) { unimplemented_sse(); }
#[no_mangle]
pub unsafe fn instr_F30F16_mem(_addr: i32, _r: i32) { unimplemented_sse(); }

pub unsafe fn instr_F30F16(source: reg128, r: i32) {
// movshdup xmm1, xmm2/m128
write_xmm_reg128(r, reg128 {
u32: [
source.u32[1],
source.u32[1],
source.u32[3],
source.u32[3],
]
});
}
pub unsafe fn instr_F30F16_reg(r1: i32, r2: i32) { instr_F30F16(read_xmm128s(r1), r2); }
pub unsafe fn instr_F30F16_mem(addr: i32, r: i32) {
instr_F30F16(return_on_pagefault!(safe_read128s(addr)), r);
}
pub unsafe fn instr_0F17_mem(addr: i32, r: i32) {
// movhps m64, xmm
movh_r128_m64(addr, r);
Expand Down Expand Up @@ -1821,24 +1848,6 @@ pub unsafe fn instr_F30F59_reg(r1: i32, r2: i32) { instr_F30F59(read_xmm_f32(r1)
pub unsafe fn instr_F30F59_mem(addr: i32, r: i32) {
instr_F30F59(return_on_pagefault!(safe_read_f32(addr)), r);
}
#[no_mangle]
pub unsafe fn instr_F20F7C(source: reg128, r: i32) {
// haddps xmm, xmm/mem128
let destination = read_xmm128s(r);
let result = reg128 {
f32: [
destination.f32[0] + destination.f32[1],
destination.f32[2] + destination.f32[3],
source.f32[0] + source.f32[1],
source.f32[2] + source.f32[3],
],
};
write_xmm_reg128(r, result);
}
pub unsafe fn instr_F20F7C_reg(r1: i32, r2: i32) { instr_F20F7C(read_xmm128s(r1), r2); }
pub unsafe fn instr_F20F7C_mem(addr: i32, r: i32) {
instr_F20F7C(return_on_pagefault!(safe_read128s(addr)), r);
}

#[no_mangle]
pub unsafe fn instr_0F5A(source: u64, r: i32) {
Expand Down Expand Up @@ -2946,6 +2955,7 @@ pub unsafe fn instr_0F77() {
// emms
fpu_set_tag_word(0xFFFF);
}

#[no_mangle]
pub unsafe fn instr_0F78() { unimplemented_sse(); }
#[no_mangle]
Expand All @@ -2954,11 +2964,79 @@ pub unsafe fn instr_0F79() { unimplemented_sse(); }
pub unsafe fn instr_0F7A() { unimplemented_sse(); }
#[no_mangle]
pub unsafe fn instr_0F7B() { unimplemented_sse(); }

#[no_mangle]
pub unsafe fn instr_0F7C() { unimplemented_sse(); }
#[no_mangle]
pub unsafe fn instr_0F7D() { unimplemented_sse(); }

#[no_mangle]
pub unsafe fn instr_660F7C(source: reg128, r: i32) {
// haddpd xmm1, xmm2/m128
let destination = read_xmm128s(r);
write_xmm_reg128(r, reg128 {
f64: [
destination.f64[0] + destination.f64[1],
source.f64[0] + source.f64[1],
],
});
}
pub unsafe fn instr_660F7C_reg(r1: i32, r2: i32) { instr_660F7C(read_xmm128s(r1), r2); }
pub unsafe fn instr_660F7C_mem(addr: i32, r: i32) {
instr_660F7C(return_on_pagefault!(safe_read128s(addr)), r);
}
#[no_mangle]
pub unsafe fn instr_F20F7C(source: reg128, r: i32) {
// haddps xmm, xmm/mem128
let destination = read_xmm128s(r);
write_xmm_reg128(r, reg128 {
f32: [
destination.f32[0] + destination.f32[1],
destination.f32[2] + destination.f32[3],
source.f32[0] + source.f32[1],
source.f32[2] + source.f32[3],
],
});
}
pub unsafe fn instr_F20F7C_reg(r1: i32, r2: i32) { instr_F20F7C(read_xmm128s(r1), r2); }
pub unsafe fn instr_F20F7C_mem(addr: i32, r: i32) {
instr_F20F7C(return_on_pagefault!(safe_read128s(addr)), r);
}

#[no_mangle]
pub unsafe fn instr_660F7D(source: reg128, r: i32) {
// hsubpd xmm1, xmm2/m128
let destination = read_xmm128s(r);
write_xmm_reg128(r, reg128 {
f64: [
destination.f64[0] - destination.f64[1],
source.f64[0] - source.f64[1],
],
});
}
pub unsafe fn instr_660F7D_reg(r1: i32, r2: i32) { instr_660F7D(read_xmm128s(r1), r2); }
pub unsafe fn instr_660F7D_mem(addr: i32, r: i32) {
instr_660F7D(return_on_pagefault!(safe_read128s(addr)), r);
}

#[no_mangle]
pub unsafe fn instr_F20F7D(source: reg128, r: i32) {
// hsubps xmm1, xmm2/m128
let destination = read_xmm128s(r);
write_xmm_reg128(r, reg128 {
f32: [
destination.f32[0] - destination.f32[1],
destination.f32[2] - destination.f32[3],
source.f32[0] - source.f32[1],
source.f32[2] - source.f32[3],
],
});
}
pub unsafe fn instr_F20F7D_reg(r1: i32, r2: i32) { instr_F20F7D(read_xmm128s(r1), r2); }
pub unsafe fn instr_F20F7D_mem(addr: i32, r: i32) {
instr_F20F7D(return_on_pagefault!(safe_read128s(addr)), r);
}

#[no_mangle]
pub unsafe fn instr_0F7E(r: i32) -> i32 {
// movd r/m32, mm
Expand Down Expand Up @@ -3145,7 +3223,7 @@ pub unsafe fn instr_0FA2() {
// pentium
eax = 3 | 6 << 4 | 15 << 8;
ebx = 1 << 16 | 8 << 8; // cpu count, clflush size
ecx = 1 << 23 | 1 << 30; // popcnt, rdrand
ecx = 1 << 0 | 1 << 23 | 1 << 30; // sse3, popcnt, rdrand
let vme = 0 << 1;
if ::config::VMWARE_HYPERVISOR_PORT {
ecx |= 1 << 31
Expand Down
Loading