Skip to content

Instantly share code, notes, and snippets.

@wbrown
wbrown / cpu-comparison.md
Last active December 19, 2020 00:19
Comparison of Forth VM performance across CPUs
CPU ops/µs TDP (w) Core TDP/Core ghz hz/op op/µs/TDPc op/µs*core
Apple M1 1,241 20 4 5 2.8 2.25 310.25 4,964
Apple A12z 895 16 4 4 2.6 2.90 223.75 3,580
Ryzen 3950x 1,094 105 16 6.5 4.0 3.65 168.30 17,504
Intel i7-10700k 1,251 125 8 15.625 5.0 3.99 80.06 10,008
@wbrown
wbrown / gist:7534739
Last active December 28, 2015 17:19
LLVM's x86 code generation from the IR is very impressive in that it recognizes sub-blocks in common and does jumps to them.

Below is the handwritten LLVM IR for SP_2SWAP and SP_ROT

SP_2SWAP:

kernel.SP_2SWAP:
    ; swap top two pairs of elements on the stack
    ;   pop %eax
    ;   pop %ebx
    ;   pop %ecx
    ;   pop %edx
@wbrown
wbrown / stack-cc10.ll
Last active December 28, 2015 08:19
I am not sure why, but values that I push onto the stack are disappearing past the last value I pushed. Output:
; clouddrift:experiments wbrown$ lli-3.3 test.ll
; 10 --> @140734656409551
; 11 --> @140734656409550
; 12 --> @140734656409549
; @140734656409549 --> 12
; @140734656409550 --> 0
; @140734656409551 --> 0
%cell = type i64
@wbrown
wbrown / forth.ll
Created November 11, 2013 23:12
noreturn optimization issues
%pntr = type i64*
%int = type i64
%cell = type i64
%WORD = type void ()*
; *****************************************************************************
; stdlib functions
; *****************************************************************************
declare i32 @puts(i8*)
@wbrown
wbrown / bugpoint-reduced-simplified.ll
Created November 11, 2013 22:42
With noreturn added into the calls.
; ModuleID = 'bugpoint-reduced-simplified.bc'
target triple = "x86_64-apple-darwin13.0.0"
@valueString = internal constant [7 x i8] c"%llu\0D\0A\00"
@stackString = internal constant [13 x i8] c"%llu: %llu\0D\0A\00"
@heapPtr = weak global i64* null
@heapSize = weak global i64 0
@execIdx = weak global i64 0
@stackIdx = weak global i64 0
@currIns = weak global i64 0
@wbrown
wbrown / forth-opt.ll
Created November 11, 2013 20:29
Output of: `clouddrift:experiments wbrown$ opt-3.3 -std-link-opts -S` on https://github.com/ephsec/svforth/blob/master/experiments/forth.ll
; ModuleID = 'forth.ll'
@stackString = internal constant [13 x i8] c"%llu: %llu\0D\0A\00"
@heapPtr = internal unnamed_addr global i64* null
@heapSize = internal unnamed_addr global i1 false
@execIdx = internal unnamed_addr global i64 0
@stackIdx = internal unnamed_addr global i64 0
; Function Attrs: nounwind
declare i32 @printf(i8* nocapture, ...) #0
@wbrown
wbrown / function-from-heap.ll
Last active December 28, 2015 00:59
This LLVM IR shows the logic that is used to store function pointers in a global heap, which is then retrieved and cast as a function to be executed. It crashes right when it tries to execute the pointer.
; constants to help with multiplatform stuff
%pntr = type i64*
%cell = type i64
; for ease of debugging, allows us to print a value to stdout
@valueString = internal constant [7 x i8] c"%llu\0D\0A\00"
declare i32 @printf(i8*, ... )
define void @printValue32(i32 %value) {