Skip to content

Instantly share code, notes, and snippets.

{
"cult":{
"version":"0.0.1",
"cpu":"Intel(R) Core(TM) i7-5557U CPU@3.10GHz"},
"cpuid":[
{"level":"00000000","subleaf":"00000000","eax":"00000014","ebx":"756E6547","ecx":"6C65746E","edx":"49656E69"},
{"level":"00000001","subleaf":"00000000","eax":"000306D4","ebx":"00100800","ecx":"7FFAFBBF","edx":"BFEBFBFF"},
{"level":"00000002","subleaf":"00000000","eax":"76036301","ebx":"00F0B5FF","ecx":"00000000","edx":"00C30000"},
{"level":"00000003","subleaf":"00000000","eax":"00000000","ebx":"00000000","ecx":"00000000","edx":"00000000"},
{"level":"00000004","subleaf":"00000000","eax":"1C004121","ebx":"01C0003F","ecx":"0000003F","edx":"00000000"},
benchmark | system | opt | runtime | instret
-------------- | -------------- | -- | ------- | -------
aes | rv-hist-riscv32 | O3 | 189.058 | 4617934394
aes | rv-hist-riscv32 | Os | 183.126 | 4445968109
aes | rv-hist-riscv64 | O3 | 213.185 | 5205137133
aes | rv-hist-riscv64 | Os | 215.497 | 5081405284
aes | rv-sim-riscv32 | O3 | 66.627 | 4617934394
aes | rv-sim-riscv32 | O3 | 66.596 | 4617934394
aes | rv-sim-riscv32 | O3 | 66.35 | 4617934394
aes | rv-sim-riscv32 | O3 | 66.459 | 4617934394
@larkmjc
larkmjc / sample-riscv-decoding-notation
Last active August 19, 2017 07:40
Sample RISC-V instruction decoding notation
u : { [31:12], [11:7] } -> { simm[31:12], rd[4:0] }
uj : { [31:12], [11:7] } -> { simm[20|10:1|11|19:12], rd[4:0] }
i : { [31:20], [19:15], [11:7] } -> { simm[11:0], rs1[4:0], rd[4:0] }
i_sh5 : { [24:20], [19:15], [11:7] } -> { imm[4:0], rs1[4:0], rd[4:0] }
i_sh6 : { [25:20], [19:15], [11:7] } -> { imm[5:0], rs1[4:0], rd[4:0] }
i_sh7 : { [26:20], [19:15], [11:7] } -> { imm[6:0], rs1[4:0], rd[4:0] }
i_csr : { [31:20], [19:15], [11:7] } -> { imm[11:0], rs1[4:0], rd[4:0] }
s : { [24:20], [19:15], [11:7] } -> { simm[11:5], rs2[4:0], rs1[4:0], simm[4:0] }
sb : { [24:20], [19:15], [11:7] } -> { simm[12|10:5], rs2[4:0], rs1[4:0],
@larkmjc
larkmjc / riscv-rvc-register-usage-histogram
Last active August 26, 2017 07:47
RISC-V RVC register usage histogram
NOTE: - indicates RVC accesible register
register usage histogram (gcc 7.0.1 20170321 experimental) -Os newlib
~~~~~~~~~~~~~~~~~~~~~~~~
1. a5 15.12% [1711277823] ---------------------------------------
2. a2 13.64% [1543505068] -----------------------------------
3. a7 10.38% [1174405192] ==========================
4. a4 8.95% [1012926250] -----------------------
5. a6 7.77% [878706830] ====================
6. t4 5.30% [599785556] =============
@larkmjc
larkmjc / misaligned_atomics.c
Last active October 23, 2024 01:21
Demonstrates torn loads for misaligned atomics
#include <stdio.h>
#include <stdlib.h>
#include <stdatomic.h>
#include <limits.h>
#include <pthread.h>
/*
* Intel® 64 and IA-32 Architectures Software Developer’s Manual
*
* Volume 3A - 8.1.1 Guaranteed Atomic Operations
--- linux-4.19-rc8.orig/arch/riscv/kernel/setup.c 2018-10-15 18:20:24.000000000 +1300
+++ linux-4.19-rc8/arch/riscv/kernel/setup.c 2018-10-19 00:25:54.571772704 +1300
@@ -227,7 +227,9 @@
setup_bootmem();
paging_init();
unflatten_device_tree();
+#ifdef CONFIG_SWIOTLB
swiotlb_init(1);
+#endif
@larkmjc
larkmjc / intersection.patch
Created February 26, 2020 21:36
Perform 2D rectangle intersection test and return topology classes
commit ac3c81578e760af11732da8f925b87ba7b1f70be
Author: Michael Clark <michaeljclark@mac.com>
Date: Tue Feb 25 10:45:10 2020 +1300
Perform 2D rectangle intersection test and return topology classes
diff --git a/src/geometry.h b/src/geometry.h
new file mode 100644
index 000000000000..1b5d890c2f58
--- /dev/null
@larkmjc
larkmjc / ftkitty.cc
Last active October 30, 2020 04:43
ftkitty rasterizes text using FreeType and HarfBuzz and outputs using kitty image protocol
/*
* ftkitty - program that outputs text using kitty image protocol
*
* meet `ftkitty`, a tiny example emitting graphics to the terminal
* using #FreeType, #HarfBuzz, and the #kitty graphics protocol.
* this is possible with ImageMagick and icat, but ftkitty is smaller
* and mostly it's just an experiment with terminal protocols.
*
* g++ -O2 examples/ftkitty.cc $(pkg-config --libs freetype2 --libs harfbuzz
* --cflags freetype2 --cflags harfbuzz) -o build/ftkitty
@larkmjc
larkmjc / workmule.cc
Last active November 11, 2020 19:03
C++ threaded worker pool that executes work-items from a queue
// See LICENSE for license details.
#include <vector>
#include <atomic>
#include <thread>
#include <mutex>
#include <memory>
#include <functional>
#include <condition_variable>
@larkmjc
larkmjc / please-license.c
Created November 21, 2020 08:15
PLEASE LICENSE is a software license somewhere in between the ISC license and public domain.
/*
* PLEASE LICENSE 11/2020, John Smith <john.smith@example.com>
*
* All rights to this work are granted for all purposes, with exception of
* author's implied right of copyright to defend the free use of this work.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES