@specy/risc-v 3.3.1 → 3.4.1

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/dist/index.d.mts CHANGED
@@ -350,6 +350,20 @@ declare enum RISCVRegisters {
350
350
  }
351
351
  type RegisterName = keyof typeof RISCVRegisters;
352
352
  declare const RISCV_REGISTERS: RegisterName[];
353
+ /**
354
+ * The floating point registers, in the order `getFloatingPointRegistersValues` returns them, which
355
+ * is the order the core holds them in: register number 0 to 31, spelled as RARS spells them.
356
+ */
357
+ declare const RISCV_FLOATING_POINT_REGISTERS: readonly ["ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", "fs0", "fs1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"];
358
+ type FloatingPointRegisterName = typeof RISCV_FLOATING_POINT_REGISTERS[number];
359
+ /**
360
+ * The control and status registers the core implements, in the order
361
+ * `getControlAndStatusRegistersValues` returns them. `fflags` and `frm` are windows onto `fcsr`,
362
+ * and `cycleh`, `timeh` and `instreth` are the high halves of `cycle`, `time` and `instret`, so
363
+ * those pairs always agree.
364
+ */
365
+ declare const RISCV_CSR_REGISTERS: readonly ["ustatus", "fflags", "frm", "fcsr", "uie", "utvec", "uscratch", "uepc", "ucause", "utval", "uip", "cycle", "time", "instret", "cycleh", "timeh", "instreth"];
366
+ type CsrRegisterName = typeof RISCV_CSR_REGISTERS[number];
353
367
  type HandlerName = keyof HandlerMap;
354
368
  /**
355
369
  * A handler may return its result directly, or a promise of it. When a handler returns a promise
@@ -386,10 +400,6 @@ interface JsRiscV {
386
400
  * it settles once that handler and the rest of the instruction have finished.
387
401
  */
388
402
  step(): Promise<StopReason>;
389
- /**
390
- * Gets the 8 condition flags.
391
- */
392
- getConditionFlags(): number[];
393
403
  /**
394
404
  * Sets the size of the undo stack, must be called before assembling the program.
395
405
  * @param size
@@ -505,6 +515,47 @@ interface JsRiscV {
505
515
  * @returns An array containing the register values in long format. The order of the values is implementation defined.
506
516
  */
507
517
  getRegistersValuesLong(): string[];
518
+ /**
519
+ * Gets every floating point register as a high/low pair of 32 bit halves: element `2 * i` is
520
+ * the high half of register `i` and `2 * i + 1` its low half, so the array holds 64 numbers.
521
+ * The registers are in `RISCV_FLOATING_POINT_REGISTERS` order, and both halves matter on both
522
+ * targets: the file is 64 bit wide even on RV32, where a single is NaN-boxed into it (its high
523
+ * half is `0xFFFFFFFF`).
524
+ *
525
+ * The core hands this over as an `Int32Array` of signed 32 bit halves, so a half with its top
526
+ * bit set reads back negative: compose each pair with `highLowToBigint`, which takes both
527
+ * halves unsigned, rather than mapping `>>> 0` over the array (a typed array's `map` truncates
528
+ * the result back to int32, handing you the negative value again).
529
+ *
530
+ * Pairs rather than decimal strings because this is read on every panel refresh, and a 64 bit
531
+ * conversion per register is the kind of work that costs in the compiled core.
532
+ */
533
+ getFloatingPointRegistersValues(): Int32Array;
534
+ /**
535
+ * Sets one floating point register, writing it directly: no undo entry is recorded, because
536
+ * presetting a register from the host is not something the program did. Split the value with
537
+ * `bigintToHighLow`, and NaN-box a single yourself (`0xFFFFFFFFn << 32n | bits`) if that is
538
+ * what you mean.
539
+ * @param index Position in `RISCV_FLOATING_POINT_REGISTERS`. Must be a whole number from 0 to
540
+ * 31; anything else throws.
541
+ */
542
+ setFloatingPointRegisterValue(index: number, high: number, low: number): void;
543
+ /**
544
+ * Gets every control and status register as a high/low pair, in the same shape as
545
+ * `getFloatingPointRegistersValues`: an `Int32Array` of 34 signed halves for the 17 registers
546
+ * of `RISCV_CSR_REGISTERS`, to be composed with `highLowToBigint` for the same reason. The
547
+ * `cycle` and `instret` counters are settled first, so they count every instruction executed
548
+ * so far.
549
+ */
550
+ getControlAndStatusRegistersValues(): Int32Array;
551
+ /**
552
+ * Sets one control and status register, writing it directly and recording no undo entry.
553
+ * Writing `fflags` or `frm` updates `fcsr`, and writing a counter such as `cycle` is allowed
554
+ * here even though the program cannot write it.
555
+ * @param index Position in `RISCV_CSR_REGISTERS`. Must be a whole number from 0 to 16;
556
+ * anything else throws.
557
+ */
558
+ setControlAndStatusRegisterValue(index: number, high: number, low: number): void;
508
559
  /**
509
560
  * Gets the undo stack.
510
561
  * @returns An array of `JsBackStep` objects representing the history of the simulation.
@@ -611,5 +662,11 @@ declare function makeRiscVFromFiles(files: RISCVSourceSet, entryFile: string): J
611
662
  */
612
663
  declare function initializeRISCV(): void;
613
664
  declare function bigintToHighLow(value: bigint): [high: number, low: number];
665
+ /**
666
+ * The inverse of `bigintToHighLow`: composes the unsigned 64 bit value of a high/low pair, as the
667
+ * register file getters return them. Both halves are taken unsigned, so a half the core hands over
668
+ * as a negative int still lands in the right place.
669
+ */
670
+ declare function highLowToBigint(high: number, low: number): bigint;
614
671
 
615
- export { BackStepAction, ConfirmResult, DialogType, type HandlerMap, type HandlerMapFns, type JsBackStep, type JsInstruction, type JsInstructionToken, type JsProgramStatement, type JsRiscV, type JsRiscVStackFrame, type MemoryAccessObserver, type MemoryObserverHandle, type MemoryWriteObserver, RISCV, type RISCVAssembleError, type RISCVAssembleResult, RISCVRegisters, type RISCVSourceLocation, type RISCVSourceSet, RISCV_REGISTERS, type RegisterName, type RiscvTokenizedLine, StopReason, bigintToHighLow, makeRiscVFromFiles, registerHandlers, unimplementedHandler };
672
+ export { BackStepAction, ConfirmResult, type CsrRegisterName, DialogType, type FloatingPointRegisterName, type HandlerMap, type HandlerMapFns, type JsBackStep, type JsInstruction, type JsInstructionToken, type JsProgramStatement, type JsRiscV, type JsRiscVStackFrame, type MemoryAccessObserver, type MemoryObserverHandle, type MemoryWriteObserver, RISCV, type RISCVAssembleError, type RISCVAssembleResult, RISCVRegisters, type RISCVSourceLocation, type RISCVSourceSet, RISCV_CSR_REGISTERS, RISCV_FLOATING_POINT_REGISTERS, RISCV_REGISTERS, type RegisterName, type RiscvTokenizedLine, StopReason, bigintToHighLow, highLowToBigint, makeRiscVFromFiles, registerHandlers, unimplementedHandler };
package/dist/index.d.ts CHANGED
@@ -350,6 +350,20 @@ declare enum RISCVRegisters {
350
350
  }
351
351
  type RegisterName = keyof typeof RISCVRegisters;
352
352
  declare const RISCV_REGISTERS: RegisterName[];
353
+ /**
354
+ * The floating point registers, in the order `getFloatingPointRegistersValues` returns them, which
355
+ * is the order the core holds them in: register number 0 to 31, spelled as RARS spells them.
356
+ */
357
+ declare const RISCV_FLOATING_POINT_REGISTERS: readonly ["ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", "fs0", "fs1", "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", "fs10", "fs11", "ft8", "ft9", "ft10", "ft11"];
358
+ type FloatingPointRegisterName = typeof RISCV_FLOATING_POINT_REGISTERS[number];
359
+ /**
360
+ * The control and status registers the core implements, in the order
361
+ * `getControlAndStatusRegistersValues` returns them. `fflags` and `frm` are windows onto `fcsr`,
362
+ * and `cycleh`, `timeh` and `instreth` are the high halves of `cycle`, `time` and `instret`, so
363
+ * those pairs always agree.
364
+ */
365
+ declare const RISCV_CSR_REGISTERS: readonly ["ustatus", "fflags", "frm", "fcsr", "uie", "utvec", "uscratch", "uepc", "ucause", "utval", "uip", "cycle", "time", "instret", "cycleh", "timeh", "instreth"];
366
+ type CsrRegisterName = typeof RISCV_CSR_REGISTERS[number];
353
367
  type HandlerName = keyof HandlerMap;
354
368
  /**
355
369
  * A handler may return its result directly, or a promise of it. When a handler returns a promise
@@ -386,10 +400,6 @@ interface JsRiscV {
386
400
  * it settles once that handler and the rest of the instruction have finished.
387
401
  */
388
402
  step(): Promise<StopReason>;
389
- /**
390
- * Gets the 8 condition flags.
391
- */
392
- getConditionFlags(): number[];
393
403
  /**
394
404
  * Sets the size of the undo stack, must be called before assembling the program.
395
405
  * @param size
@@ -505,6 +515,47 @@ interface JsRiscV {
505
515
  * @returns An array containing the register values in long format. The order of the values is implementation defined.
506
516
  */
507
517
  getRegistersValuesLong(): string[];
518
+ /**
519
+ * Gets every floating point register as a high/low pair of 32 bit halves: element `2 * i` is
520
+ * the high half of register `i` and `2 * i + 1` its low half, so the array holds 64 numbers.
521
+ * The registers are in `RISCV_FLOATING_POINT_REGISTERS` order, and both halves matter on both
522
+ * targets: the file is 64 bit wide even on RV32, where a single is NaN-boxed into it (its high
523
+ * half is `0xFFFFFFFF`).
524
+ *
525
+ * The core hands this over as an `Int32Array` of signed 32 bit halves, so a half with its top
526
+ * bit set reads back negative: compose each pair with `highLowToBigint`, which takes both
527
+ * halves unsigned, rather than mapping `>>> 0` over the array (a typed array's `map` truncates
528
+ * the result back to int32, handing you the negative value again).
529
+ *
530
+ * Pairs rather than decimal strings because this is read on every panel refresh, and a 64 bit
531
+ * conversion per register is the kind of work that costs in the compiled core.
532
+ */
533
+ getFloatingPointRegistersValues(): Int32Array;
534
+ /**
535
+ * Sets one floating point register, writing it directly: no undo entry is recorded, because
536
+ * presetting a register from the host is not something the program did. Split the value with
537
+ * `bigintToHighLow`, and NaN-box a single yourself (`0xFFFFFFFFn << 32n | bits`) if that is
538
+ * what you mean.
539
+ * @param index Position in `RISCV_FLOATING_POINT_REGISTERS`. Must be a whole number from 0 to
540
+ * 31; anything else throws.
541
+ */
542
+ setFloatingPointRegisterValue(index: number, high: number, low: number): void;
543
+ /**
544
+ * Gets every control and status register as a high/low pair, in the same shape as
545
+ * `getFloatingPointRegistersValues`: an `Int32Array` of 34 signed halves for the 17 registers
546
+ * of `RISCV_CSR_REGISTERS`, to be composed with `highLowToBigint` for the same reason. The
547
+ * `cycle` and `instret` counters are settled first, so they count every instruction executed
548
+ * so far.
549
+ */
550
+ getControlAndStatusRegistersValues(): Int32Array;
551
+ /**
552
+ * Sets one control and status register, writing it directly and recording no undo entry.
553
+ * Writing `fflags` or `frm` updates `fcsr`, and writing a counter such as `cycle` is allowed
554
+ * here even though the program cannot write it.
555
+ * @param index Position in `RISCV_CSR_REGISTERS`. Must be a whole number from 0 to 16;
556
+ * anything else throws.
557
+ */
558
+ setControlAndStatusRegisterValue(index: number, high: number, low: number): void;
508
559
  /**
509
560
  * Gets the undo stack.
510
561
  * @returns An array of `JsBackStep` objects representing the history of the simulation.
@@ -611,5 +662,11 @@ declare function makeRiscVFromFiles(files: RISCVSourceSet, entryFile: string): J
611
662
  */
612
663
  declare function initializeRISCV(): void;
613
664
  declare function bigintToHighLow(value: bigint): [high: number, low: number];
665
+ /**
666
+ * The inverse of `bigintToHighLow`: composes the unsigned 64 bit value of a high/low pair, as the
667
+ * register file getters return them. Both halves are taken unsigned, so a half the core hands over
668
+ * as a negative int still lands in the right place.
669
+ */
670
+ declare function highLowToBigint(high: number, low: number): bigint;
614
671
 
615
- export { BackStepAction, ConfirmResult, DialogType, type HandlerMap, type HandlerMapFns, type JsBackStep, type JsInstruction, type JsInstructionToken, type JsProgramStatement, type JsRiscV, type JsRiscVStackFrame, type MemoryAccessObserver, type MemoryObserverHandle, type MemoryWriteObserver, RISCV, type RISCVAssembleError, type RISCVAssembleResult, RISCVRegisters, type RISCVSourceLocation, type RISCVSourceSet, RISCV_REGISTERS, type RegisterName, type RiscvTokenizedLine, StopReason, bigintToHighLow, makeRiscVFromFiles, registerHandlers, unimplementedHandler };
672
+ export { BackStepAction, ConfirmResult, type CsrRegisterName, DialogType, type FloatingPointRegisterName, type HandlerMap, type HandlerMapFns, type JsBackStep, type JsInstruction, type JsInstructionToken, type JsProgramStatement, type JsRiscV, type JsRiscVStackFrame, type MemoryAccessObserver, type MemoryObserverHandle, type MemoryWriteObserver, RISCV, type RISCVAssembleError, type RISCVAssembleResult, RISCVRegisters, type RISCVSourceLocation, type RISCVSourceSet, RISCV_CSR_REGISTERS, RISCV_FLOATING_POINT_REGISTERS, RISCV_REGISTERS, type RegisterName, type RiscvTokenizedLine, StopReason, bigintToHighLow, highLowToBigint, makeRiscVFromFiles, registerHandlers, unimplementedHandler };