Skip to content

Instantly share code, notes, and snippets.

View folkertdev's full-sized avatar

Folkert de Vries folkertdev

View GitHub Profile
@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
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)
Building compiler artifacts (stage0 -> stage1, x86_64-unknown-linux-gnu)
Creating a sysroot for stage1 compiler (use `rustup toolchain link 'name' build/host/stage1`)
Building stage0 tool lld-wrapper (x86_64-unknown-linux-gnu)
Building stage1 library artifacts (x86_64-unknown-linux-gnu)
Building stage0 tool compiletest (x86_64-unknown-linux-gnu)
Testing stage1 compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu)
@folkertdev
folkertdev / stable-order.rs
Created August 2, 2024 08:36
two files where one has inconsistent ordering of the generated error messages
//@ needs-asm-support
//@ ignore-nvptx64
//@ ignore-spirv
#![feature(asm_const)]
use std::arch::{asm, global_asm};
// Const operands must be integers and must be constants.
@folkertdev
folkertdev / comparison.svg
Created June 26, 2024 08:50
implicit coordinates are relative zero
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@folkertdev
folkertdev / example.py
Created June 18, 2024 09:37
tsp async pyo3 experiment
from dataclasses import dataclass
import tsp_python
from tsp_python import AsyncStore, OwnedVid, ReceivedTspMessageVariant, FlatReceivedTspMessage
class ReceivedTspMessage:
@staticmethod
def from_flat(msg: FlatReceivedTspMessage):
match msg.variant:
case ReceivedTspMessageVariant.GenericMessage:
@folkertdev
folkertdev / main.rs
Created June 14, 2024 14:48
PEXT experiment for lzma/xz variable width integer decoding
pub fn decode2(buf: &[u8], size_max: usize, num: &mut u64) -> usize {
let number = unsafe { core::ptr::read_unaligned(buf.as_ptr().cast()) };
let bits = unsafe { core::arch::x86_64::_pext_u64(number, 0x7F7F_7F7F_7F7F_7F7Fu64) };
let bytes_used = (number & !0x7F7F_7F7F_7F7F_7F7Fu64).count_ones();
*num = bits | (buf[8] as u64) << 56;
(size_max > 0) as usize + bytes_used as usize
}