Skip to content

Instantly share code, notes, and snippets.

View francisrstokes's full-sized avatar
🎥
Low Byte Productions on YouTube

Francis Stokes francisrstokes

🎥
Low Byte Productions on YouTube
View GitHub Profile
@francisrstokes
francisrstokes / risc-v-isa-ascii.txt
Created June 19, 2023 18:44
RISC-V Base Instruction Set v2.2 ASCII
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+------------------------------------------------------------------------------------------------+
| funct7 | rs2 | rs1 | funct3 | rd | opcode | R-type
| imm[11:0] | rs1 | funct3 | rd | opcode | I-type
| imm[11:5] | rs2 | rs1 | funct3 | imm[4:0] | opcode | S-type
| imm[12|10:5] | rs2 | rs1 | funct3 | imm[4:1|11] | opcode | B-type
| imm[31:12] | rd | opcode | U-type
| imm[20|10:1|11|19:12] | rd | opcode | J-type
+------------------------------------------------------------------------------------------------+
@francisrstokes
francisrstokes / machine.c
Created July 31, 2023 17:56
Simple State Machine Base
#include "machine.h"
void state_machine_step(state_machine_t* descriptor) {
state_transition_t* transition;
uint32_t current_state = *descriptor->state_index;
for (uint32_t i = 0; i < descriptor->num_transitions; i++) {
transition = &descriptor->transitions[i];
if ((transition->from_state == current_state) && (transition->condition(current_state))) {
descriptor->on_state_change(current_state, transition->to_state);
@francisrstokes
francisrstokes / fixcallgrind.py
Created December 13, 2023 08:34
Just a hacky script to fix the output of callgrid captures for Zig binaries
import re
import sys
import subprocess
callgrind_file = sys.argv[1]
executable_file = sys.argv[2]
if len(sys.argv) < 3:
print("Usage: fix-callgrind.py <callgrind file> <executable>")
sys.exit(1)