Skip to content

Instantly share code, notes, and snippets.

View Rexicon226's full-sized avatar
💭
optimizing

David Rubin Rexicon226

💭
optimizing
View GitHub Profile
@Rexicon226
Rexicon226 / r43x6.zig
Created January 19, 2026 00:48
6 x 43-bit curve25519 implementation
const std = @import("std");
const V = @Vector(8, u64);
const S = @Vector(8, i64);
const u64x4 = @Vector(4, u64);
const avx512 = @import("src/curves/ed25519/avx512.zig");
extern fn @"llvm.x86.avx512.vpmadd52l.uq.512"(V, V, V) V;
extern fn @"llvm.x86.avx512.vpmadd52h.uq.512"(V, V, V) V;
@Rexicon226
Rexicon226 / pht.zig
Created January 4, 2026 10:29
Compile-time perfect hash table. Based off of: https://cmph.sourceforge.net/papers/esa09.pdf. Meant for low key amounts (<= ~32).
const std = @import("std");
/// A perfect hash table for N keys of the same `length`. Useful for public key maps.
fn pht(K: type, V: type, entries: []const struct { K, V }) type {
const LAMBDA = 5;
const table_len = entries.len;
const bucket_len = (table_len + LAMBDA - 1) / LAMBDA;
const window = 4;
const length = @typeInfo(std.meta.Child(K)).array.len;
@Rexicon226
Rexicon226 / benchmark.zig
Created November 28, 2025 04:54
RVV indexOfSentinel benchmark
const std = @import("std");
const iterations_per_byte = 1000;
const warmup_iterations = 10;
pub fn main() !void {
const allocator = std.heap.smp_allocator;
// Pin the process to a single core (1)
const cpu0001: std.os.linux.cpu_set_t = [1]usize{0b0001} ++ ([_]usize{0} ** (16 - 1));
const std = @import("std");
const el: u256 = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed;
const L = 1 * el;
fn heea(v: u256) struct { u128, u128 } {
std.debug.assert(len(L) == 253);
std.debug.assert(v < L);
std.debug.assert(v > 0);
From e9b300e1579d456fd307659f86d8ac0373a25fea Mon Sep 17 00:00:00 2001
From: David Rubin <david@vortan.dev>
Date: Wed, 5 Nov 2025 18:26:33 -0800
Subject: [PATCH] explicit `PROT_WRITE` in `zero_bss` is redundant
The `PAGE_WRITE` check already protects the `memset`.
The Zig compiler uses `memsz` to reserve virtual address
space that can be used by future updates, including
in non-writable sections such as `.text`.
const std = @import("std");
const Edwards25519 = std.crypto.ecc.Edwards25519;
export fn slow(s: *const [32]u8) bool {
Edwards25519.scalar.rejectNonCanonical(s.*) catch return false;
return true;
}
export fn fast(s: *const [32]u8) bool {
// If none of the top 4 bits are set, then the scalar fits into S \in [0, 2^252),
@Rexicon226
Rexicon226 / benchmark.zig
Last active August 15, 2025 07:03
countScalar benchmark
const std = @import("std");
const testing = std.testing;
const iterations_per_byte = 1000;
const warmup_iterations = 10;
pub fn main() !void {
const allocator = std.heap.smp_allocator;
// Pin the process to a single core (1)
diff --git a/lib/libtsan/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc b/lib/libtsan/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc
index 16b2a10d8b..6370e63ab6 100644
--- a/lib/libtsan/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc
+++ b/lib/libtsan/sanitizer_common/sanitizer_interceptors_ioctl_netbsd.inc
@@ -641,22 +641,6 @@ static void ioctl_table_fill() {
_(SPKRSETVOL, READ, sizeof(unsigned int));
#if defined(__x86_64__)
/* Entries from file: dev/nvmm/nvmm_ioctl.h */
- _(NVMM_IOC_CAPABILITY, WRITE, struct_nvmm_ioc_capability_sz);
- _(NVMM_IOC_MACHINE_CREATE, READWRITE, struct_nvmm_ioc_machine_create_sz);
@Rexicon226
Rexicon226 / bench.zig
Created August 3, 2025 01:13
RVV `indexOfSentinel` benchmark
const std = @import("std");
const iterations_per_byte = 1000;
const warmup_iterations = 10;
pub fn main() !void {
const allocator = std.heap.smp_allocator;
// Pin the process to a single core (1)
const cpu0001: std.os.linux.cpu_set_t = [1]usize{0b0001} ++ ([_]usize{0} ** (16 - 1));
@Rexicon226
Rexicon226 / benchmark.zig
Last active November 28, 2025 01:48
CRC-32C benchmark
const std = @import("std");
const Wrapper = @import("crc32c.zig").Wrapper;
const iterations_per_byte = 1000;
const warmup_iterations = 10;
pub fn main() !void {
const allocator = std.heap.smp_allocator;
// Pin the process to a single core (1)