Skip to content

Commit

Permalink
Rename instructions to cycles in wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Dec 17, 2024
1 parent 3f5753d commit 4d9907d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frontend/wasm/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type MessageFromWorkerType = { replyToId?: number } & (
{ type: "rttData", data: string } |
{ type: "lcdSleeping", data: boolean } |
{ type: "cpuSleeping", data: boolean } |
{ type: "performance", data: { loopTime: number, ips: number, totalSRAM: number, pins: number } } |
{ type: "performance", data: { loopTime: number, cps: number, totalSRAM: number, pins: number } } |
{ type: "backupData", data: ArrayBuffer } |
{ type: "commandOutput", data: string } |
{ type: "aborted", data: any }
Expand Down
10 changes: 6 additions & 4 deletions frontend/wasm/src/components/Emulator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template(v-if="!isReady")
.form-check.form-switch
input.form-check-input(type="checkbox" v-model="turboMode" id="turboMode")
label.form-check-label(for="turboMode") Turbo mode
div Instructions per second: {{ numberFmt.format(performance.ips.value.toFixed(0)) }}
div {{ numberFmt.format(performance.cps.value.toFixed(0)) }} Hz ({{speedPercentage.toFixed(0)}}%)
div Loop time: {{ performance.loopTime.value.toFixed(0) }} ms
div CPU: {{ isCpuSleeping ? "Sleeping" : "Running" }}
div RAM size: {{ numberFmt.format(performance.sramSize.value) }} bytes
Expand Down Expand Up @@ -70,7 +70,7 @@ template(v-if="!isReady")
</template>

<script lang="ts" setup>
import { onUnmounted, ref, watch } from "vue";
import { computed, onUnmounted, ref, watch } from "vue";
import MyWorker from "@/worker?worker";
Expand Down Expand Up @@ -126,11 +126,13 @@ function addConsoleLine(text: string, type: Line["type"]) {
}
const performance = {
ips: useAverage(1000),
cps: useAverage(1000),
loopTime: useAverage(1000),
sramSize: ref(0),
}
const speedPercentage = computed(() => performance.cps.value / 64000000 * 100);
const worker = new MyWorker();
onUnmounted(() => worker.terminate());
Expand Down Expand Up @@ -177,7 +179,7 @@ worker.onmessage = async (event) => {
break;
case "performance":
performance.ips.value = data.ips;
performance.cps.value = data.cps;
performance.loopTime.value = data.loopTime;
performance.sramSize.value = data.totalSRAM;
pins.value = data.pins;
Expand Down
14 changes: 7 additions & 7 deletions frontend/wasm/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Emulator {

private rttFoundBlock = false;

private instructionCount = 0;
private cycleCount = 0;

get isRunning() {
return !!this.runInterval;
Expand Down Expand Up @@ -119,14 +119,14 @@ class Emulator {
this.rttReadBuffer = numberToPointer(Module._malloc(this.rttReadBufferSize));
}

private doLoop(iterations: number) {
this.instructionCount += iterations;
return this.Module._pinetime_loop(this.pinetime, iterations);
private doLoop(cycles: number) {
this.cycleCount += cycles;
return this.Module._pinetime_loop(this.pinetime, cycles);
}

private run() {
const start = performance.now();
const instructionCountStart = this.instructionCount;
const cycleCountStart = this.cycleCount;
let screenUpdated = false;

if (this.turboMode) {
Expand All @@ -138,7 +138,7 @@ class Emulator {
}
}

if (this.instructionCount < 10000000 && !this.rttFoundBlock) {
if (this.cycleCount < 10000000 && !this.rttFoundBlock) {
this.rttFoundBlock = !!this.Module._rtt_find_control(this.rtt);
if (this.rttFoundBlock)
sendMessage("rttFound", undefined);
Expand Down Expand Up @@ -174,7 +174,7 @@ class Emulator {

sendMessage("performance", {
loopTime: end - start,
ips: (this.instructionCount - instructionCountStart) / ((end - start) / 1000),
cps: (this.cycleCount - cycleCountStart) / ((end - start) / 1000),
totalSRAM: this.Module._nrf52832_get_sram_size(this.nrf52),
pins: this.Module._pins_read_all(this.pins),
});
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set(SRC_FILES
pinetime.c
pins.c
program.c
scheduler.c
segger_rtt.c
ticker.c

Expand Down Expand Up @@ -63,6 +62,7 @@ set(SRC_NATIVE_FILES
main.c
pcap.c
runlog.c
scheduler.c
time.c
)

Expand Down
6 changes: 3 additions & 3 deletions src/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

#include <emscripten.h>

bool pinetime_loop(pinetime_t *pt, size_t n)
bool pinetime_loop(pinetime_t *pt, int cycles)
{
st7789_t *lcd = pinetime_get_st7789(pt);
size_t initial_write_count = st7789_get_write_count(lcd);

while (n--)
while (cycles > 0)
{
pinetime_step(pt);
cycles -= pinetime_step(pt);
}

return st7789_get_write_count(lcd) != initial_write_count;
Expand Down

0 comments on commit 4d9907d

Please sign in to comment.