Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@folkertdev
folkertdev / generate.sh
Created July 6, 2026 20:33
C test case generation
#!/usr/bin/env bash
set -euo pipefail
file=${1:?usage: ./normalize-checks.sh FILE}
python3 ~/c/llvm-project/llvm/utils/update_cc_test_checks.py --clang=clang --filter-out ".*" "$file"
vim -Nu NONE -n -es "$file" <<'VIM'
g/-SAME:/s/\v^(.*\)).*/\1/
%s#// \(.\{-}\)-LABEL: \(.*\)\n// \1-SAME: \(.*\)#// \1: \2\3#
@folkertdev
folkertdev / adler32_lsx.rs
Created June 28, 2026 12:24
adler32 lsx version that miri can run
//! # Safety
//!
//! The functions in this module should only be executed on loongarch machines with the LSX
//! extension.
use core::arch::loongarch64::{
lsx_vadd_h, lsx_vadd_w, lsx_vinsgr2vr_w, lsx_vmadd_w, lsx_vpickve2gr_w, lsx_vslli_w, m128i,
};
use crate::adler32::{
generic::{adler32_len_1, adler32_len_16},
@folkertdev
folkertdev / quote_reduced.ll
Created June 11, 2026 15:41
A .ll file that hits `error: out of range PC16 fixup` when compiled with `llc -relocation-model=pic -O0 -mcpu=mips64r5 -filetype=obj quote_reduced.ll`
This file has been truncated, but you can view the full file.
; ModuleID = 'quote.ll'
source_filename = "proc_macro.34046a418b4d3184-cgu.0"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "mips64el-unknown-linux-gnuabi64"
%TokenTree = type { [16 x i8], i8, [3 x i8] }
@alloc_914b2c69d7eca30497b9feaf15ac92f1 = external hidden unnamed_addr constant [1 x i8], align 1
@alloc_dda1ee2b88b89b9cdac753eef7988035 = external hidden unnamed_addr constant [1 x i8], align 1
@alloc_00ae4b301f7fab8ac9617c03fcbd7274 = external hidden unnamed_addr constant [43 x i8], align 1
@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