Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@folkertdev
folkertdev / Cargo.toml
Created May 21, 2025 14:29
benchmark `compare256` performance
[package]
name = "compare256-benchmark"
version = "0.1.0"
edition = "2024"
[dev-dependencies]
divan = "0.1.21"
[[bench]]
name = "compare256"
@folkertdev
folkertdev / cortex-m-macro.rs
Created April 25, 2025 09:25
cfg macro example
#[unsafe(naked)]
extern "C" fn Reset() {
core::arch::naked_asm!(
// debug info
".cfi_sections .debug_frame",
".cfi_startproc",
// If enabled, initialise the SP. This is normally initialised by the CPU itself or by a
// bootloader, but some debuggers fail to set it when resetting the target, leading to
// stack corruptions.
#[cfg(feature = "set-sp")]
@folkertdev
folkertdev / main.rs
Created April 16, 2025 14:40
Profiling SIMD saturating subtract
const N: usize = 10000;
fn main() {
let mut args = std::env::args().skip(1); // skip the program name
// just get a bunch of arbitrary values cheaply
const INPUT: &[u8] = include_bytes!(
"/home/folkertdev/.cargo/registry/cache/github.com-1ecc6299db9ec823/clap-4.2.7.crate"
);
let (_, table, _) = unsafe { INPUT.align_to() };
@folkertdev
folkertdev / comrak_benchmark.rs
Created March 4, 2025 13:35
comrak_benchmark.rs
```rust
pub fn main() {
for _ in 0..100000 {
for email in INPUT {
let result = autolink_email(core::hint::black_box(email.as_bytes()));
}
}
}
const INPUT: &[&str] = &[
@folkertdev
folkertdev / cargo-config.toml
Created January 12, 2025 16:00
use of the `stfle` instruction for s390x targets, to get the extended facility list
[build]
target = "s390x-unknown-linux-gnu"
[target.s390x-unknown-linux-gnu]
# runner = "qemu-s390x -cpu max -L /usr/s390x-linux-gnu"
runner = "qemu-s390x -cpu qemu,vx=on,vxeh=on,vxeh2=off -L /usr/s390x-linux-gnu"
# runner = "qemu-s390x -cpu z10EC -L /usr/s390x-linux-gnu"
linker = "s390x-linux-gnu-gcc"
@folkertdev
folkertdev / input.c
Created November 27, 2024 20:42
pass_clang::remove-unused-function has encountered a bug
typedef unsigned char Bool;
typedef unsigned char UChar;
typedef int Int32;
typedef unsigned int UInt32;
#define True ((Bool)1)
#define BZ_X_MAGIC_1 10
typedef struct {
char *next_in;
}
bz_stream;
@folkertdev
folkertdev / gist:977183fb706b7693863bd7f358578292
Last active October 23, 2024 07:54
zlib-rs labeled match benchmarks

zlib-rs labeled match benchmarks

build the toolchain

A proof of concept implementation can be found at https://github.com/trifectatechfoundation/rust/tree/labeled-match. Build it with ./x build, and then set up the toolchain. Now cargo +stage1 build should use a compiler with labeled-match available.

run the benchmark

git clone https://github.com/trifectatechfoundation/zlib-rs.git
@folkertdev
folkertdev / bounds and overflow checks.md
Created August 27, 2024 12:05
effect of bounds and overflow checks in zlib-rs

Some further zlib-rs benchmarks using commit c9b7299fa81ca2a8448cbe3e96a42275c9b41b24

Bounds checks

Rust will panic when you try to index out of bounds

This check has a cost: your CPU must perform this check. Typically this involves two instructions: a compare "is the index in bounds" and a jump "go to the panic code". Hence, we intuitively expect programs that perform bounds checking to be slightly slower. In theory, C has an edge here because it does not, by default, check that array access is in bounds.

@folkertdev
folkertdev / blogpost-compress.rs
Created August 8, 2024 10:04
benchmark for measuring zlib-rs versus zlib-ng compression performance
use std::ffi::{c_int, c_uint};
// we use the libz_sys but configure zlib-ng in zlib compat mode
use libz_sys as libz_ng_sys;
use zlib_rs::{DeflateFlush, ReturnCode};
fn main() {
let mut it = std::env::args();
Finished `dev` profile [unoptimized] target(s) in 0.05s
WARNING: The `change-id` is missing in the `config.toml`. This means that you will not be able to track the major changes made to the bootstrap configurations.
NOTE: to silence this warning, add `change-id = 127866` at the top of `config.toml`
Building stage0 library artifacts (x86_64-unknown-linux-gnu)
Finished `release` profile [optimized + debuginfo] target(s) in 0.11s
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
Finished `release` profile [optimized + debuginfo] target(s) in 0.19s
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage0 tool lld-wrapper (x86_64-unknown-linux-gnu)
Finished `release` profile [optimized + debuginfo] target(s) in 0.10s