@aptre/v86 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE +22 -0
  2. package/LICENSE.MIT +22 -0
  3. package/Readme.md +237 -0
  4. package/dist/v86.browser.js +26666 -0
  5. package/dist/v86.browser.js.map +7 -0
  6. package/dist/v86.js +26632 -0
  7. package/dist/v86.js.map +7 -0
  8. package/gen/generate_analyzer.ts +512 -0
  9. package/gen/generate_interpreter.ts +522 -0
  10. package/gen/generate_jit.ts +624 -0
  11. package/gen/rust_ast.ts +107 -0
  12. package/gen/util.ts +35 -0
  13. package/gen/x86_table.ts +1836 -0
  14. package/lib/9p.ts +1547 -0
  15. package/lib/filesystem.ts +1879 -0
  16. package/lib/marshall.ts +168 -0
  17. package/lib/softfloat/softfloat.c +32501 -0
  18. package/lib/zstd/zstddeclib.c +13520 -0
  19. package/package.json +75 -0
  20. package/src/acpi.ts +267 -0
  21. package/src/browser/dummy_screen.ts +106 -0
  22. package/src/browser/fake_network.ts +1771 -0
  23. package/src/browser/fetch_network.ts +361 -0
  24. package/src/browser/filestorage.ts +124 -0
  25. package/src/browser/inbrowser_network.ts +57 -0
  26. package/src/browser/keyboard.ts +564 -0
  27. package/src/browser/main.ts +3415 -0
  28. package/src/browser/mouse.ts +255 -0
  29. package/src/browser/network.ts +142 -0
  30. package/src/browser/print_stats.ts +336 -0
  31. package/src/browser/screen.ts +978 -0
  32. package/src/browser/serial.ts +316 -0
  33. package/src/browser/speaker.ts +1223 -0
  34. package/src/browser/starter.ts +1688 -0
  35. package/src/browser/wisp_network.ts +332 -0
  36. package/src/browser/worker_bus.ts +64 -0
  37. package/src/buffer.ts +652 -0
  38. package/src/bus.ts +78 -0
  39. package/src/const.ts +128 -0
  40. package/src/cpu.ts +2891 -0
  41. package/src/dma.ts +474 -0
  42. package/src/elf.ts +251 -0
  43. package/src/floppy.ts +1778 -0
  44. package/src/ide.ts +3455 -0
  45. package/src/io.ts +504 -0
  46. package/src/iso9660.ts +317 -0
  47. package/src/kernel.ts +250 -0
  48. package/src/lib.ts +645 -0
  49. package/src/log.ts +149 -0
  50. package/src/main.ts +199 -0
  51. package/src/ne2k.ts +1589 -0
  52. package/src/pci.ts +815 -0
  53. package/src/pit.ts +406 -0
  54. package/src/ps2.ts +820 -0
  55. package/src/rtc.ts +537 -0
  56. package/src/rust/analysis.rs +101 -0
  57. package/src/rust/codegen.rs +2660 -0
  58. package/src/rust/config.rs +3 -0
  59. package/src/rust/control_flow.rs +425 -0
  60. package/src/rust/cpu/apic.rs +658 -0
  61. package/src/rust/cpu/arith.rs +1207 -0
  62. package/src/rust/cpu/call_indirect.rs +2 -0
  63. package/src/rust/cpu/cpu.rs +4501 -0
  64. package/src/rust/cpu/fpu.rs +923 -0
  65. package/src/rust/cpu/global_pointers.rs +112 -0
  66. package/src/rust/cpu/instructions.rs +2486 -0
  67. package/src/rust/cpu/instructions_0f.rs +5261 -0
  68. package/src/rust/cpu/ioapic.rs +316 -0
  69. package/src/rust/cpu/memory.rs +351 -0
  70. package/src/rust/cpu/misc_instr.rs +613 -0
  71. package/src/rust/cpu/mod.rs +16 -0
  72. package/src/rust/cpu/modrm.rs +133 -0
  73. package/src/rust/cpu/pic.rs +402 -0
  74. package/src/rust/cpu/sse_instr.rs +361 -0
  75. package/src/rust/cpu/string.rs +701 -0
  76. package/src/rust/cpu/vga.rs +175 -0
  77. package/src/rust/cpu_context.rs +69 -0
  78. package/src/rust/dbg.rs +98 -0
  79. package/src/rust/gen/analyzer.rs +3807 -0
  80. package/src/rust/gen/analyzer0f.rs +3992 -0
  81. package/src/rust/gen/interpreter.rs +4447 -0
  82. package/src/rust/gen/interpreter0f.rs +5404 -0
  83. package/src/rust/gen/jit.rs +5080 -0
  84. package/src/rust/gen/jit0f.rs +5547 -0
  85. package/src/rust/gen/mod.rs +14 -0
  86. package/src/rust/jit.rs +2443 -0
  87. package/src/rust/jit_instructions.rs +7881 -0
  88. package/src/rust/js_api.rs +6 -0
  89. package/src/rust/leb.rs +46 -0
  90. package/src/rust/lib.rs +29 -0
  91. package/src/rust/modrm.rs +330 -0
  92. package/src/rust/opstats.rs +249 -0
  93. package/src/rust/page.rs +15 -0
  94. package/src/rust/paging.rs +25 -0
  95. package/src/rust/prefix.rs +15 -0
  96. package/src/rust/profiler.rs +155 -0
  97. package/src/rust/regs.rs +38 -0
  98. package/src/rust/softfloat.rs +286 -0
  99. package/src/rust/state_flags.rs +27 -0
  100. package/src/rust/wasmgen/mod.rs +2 -0
  101. package/src/rust/wasmgen/wasm_builder.rs +1047 -0
  102. package/src/rust/wasmgen/wasm_opcodes.rs +221 -0
  103. package/src/rust/zstd.rs +105 -0
  104. package/src/sb16.ts +1928 -0
  105. package/src/state.ts +359 -0
  106. package/src/uart.ts +472 -0
  107. package/src/vga.ts +2791 -0
  108. package/src/virtio.ts +1756 -0
  109. package/src/virtio_balloon.ts +273 -0
  110. package/src/virtio_console.ts +372 -0
  111. package/src/virtio_net.ts +326 -0
@@ -0,0 +1,15 @@
1
+ pub const PREFIX_REPZ: u8 = 0b01000;
2
+ pub const PREFIX_REPNZ: u8 = 0b10000;
3
+ pub const PREFIX_MASK_REP: u8 = PREFIX_REPZ | PREFIX_REPNZ;
4
+
5
+ pub const PREFIX_MASK_OPSIZE: u8 = 0b100000;
6
+ pub const PREFIX_MASK_ADDRSIZE: u8 = 0b1000000;
7
+
8
+ pub const PREFIX_66: u8 = PREFIX_MASK_OPSIZE;
9
+ pub const PREFIX_67: u8 = PREFIX_MASK_ADDRSIZE;
10
+ pub const PREFIX_F2: u8 = PREFIX_REPNZ;
11
+ pub const PREFIX_F3: u8 = PREFIX_REPZ;
12
+
13
+ pub const SEG_PREFIX_ZERO: u8 = 7;
14
+
15
+ pub const PREFIX_MASK_SEGMENT: u8 = 0b111;
@@ -0,0 +1,155 @@
1
+ #[allow(non_camel_case_types)]
2
+ pub enum stat {
3
+ COMPILE,
4
+ COMPILE_SKIPPED_NO_NEW_ENTRY_POINTS,
5
+ COMPILE_WRONG_ADDRESS_SPACE,
6
+ COMPILE_CUT_OFF_AT_END_OF_PAGE,
7
+ COMPILE_WITH_LOOP_SAFETY,
8
+ COMPILE_PAGE,
9
+ COMPILE_BASIC_BLOCK,
10
+ COMPILE_DUPLICATED_BASIC_BLOCK,
11
+ COMPILE_WASM_BLOCK,
12
+ COMPILE_WASM_LOOP,
13
+ COMPILE_DISPATCHER,
14
+ COMPILE_ENTRY_POINT,
15
+ COMPILE_WASM_TOTAL_BYTES,
16
+
17
+ RUN_INTERPRETED,
18
+ RUN_INTERPRETED_NEW_PAGE,
19
+ RUN_INTERPRETED_PAGE_HAS_CODE,
20
+ RUN_INTERPRETED_PAGE_HAS_ENTRY_AFTER_PAGE_WALK,
21
+ RUN_INTERPRETED_NEAR_END_OF_PAGE,
22
+ RUN_INTERPRETED_DIFFERENT_STATE,
23
+ RUN_INTERPRETED_DIFFERENT_STATE_CPL3,
24
+ RUN_INTERPRETED_DIFFERENT_STATE_FLAT,
25
+ RUN_INTERPRETED_DIFFERENT_STATE_IS32,
26
+ RUN_INTERPRETED_DIFFERENT_STATE_SS32,
27
+ RUN_INTERPRETED_MISSED_COMPILED_ENTRY_RUN_INTERPRETED,
28
+ RUN_INTERPRETED_STEPS,
29
+
30
+ RUN_FROM_CACHE,
31
+ RUN_FROM_CACHE_STEPS,
32
+
33
+ DIRECT_EXIT,
34
+ INDIRECT_JUMP,
35
+ INDIRECT_JUMP_NO_ENTRY,
36
+ NORMAL_PAGE_CHANGE,
37
+ NORMAL_FALLTHRU,
38
+ NORMAL_FALLTHRU_WITH_TARGET_BLOCK,
39
+ NORMAL_BRANCH,
40
+ NORMAL_BRANCH_WITH_TARGET_BLOCK,
41
+ CONDITIONAL_JUMP,
42
+ CONDITIONAL_JUMP_PAGE_CHANGE,
43
+ CONDITIONAL_JUMP_EXIT,
44
+ CONDITIONAL_JUMP_FALLTHRU,
45
+ CONDITIONAL_JUMP_FALLTHRU_WITH_TARGET_BLOCK,
46
+ CONDITIONAL_JUMP_BRANCH,
47
+ CONDITIONAL_JUMP_BRANCH_WITH_TARGET_BLOCK,
48
+ DISPATCHER_SMALL,
49
+ DISPATCHER_LARGE,
50
+ LOOP,
51
+
52
+ LOOP_SAFETY,
53
+
54
+ CONDITION_OPTIMISED,
55
+ CONDITION_UNOPTIMISED,
56
+ CONDITION_UNOPTIMISED_PF,
57
+ CONDITION_UNOPTIMISED_UNHANDLED_L,
58
+ CONDITION_UNOPTIMISED_UNHANDLED_LE,
59
+
60
+ FAILED_PAGE_CHANGE,
61
+
62
+ SAFE_READ_FAST,
63
+ SAFE_READ_SLOW_PAGE_CROSSED,
64
+ SAFE_READ_SLOW_NOT_VALID,
65
+ SAFE_READ_SLOW_NOT_USER,
66
+ SAFE_READ_SLOW_IN_MAPPED_RANGE,
67
+
68
+ SAFE_WRITE_FAST,
69
+ SAFE_WRITE_SLOW_PAGE_CROSSED,
70
+ SAFE_WRITE_SLOW_NOT_VALID,
71
+ SAFE_WRITE_SLOW_NOT_USER,
72
+ SAFE_WRITE_SLOW_IN_MAPPED_RANGE,
73
+ SAFE_WRITE_SLOW_READ_ONLY,
74
+ SAFE_WRITE_SLOW_HAS_CODE,
75
+
76
+ SAFE_READ_WRITE_FAST,
77
+ SAFE_READ_WRITE_SLOW_PAGE_CROSSED,
78
+ SAFE_READ_WRITE_SLOW_NOT_VALID,
79
+ SAFE_READ_WRITE_SLOW_NOT_USER,
80
+ SAFE_READ_WRITE_SLOW_IN_MAPPED_RANGE,
81
+ SAFE_READ_WRITE_SLOW_READ_ONLY,
82
+ SAFE_READ_WRITE_SLOW_HAS_CODE,
83
+
84
+ PAGE_FAULT,
85
+ TLB_MISS,
86
+
87
+ MAIN_LOOP,
88
+ MAIN_LOOP_IDLE,
89
+ DO_MANY_CYCLES,
90
+ CYCLE_INTERNAL,
91
+
92
+ INVALIDATE_ALL_MODULES_NO_FREE_WASM_INDICES,
93
+ INVALIDATE_MODULE_WRITTEN_WHILE_COMPILED,
94
+ INVALIDATE_MODULE_UNUSED_AFTER_OVERWRITE,
95
+ INVALIDATE_MODULE_DIRTY_PAGE,
96
+
97
+ INVALIDATE_PAGE_HAD_CODE,
98
+ INVALIDATE_PAGE_HAD_ENTRY_POINTS,
99
+ DIRTY_PAGE_DID_NOT_HAVE_CODE,
100
+
101
+ RUN_FROM_CACHE_EXIT_SAME_PAGE,
102
+ RUN_FROM_CACHE_EXIT_NEAR_END_OF_PAGE,
103
+ RUN_FROM_CACHE_EXIT_DIFFERENT_PAGE,
104
+
105
+ CLEAR_TLB,
106
+ FULL_CLEAR_TLB,
107
+ TLB_FULL,
108
+ TLB_GLOBAL_FULL,
109
+
110
+ MODRM_SIMPLE_REG,
111
+ MODRM_SIMPLE_REG_WITH_OFFSET,
112
+ MODRM_SIMPLE_CONST_OFFSET,
113
+ MODRM_COMPLEX,
114
+
115
+ SEG_OFFSET_OPTIMISED,
116
+ SEG_OFFSET_NOT_OPTIMISED,
117
+ SEG_OFFSET_NOT_OPTIMISED_ES,
118
+ SEG_OFFSET_NOT_OPTIMISED_FS,
119
+ SEG_OFFSET_NOT_OPTIMISED_GS,
120
+ SEG_OFFSET_NOT_OPTIMISED_NOT_FLAT,
121
+ }
122
+
123
+ #[allow(non_upper_case_globals)]
124
+ pub static mut stat_array: [u64; 500] = [0; 500];
125
+
126
+ pub fn stat_increment(stat: stat) { stat_increment_by(stat, 1); }
127
+
128
+ pub fn stat_increment_by(stat: stat, by: u64) {
129
+ if cfg!(feature = "profiler") {
130
+ unsafe { stat_array[stat as usize] += by }
131
+ }
132
+ }
133
+
134
+ #[no_mangle]
135
+ pub fn profiler_init() {
136
+ unsafe {
137
+ #[allow(static_mut_refs)]
138
+ for x in stat_array.iter_mut() {
139
+ *x = 0
140
+ }
141
+ }
142
+ }
143
+
144
+ #[no_mangle]
145
+ pub fn profiler_stat_get(stat: stat) -> f64 {
146
+ if cfg!(feature = "profiler") {
147
+ unsafe { stat_array[stat as usize] as f64 }
148
+ }
149
+ else {
150
+ 0.0
151
+ }
152
+ }
153
+
154
+ #[no_mangle]
155
+ pub fn profiler_is_enabled() -> bool { cfg!(feature = "profiler") }
@@ -0,0 +1,38 @@
1
+ pub const ES: u32 = 0;
2
+ pub const CS: u32 = 1;
3
+ pub const SS: u32 = 2;
4
+ pub const DS: u32 = 3;
5
+ pub const FS: u32 = 4;
6
+ pub const GS: u32 = 5;
7
+
8
+ pub const EAX: u32 = 0;
9
+ pub const ECX: u32 = 1;
10
+ pub const EDX: u32 = 2;
11
+ pub const EBX: u32 = 3;
12
+ pub const ESP: u32 = 4;
13
+ pub const EBP: u32 = 5;
14
+ pub const ESI: u32 = 6;
15
+ pub const EDI: u32 = 7;
16
+
17
+ pub const AX: u32 = 0;
18
+ pub const CX: u32 = 1;
19
+ pub const DX: u32 = 2;
20
+ pub const BX: u32 = 3;
21
+ pub const SP: u32 = 4;
22
+ pub const BP: u32 = 5;
23
+ pub const SI: u32 = 6;
24
+ pub const DI: u32 = 7;
25
+
26
+ pub const AL: u32 = 0;
27
+ pub const CL: u32 = 1;
28
+ pub const DL: u32 = 2;
29
+ pub const BL: u32 = 3;
30
+ pub const AH: u32 = 4;
31
+ pub const CH: u32 = 5;
32
+ pub const DH: u32 = 6;
33
+ pub const BH: u32 = 7;
34
+
35
+ pub const CR0_EM: u32 = 1 << 2;
36
+ pub const CR0_TS: u32 = 1 << 3;
37
+
38
+ pub const CR4_TSD: u32 = 1 << 2;
@@ -0,0 +1,286 @@
1
+ extern "C" {
2
+ fn extF80M_add(x: *const F80, y: *const F80, ptr: *mut F80);
3
+ fn extF80M_sub(x: *const F80, y: *const F80, ptr: *mut F80);
4
+ fn extF80M_mul(x: *const F80, y: *const F80, ptr: *mut F80);
5
+ fn extF80M_div(x: *const F80, y: *const F80, ptr: *mut F80);
6
+ //fn extF80M_rem(x: *const F80, y: *const F80, ptr: *mut F80);
7
+ fn extF80M_sqrt(x: *const F80, ptr: *mut F80);
8
+
9
+ fn extF80M_roundToInt(x: *const F80, rounding_mode: u8, raise_inexact: bool, dst: *mut F80);
10
+
11
+ fn extF80M_eq(x: *const F80, y: *const F80) -> bool;
12
+ //fn extF80M_eq_signaling(x: *const F80, y: *const F80) -> bool;
13
+
14
+ //fn extF80M_le(x: *const F80, y: *const F80) -> bool;
15
+ //fn extF80M_le_quiet(x: *const F80, y: *const F80) -> bool;
16
+ fn extF80M_lt(x: *const F80, y: *const F80) -> bool;
17
+ fn extF80M_lt_quiet(x: *const F80, y: *const F80) -> bool;
18
+
19
+ fn extF80M_to_i32(src: *const F80, rounding_mode: u8, raise_inexact: bool) -> i32;
20
+ fn extF80M_to_i64(src: *const F80, rounding_mode: u8, raise_inexact: bool) -> i64;
21
+ fn i32_to_extF80M(src: i32, dst: *mut F80);
22
+ fn i64_to_extF80M(src: i64, dst: *mut F80);
23
+
24
+ fn f32_to_extF80M(src: i32, dst: *mut F80);
25
+ fn f64_to_extF80M(src: u64, dst: *mut F80);
26
+ fn extF80M_to_f32(src: *const F80) -> i32;
27
+ fn extF80M_to_f64(src: *const F80) -> u64;
28
+
29
+ static mut softfloat_roundingMode: u8;
30
+ static mut extF80_roundingPrecision: u8;
31
+ static mut softfloat_exceptionFlags: u8;
32
+ }
33
+
34
+ pub enum RoundingMode {
35
+ NearEven,
36
+ Trunc,
37
+ Floor,
38
+ Ceil,
39
+ }
40
+ pub enum Precision {
41
+ P80,
42
+ P64,
43
+ P32,
44
+ }
45
+
46
+ #[repr(C)]
47
+ #[derive(Copy, Clone)]
48
+ pub struct F80 {
49
+ pub mantissa: u64,
50
+ pub sign_exponent: u16,
51
+ }
52
+ impl F80 {
53
+ pub const ZERO: F80 = F80 {
54
+ mantissa: 0,
55
+ sign_exponent: 0,
56
+ };
57
+ pub const ONE: F80 = F80 {
58
+ mantissa: 0x8000000000000000,
59
+ sign_exponent: 0x3FFF,
60
+ };
61
+ pub const LN_10: F80 = F80 {
62
+ mantissa: 0x935D8DDDAAA8B000,
63
+ sign_exponent: 0x4000,
64
+ };
65
+ pub const LN_2: F80 = F80 {
66
+ mantissa: 0xB17217F7D1CF7800,
67
+ sign_exponent: 0x3FFE,
68
+ };
69
+ pub const PI: F80 = F80 {
70
+ mantissa: 0xC90FDAA22168C000,
71
+ sign_exponent: 0x4000,
72
+ };
73
+ pub const LOG2_E: F80 = F80 {
74
+ mantissa: 0xB8AA3B295C17F000,
75
+ sign_exponent: 0x3FFF,
76
+ };
77
+ pub const INDEFINITE_NAN: F80 = F80 {
78
+ mantissa: 0xC000000000000000,
79
+ sign_exponent: 0x7FFF,
80
+ };
81
+ pub const POS_INFINITY: F80 = F80 {
82
+ mantissa: 0x8000000000000000,
83
+ sign_exponent: 0x7FFF,
84
+ };
85
+ pub const NEG_INFINITY: F80 = F80 {
86
+ mantissa: 0x8000000000000000,
87
+ sign_exponent: 0xFFFF,
88
+ };
89
+
90
+ pub fn sign(&self) -> bool { (self.sign_exponent >> 15) == 1 }
91
+ pub fn exponent(&self) -> i16 { (self.sign_exponent as i16 & 0x7FFF) - 0x3FFF }
92
+
93
+ pub fn of_i32(src: i32) -> F80 {
94
+ let mut x = F80::ZERO;
95
+ unsafe { i32_to_extF80M(src, &mut x) };
96
+ x
97
+ }
98
+ pub fn of_i64(src: i64) -> F80 {
99
+ let mut x = F80::ZERO;
100
+ unsafe { i64_to_extF80M(src, &mut x) };
101
+ x
102
+ }
103
+
104
+ pub fn of_f32(src: i32) -> F80 {
105
+ let mut x = F80::ZERO;
106
+ unsafe { f32_to_extF80M(src, &mut x) };
107
+ x
108
+ }
109
+
110
+ pub fn of_f64(src: u64) -> F80 {
111
+ let mut x = F80::ZERO;
112
+ unsafe { f64_to_extF80M(src, &mut x) };
113
+ x
114
+ }
115
+ fn of_f64x(src: f64) -> F80 { F80::of_f64(f64::to_bits(src)) }
116
+
117
+ pub fn to_f32(&self) -> i32 { unsafe { extF80M_to_f32(self) } }
118
+ pub fn to_f64(&self) -> u64 { unsafe { extF80M_to_f64(self) } }
119
+ fn to_f64x(&self) -> f64 { f64::from_bits(self.to_f64()) }
120
+
121
+ pub fn to_i32(&self) -> i32 { unsafe { extF80M_to_i32(self, softfloat_roundingMode, false) } }
122
+ pub fn to_i64(&self) -> i64 { unsafe { extF80M_to_i64(self, softfloat_roundingMode, false) } }
123
+
124
+ pub fn truncate_to_i32(&self) -> i32 { unsafe { extF80M_to_i32(self, 1, false) } }
125
+ pub fn truncate_to_i64(&self) -> i64 { unsafe { extF80M_to_i64(self, 1, false) } }
126
+
127
+ pub fn cos(self) -> F80 { F80::of_f64x(self.to_f64x().cos()) }
128
+ pub fn sin(self) -> F80 { F80::of_f64x(self.to_f64x().sin()) }
129
+ pub fn tan(self) -> F80 { F80::of_f64x(self.to_f64x().tan()) }
130
+ pub fn atan(self) -> F80 { F80::of_f64x(self.to_f64x().atan()) }
131
+ pub fn atan2(self, other: F80) -> F80 { F80::of_f64x(self.to_f64x().atan2(other.to_f64x())) }
132
+
133
+ pub fn log2(self) -> F80 { F80::of_f64x(self.to_f64x().log2()) }
134
+ pub fn ln(self) -> F80 { F80::of_f64x(self.to_f64x().ln()) }
135
+
136
+ pub fn abs(self) -> F80 {
137
+ F80 {
138
+ mantissa: self.mantissa,
139
+ sign_exponent: self.sign_exponent & !0x8000,
140
+ }
141
+ }
142
+ pub fn two_pow(self) -> F80 { F80::of_f64x(2.0f64.powf(self.to_f64x())) }
143
+ pub fn round(self) -> F80 {
144
+ let mut result = F80::ZERO;
145
+ unsafe { extF80M_roundToInt(&self, softfloat_roundingMode, false, &mut result) };
146
+ result
147
+ }
148
+ pub fn trunc(self) -> F80 {
149
+ let mut result = F80::ZERO;
150
+ unsafe { extF80M_roundToInt(&self, 1, false, &mut result) };
151
+ result
152
+ }
153
+
154
+ pub fn sqrt(self) -> F80 {
155
+ let mut result = F80::ZERO;
156
+ unsafe { extF80M_sqrt(&self, &mut result) };
157
+ result
158
+ }
159
+
160
+ pub fn is_finite(self) -> bool {
161
+ // TODO: Can probably be done more efficiently
162
+ self != F80::POS_INFINITY && self != F80::NEG_INFINITY
163
+ }
164
+ pub fn is_nan(self) -> bool {
165
+ // TODO: Can probably be done more efficiently
166
+ self != self
167
+ }
168
+
169
+ pub fn set_rounding_mode(mode: RoundingMode) {
170
+ unsafe {
171
+ softfloat_roundingMode = match mode {
172
+ RoundingMode::NearEven => 0,
173
+ RoundingMode::Trunc => 1,
174
+ RoundingMode::Floor => 2,
175
+ RoundingMode::Ceil => 3,
176
+ }
177
+ };
178
+ }
179
+ pub fn set_precision(precision: Precision) {
180
+ unsafe {
181
+ extF80_roundingPrecision = match precision {
182
+ Precision::P80 => 80,
183
+ Precision::P64 => 64,
184
+ Precision::P32 => 32,
185
+ }
186
+ };
187
+ }
188
+
189
+ pub fn get_exception_flags() -> u8 {
190
+ let f = unsafe { softfloat_exceptionFlags };
191
+ // translate softfloat's flags to x87 status flags
192
+ f >> 4 & 1 | f >> 1 & 4 | f << 3 & 16
193
+ }
194
+ pub fn clear_exception_flags() { unsafe { softfloat_exceptionFlags = 0 } }
195
+
196
+ pub fn partial_cmp_quiet(&self, other: &Self) -> Option<std::cmp::Ordering> {
197
+ // TODO: Can probably be done more efficiently
198
+ if unsafe { extF80M_lt_quiet(self, other) } {
199
+ Some(std::cmp::Ordering::Less)
200
+ }
201
+ else if unsafe { extF80M_lt_quiet(other, self) } {
202
+ Some(std::cmp::Ordering::Greater)
203
+ }
204
+ else if self == other {
205
+ Some(std::cmp::Ordering::Equal)
206
+ }
207
+ else {
208
+ None
209
+ }
210
+ }
211
+ }
212
+
213
+ impl std::ops::Add for F80 {
214
+ type Output = F80;
215
+ fn add(self, other: Self) -> Self {
216
+ let mut result = F80::ZERO;
217
+ unsafe { extF80M_add(&self, &other, &mut result) };
218
+ result
219
+ }
220
+ }
221
+ impl std::ops::Sub for F80 {
222
+ type Output = F80;
223
+ fn sub(self, other: Self) -> Self {
224
+ let mut result = F80::ZERO;
225
+ unsafe { extF80M_sub(&self, &other, &mut result) };
226
+ result
227
+ }
228
+ }
229
+ impl std::ops::Neg for F80 {
230
+ type Output = F80;
231
+ fn neg(self) -> Self {
232
+ let mut result = self;
233
+ result.sign_exponent ^= 1 << 15;
234
+ result
235
+ }
236
+ }
237
+ impl std::ops::Mul for F80 {
238
+ type Output = F80;
239
+ fn mul(self, other: Self) -> Self {
240
+ let mut result = F80::ZERO;
241
+ unsafe { extF80M_mul(&self, &other, &mut result) };
242
+ result
243
+ }
244
+ }
245
+ impl std::ops::Div for F80 {
246
+ type Output = F80;
247
+ fn div(self, other: Self) -> Self {
248
+ let mut result = F80::ZERO;
249
+ unsafe { extF80M_div(&self, &other, &mut result) };
250
+ result
251
+ }
252
+ }
253
+ impl std::ops::Rem for F80 {
254
+ type Output = F80;
255
+ fn rem(self, other: Self) -> Self {
256
+ let quot = (self / other).trunc();
257
+ self - quot * other
258
+ // Uses round-to-nearest instead of truncation
259
+ //let mut result = F80::ZERO;
260
+ //unsafe {
261
+ // extF80M_rem(&self, &other, &mut result)
262
+ //};
263
+ //result
264
+ }
265
+ }
266
+
267
+ impl PartialEq for F80 {
268
+ fn eq(&self, other: &Self) -> bool { unsafe { extF80M_eq(self, other) } }
269
+ }
270
+ impl PartialOrd for F80 {
271
+ fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
272
+ // TODO: Can probably be done more efficiently
273
+ if unsafe { extF80M_lt(self, other) } {
274
+ Some(std::cmp::Ordering::Less)
275
+ }
276
+ else if unsafe { extF80M_lt(other, self) } {
277
+ Some(std::cmp::Ordering::Greater)
278
+ }
279
+ else if self == other {
280
+ Some(std::cmp::Ordering::Equal)
281
+ }
282
+ else {
283
+ None
284
+ }
285
+ }
286
+ }
@@ -0,0 +1,27 @@
1
+ #[derive(Copy, Clone, PartialEq, Eq)]
2
+ #[repr(transparent)]
3
+ pub struct CachedStateFlags(u8);
4
+
5
+ impl CachedStateFlags {
6
+ const MASK_IS_32: u8 = 1 << 0;
7
+ const MASK_SS32: u8 = 1 << 1;
8
+ const MASK_CPL3: u8 = 1 << 2;
9
+ const MASK_FLAT_SEGS: u8 = 1 << 3;
10
+
11
+ pub const EMPTY: CachedStateFlags = CachedStateFlags(0);
12
+
13
+ pub fn of_u32(f: u32) -> CachedStateFlags {
14
+ dbg_assert!(
15
+ f as u8
16
+ & !(Self::MASK_IS_32 | Self::MASK_SS32 | Self::MASK_CPL3 | Self::MASK_FLAT_SEGS)
17
+ == 0
18
+ );
19
+ CachedStateFlags(f as u8)
20
+ }
21
+ pub fn to_u32(&self) -> u32 { self.0 as u32 }
22
+
23
+ pub fn cpl3(&self) -> bool { self.0 & CachedStateFlags::MASK_CPL3 != 0 }
24
+ pub fn has_flat_segmentation(&self) -> bool { self.0 & CachedStateFlags::MASK_FLAT_SEGS != 0 }
25
+ pub fn is_32(&self) -> bool { self.0 & CachedStateFlags::MASK_IS_32 != 0 }
26
+ pub fn ssize_32(&self) -> bool { self.0 & CachedStateFlags::MASK_SS32 != 0 }
27
+ }
@@ -0,0 +1,2 @@
1
+ pub mod wasm_builder;
2
+ mod wasm_opcodes;