Skip to content

Instantly share code, notes, and snippets.

View ClarkThan's full-sized avatar
😇

Clark Than ClarkThan

😇
View GitHub Profile
@ClarkThan
ClarkThan / riscv.md
Created March 2, 2023 04:29 — forked from cb372/riscv.md
Writing an OS in Rust to run on RISC-V

(This is a translation of the original article in Japanese by moratorium08.)

(UPDATE (22/3/2019): Added some corrections provided by the original author.)

Writing your own OS to run on a handmade CPU is a pretty ambitious project, but I've managed to get it working pretty well so I'm going to write some notes about how I did it.

@ClarkThan
ClarkThan / CoC.ml
Created February 27, 2023 03:16 — forked from Hirrolot/CoC.ml
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@ClarkThan
ClarkThan / binned_allocator.zig
Created February 3, 2023 04:37 — forked from silversquirl/binned_allocator.zig
A fast, simple allocator for Zig
const std = @import("std");
const builtin = @import("builtin");
pub const Config = struct {
/// Whether to synchronize usage of this allocator.
/// For actual thread safety, the backing allocator must also be thread safe.
thread_safe: bool = !builtin.single_threaded,
/// Whether to warn about leaked memory on deinit.
/// This reporting is extremely limited; for proper leak checking use GeneralPurposeAllocator.
@ClarkThan
ClarkThan / CoC.ml
Created December 13, 2022 09:24 — forked from Hirrolot/CoC.ml
Barebones lambda cube in OCaml
type binder = Lam | Pi
(* The syntax of our calculus. Notice that types are represented in the same way
as terms, which is the essence of CoC. *)
type term =
| Var of string
| Appl of term * term
| Binder of binder * string * term * term
| Star
| Box
@ClarkThan
ClarkThan / lib.rs
Created August 7, 2022 08:25 — forked from Measter/lib.rs
Rust Perf Benchmark
#![feature(test)]
extern crate test;
#[cfg(test)]
mod tests {
use super::*;
use std::fs::{File};
use std::io::{BufWriter, Write, BufRead, BufReader};
#[bench]
@ClarkThan
ClarkThan / tucan_bibliography.md
Created July 13, 2022 04:53 — forked from mrnugget/tucan_bibliography.md
Tucan Bibliography. Majority of the resources I used to build Tucan, my toy optimizing compiler in Rust

Tucan - Bibliography

Majority of the resources I used to build Tucan, my toy optimizing compiler in Rust. This list is not complete but most of the things listed here are things I really read through and used.

Books

  • Engineering a compiler (I use this a lot! For SSA, dominance and optimizations)
  • [Static Single Assignment Book][ssabook] (I use this a lot!)
  • Types And Programming Languages
@ClarkThan
ClarkThan / latency.txt
Created June 13, 2022 09:23 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@ClarkThan
ClarkThan / Quirks of C.md
Created June 13, 2022 09:20 — forked from fay59/Quirks of C.md
Quirks of C

Here's a list of mildly interesting things about the C language that I learned mostly by consuming Clang's ASTs. Although surprises are getting sparser, I might continue to update this document over time.

There are many more mildly interesting features of C++, but the language is literally known for being weird, whereas C is usually considered smaller and simpler, so this is (almost) only about C.

1. Combined type and variable/field declaration, inside a struct scope [https://godbolt.org/g/Rh94Go]

struct foo {
   struct bar {
 int x;