virtual-machine 0.7.2 → 0.7.5
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.
- package/README.md +1 -1
- package/build/{chunk-SWPU5PUE.mjs → chunk-QNHY4JET.mjs} +93 -30
- package/build/cli.js +134 -37
- package/build/index.d.ts +71 -17
- package/build/index.js +94 -31
- package/build/index.mjs +3 -3
- package/build/node-worker.js +82 -31
- package/build/{riscv_vm-P4HTJVQ6.mjs → riscv_vm-3VZO5RQ3.mjs} +3 -1
- package/build/worker.js +23 -23
- package/native/index.mjs +1 -0
- package/native/riscv-vm-native.darwin-arm64.node +0 -0
- package/native/riscv-vm-native.darwin-x64.node +0 -0
- package/native/riscv-vm-native.linux-arm64-gnu.node +0 -0
- package/native/riscv-vm-native.linux-arm64-musl.node +0 -0
- package/native/riscv-vm-native.linux-x64-gnu.node +0 -0
- package/native/riscv-vm-native.linux-x64-musl.node +0 -0
- package/native/riscv-vm-native.win32-x64-msvc.node +0 -0
- package/package.json +3 -2
package/build/index.d.ts
CHANGED
|
@@ -259,6 +259,14 @@ declare class WasmVm {
|
|
|
259
259
|
* This allows the browser to do partial texture uploads for better performance.
|
|
260
260
|
*/
|
|
261
261
|
get_gpu_dirty_rect(): Uint32Array | undefined;
|
|
262
|
+
/**
|
|
263
|
+
* Reset hart 0 to bare machine mode at the entry point.
|
|
264
|
+
*
|
|
265
|
+
* Benchmark workloads (see `bench_workload`) are M-mode programs; this
|
|
266
|
+
* undoes the S-mode boot setup that `new_with_harts` applies so they
|
|
267
|
+
* run exactly like under the native bench runner.
|
|
268
|
+
*/
|
|
269
|
+
reset_machine_mode(): void;
|
|
262
270
|
/**
|
|
263
271
|
* Check if cancellation has been requested.
|
|
264
272
|
*/
|
|
@@ -277,10 +285,14 @@ declare class WasmVm {
|
|
|
277
285
|
* Get a direct zero-copy view into the framebuffer in SharedArrayBuffer.
|
|
278
286
|
*
|
|
279
287
|
* This eliminates all memory copies by creating a Uint8Array view directly
|
|
280
|
-
* into
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
288
|
+
* into guest memory at the framebuffer offset. The browser can pass this
|
|
289
|
+
* directly to WebGPU's writeTexture for zero-copy rendering.
|
|
290
|
+
*
|
|
291
|
+
* Works in both memory modes:
|
|
292
|
+
* - SMP (SharedArrayBuffer): stable view into the SAB.
|
|
293
|
+
* - Single-hart (linear memory): view into WASM linear memory. This view
|
|
294
|
+
* is invalidated whenever WASM memory grows, so consume it immediately
|
|
295
|
+
* and call this again each frame (do not cache it JS-side).
|
|
284
296
|
*/
|
|
285
297
|
get_framebuffer_view(): Uint8Array | undefined;
|
|
286
298
|
/**
|
|
@@ -369,7 +381,11 @@ declare class WasmVm {
|
|
|
369
381
|
step(): boolean;
|
|
370
382
|
/**
|
|
371
383
|
* Push an input byte to the UART.
|
|
372
|
-
*
|
|
384
|
+
*
|
|
385
|
+
* In SMP mode there is a single shared input ring consumed by whichever
|
|
386
|
+
* hart runs the shell (the bus routes RBR/LSR reads of every hart,
|
|
387
|
+
* including hart 0, to the ring). Pushing to the local FIFO as well
|
|
388
|
+
* would duplicate the stream and leave stale bytes behind.
|
|
373
389
|
*/
|
|
374
390
|
input(byte: number): void;
|
|
375
391
|
/**
|
|
@@ -377,12 +393,22 @@ declare class WasmVm {
|
|
|
377
393
|
*/
|
|
378
394
|
is_smp(): boolean;
|
|
379
395
|
/**
|
|
380
|
-
* Execute up to N instructions
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
396
|
+
* Execute up to N instructions by looping `step()`.
|
|
397
|
+
*
|
|
398
|
+
* DEPRECATED for hot paths: prefer `run_batch`, which hoists device
|
|
399
|
+
* polling and CLINT sync out of the instruction loop and returns early
|
|
400
|
+
* on WFI. `step_n` keeps the historical contract that a return value
|
|
401
|
+
* less than `count` means the VM halted (it never stops early on WFI),
|
|
402
|
+
* which existing consumers rely on for halt detection.
|
|
384
403
|
*/
|
|
385
404
|
step_n(count: number): number;
|
|
405
|
+
/**
|
|
406
|
+
* Total retired guest instructions on hart 0.
|
|
407
|
+
*
|
|
408
|
+
* Unlike step counts, this reflects real instructions (superblock
|
|
409
|
+
* execution retires many instructions per step). Use for MIPS metrics.
|
|
410
|
+
*/
|
|
411
|
+
instret(): number;
|
|
386
412
|
/**
|
|
387
413
|
* Get the entry PC address for workers.
|
|
388
414
|
* This is the address where secondary harts should start executing.
|
|
@@ -423,6 +449,20 @@ declare class WasmVm {
|
|
|
423
449
|
* Get the number of harts configured.
|
|
424
450
|
*/
|
|
425
451
|
num_harts(): number;
|
|
452
|
+
/**
|
|
453
|
+
* Execute up to N instructions in a batch with device polling, CLINT
|
|
454
|
+
* sync, and RTC updates hoisted to chunk boundaries.
|
|
455
|
+
*
|
|
456
|
+
* This is the fast path for hart 0: the inner loop is a tight
|
|
457
|
+
* `cpu.step()` with no per-instruction bookkeeping. Interrupt latency
|
|
458
|
+
* is bounded by IRQ_SYNC_INTERVAL (shared-CLINT sync) and the CPU's own
|
|
459
|
+
* internal 256-instruction interrupt poll.
|
|
460
|
+
*
|
|
461
|
+
* Returns the number of dispatcher steps executed (superblocks count as
|
|
462
|
+
* one step; use `instret()` for true instruction counts). Returns early
|
|
463
|
+
* on halt or WFI so the JS caller can pace execution.
|
|
464
|
+
*/
|
|
465
|
+
run_batch(max_steps: number): number;
|
|
426
466
|
}
|
|
427
467
|
|
|
428
468
|
declare class WorkerState {
|
|
@@ -496,6 +536,15 @@ declare enum WorkerStepResult {
|
|
|
496
536
|
Wfi = 4,
|
|
497
537
|
}
|
|
498
538
|
|
|
539
|
+
/**
|
|
540
|
+
* Build a synthetic benchmark workload binary (see `bench` module).
|
|
541
|
+
*
|
|
542
|
+
* Load the returned bytes as a raw "kernel" via `WasmVm::new_with_harts`
|
|
543
|
+
* and drive it with `step_n`; read `instret()` for MIPS accounting.
|
|
544
|
+
* Available workloads: nop, prime, memcpy, spinlock, ecall.
|
|
545
|
+
*/
|
|
546
|
+
declare function bench_workload(name: string): Uint8Array;
|
|
547
|
+
|
|
499
548
|
/**
|
|
500
549
|
* Check interrupts for this hart using the shared CLINT.
|
|
501
550
|
*
|
|
@@ -519,6 +568,7 @@ interface InitOutput {
|
|
|
519
568
|
readonly memory: WebAssembly.Memory;
|
|
520
569
|
readonly __wbg_wasmvm_free: (a: number, b: number) => void;
|
|
521
570
|
readonly __wbg_workerstate_free: (a: number, b: number) => void;
|
|
571
|
+
readonly bench_workload: (a: number, b: number) => [number, number, number, number];
|
|
522
572
|
readonly wasmvm_allow_workers_to_start: (a: number) => void;
|
|
523
573
|
readonly wasmvm_clear_cancel: (a: number) => void;
|
|
524
574
|
readonly wasmvm_connect_webtransport: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
@@ -553,6 +603,7 @@ interface InitOutput {
|
|
|
553
603
|
readonly wasmvm_has_gpu_frame: (a: number) => number;
|
|
554
604
|
readonly wasmvm_inject_network_packet: (a: number, b: any) => number;
|
|
555
605
|
readonly wasmvm_input: (a: number, b: number) => void;
|
|
606
|
+
readonly wasmvm_instret: (a: number) => number;
|
|
556
607
|
readonly wasmvm_is_cancel_requested: (a: number) => number;
|
|
557
608
|
readonly wasmvm_is_external_network_connected: (a: number) => number;
|
|
558
609
|
readonly wasmvm_is_halted: (a: number) => number;
|
|
@@ -565,6 +616,8 @@ interface InitOutput {
|
|
|
565
616
|
readonly wasmvm_print_banner: (a: number) => void;
|
|
566
617
|
readonly wasmvm_print_status: (a: number, b: number, c: number) => void;
|
|
567
618
|
readonly wasmvm_request_cancel: (a: number) => void;
|
|
619
|
+
readonly wasmvm_reset_machine_mode: (a: number) => void;
|
|
620
|
+
readonly wasmvm_run_batch: (a: number, b: number) => number;
|
|
568
621
|
readonly wasmvm_send_d1_char: (a: number, b: number) => number;
|
|
569
622
|
readonly wasmvm_send_d1_key_event: (a: number, b: number, c: number) => number;
|
|
570
623
|
readonly wasmvm_send_key_event: (a: number, b: number, c: number) => number;
|
|
@@ -579,6 +632,7 @@ interface InitOutput {
|
|
|
579
632
|
readonly wasmvm_terminate_workers: (a: number) => void;
|
|
580
633
|
readonly wasmvm_uart_output_pending: (a: number) => number;
|
|
581
634
|
readonly worker_check_interrupts: (a: number, b: any) => bigint;
|
|
635
|
+
readonly worker_entry: (a: number, b: any, c: bigint) => void;
|
|
582
636
|
readonly workerstate_get_a0: (a: number) => bigint;
|
|
583
637
|
readonly workerstate_hart_id: (a: number) => number;
|
|
584
638
|
readonly workerstate_is_msip_pending: (a: number) => number;
|
|
@@ -586,13 +640,12 @@ interface InitOutput {
|
|
|
586
640
|
readonly workerstate_new: (a: number, b: any, c: bigint) => number;
|
|
587
641
|
readonly workerstate_step_batch: (a: number, b: number) => number;
|
|
588
642
|
readonly workerstate_step_count: (a: number) => bigint;
|
|
589
|
-
readonly
|
|
590
|
-
readonly
|
|
591
|
-
readonly
|
|
592
|
-
readonly
|
|
593
|
-
readonly
|
|
594
|
-
readonly
|
|
595
|
-
readonly wasm_bindgen__convert__closures_____invoke__h5006ec25729b138d: (a: number, b: number, c: any) => void;
|
|
643
|
+
readonly wasm_bindgen__convert__closures_____invoke__h10fd13f77519f00f: (a: number, b: number, c: any) => void;
|
|
644
|
+
readonly wasm_bindgen__closure__destroy__h98fb6f0c0578da12: (a: number, b: number) => void;
|
|
645
|
+
readonly wasm_bindgen__convert__closures_____invoke__h3c19a701e2fb4946: (a: number, b: number, c: any) => void;
|
|
646
|
+
readonly wasm_bindgen__closure__destroy__h1e8cf243a981f4cd: (a: number, b: number) => void;
|
|
647
|
+
readonly wasm_bindgen__convert__closures_____invoke__h6ce8d92453d66e1b: (a: number, b: number) => void;
|
|
648
|
+
readonly wasm_bindgen__convert__closures_____invoke__h1f45221b43ca80d0: (a: number, b: number) => void;
|
|
596
649
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
597
650
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
598
651
|
readonly __wbindgen_exn_store: (a: number) => void;
|
|
@@ -636,11 +689,12 @@ type __pkg_riscv_vm_WorkerState = WorkerState;
|
|
|
636
689
|
declare const __pkg_riscv_vm_WorkerState: typeof WorkerState;
|
|
637
690
|
type __pkg_riscv_vm_WorkerStepResult = WorkerStepResult;
|
|
638
691
|
declare const __pkg_riscv_vm_WorkerStepResult: typeof WorkerStepResult;
|
|
692
|
+
declare const __pkg_riscv_vm_bench_workload: typeof bench_workload;
|
|
639
693
|
declare const __pkg_riscv_vm_initSync: typeof initSync;
|
|
640
694
|
declare const __pkg_riscv_vm_worker_check_interrupts: typeof worker_check_interrupts;
|
|
641
695
|
declare const __pkg_riscv_vm_worker_entry: typeof worker_entry;
|
|
642
696
|
declare namespace __pkg_riscv_vm {
|
|
643
|
-
export { type __pkg_riscv_vm_InitInput as InitInput, type __pkg_riscv_vm_InitOutput as InitOutput, __pkg_riscv_vm_NetworkStatus as NetworkStatus, type __pkg_riscv_vm_SyncInitInput as SyncInitInput, __pkg_riscv_vm_WasmVm as WasmVm, __pkg_riscv_vm_WorkerState as WorkerState, __pkg_riscv_vm_WorkerStepResult as WorkerStepResult, __wbg_init as default, __pkg_riscv_vm_initSync as initSync, __pkg_riscv_vm_worker_check_interrupts as worker_check_interrupts, __pkg_riscv_vm_worker_entry as worker_entry };
|
|
697
|
+
export { type __pkg_riscv_vm_InitInput as InitInput, type __pkg_riscv_vm_InitOutput as InitOutput, __pkg_riscv_vm_NetworkStatus as NetworkStatus, type __pkg_riscv_vm_SyncInitInput as SyncInitInput, __pkg_riscv_vm_WasmVm as WasmVm, __pkg_riscv_vm_WorkerState as WorkerState, __pkg_riscv_vm_WorkerStepResult as WorkerStepResult, __pkg_riscv_vm_bench_workload as bench_workload, __wbg_init as default, __pkg_riscv_vm_initSync as initSync, __pkg_riscv_vm_worker_check_interrupts as worker_check_interrupts, __pkg_riscv_vm_worker_entry as worker_entry };
|
|
644
698
|
}
|
|
645
699
|
|
|
646
700
|
/**
|