Skip to content

Instantly share code, notes, and snippets.

View nmoinvaz's full-sized avatar

Nathan Moinvaziri nmoinvaz

  • Phoenix, United States
View GitHub Profile
@nmoinvaz
nmoinvaz / deflate_sym_macros.h
Created February 11, 2026 21:51
Zlib-ng deflate symbol macros
/* ===========================================================================
* Symbol buffer write/read macros.
*
* The symbol buffer stores literal and distance/length pairs. The storage
* format differs based on LIT_MEM (separate buffers) vs sym_buf (interleaved),
* and on whether the platform supports fast unaligned 32-bit access
* (OPTIMAL_CMP >= 32), which allows packing a 3-byte symbol into a single
* 32-bit write/read.
*
* SYM_WRITE_LIT and SYM_WRITE_DIST write a symbol and advance sym_next.
@nmoinvaz
nmoinvaz / comparebench.py
Last active February 8, 2026 07:04
Deflatebench comparison
import re, sys
def parse_results(path):
results = {}
with open(path) as f:
for line in f:
m = re.match(r'\s+(\d+|avg\d?)\s', line)
if not m:
continue
level = m.group(1)
@nmoinvaz
nmoinvaz / benchmark.yml
Last active February 8, 2026 06:51
Zlib-ng benchmark workflow
name: Benchmark
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to benchmark (results posted as PR comment)'
required: false
type: number
@nmoinvaz
nmoinvaz / functable_part.c
Created February 2, 2026 01:57
Zlib-ng functable without fallbacks
// Set up generic C code fallbacks
#ifndef WITH_ALL_FALLBACKS
// Only use necessary generic functions when no suitable simd versions are available.
// These conditions mirror the native_* defines in arch/*_functions.h headers.
# if (defined(X86_SSE2) && defined(__SSE2__)) || (defined(ARCH_X86) && defined(ARCH_64BIT))
ft.adler32 = &adler32_c;
ft.adler32_copy = &adler32_copy_c;
ft.crc32 = &crc32_braid;
ft.crc32_copy = &crc32_copy_braid;
@nmoinvaz
nmoinvaz / benchmark_tally.cc
Created February 1, 2026 01:10
Zlib-ng benchmark for deflate tallying
/* benchmark_tally.cc -- benchmark sym_buf read/write strategies
* Copyright (C) 2024 zlib-ng contributors
* For conditions of distribution and use, see copyright notice in zlib.h
*
* Compares:
* 1. LIT_MEM (separate d_buf/l_buf arrays)
* 2. sym_buf with zng_memread_4/zng_memwrite_4 (batched)
* 3. sym_buf with byte-by-byte access (original)
*/
@nmoinvaz
nmoinvaz / quick-bench-count-matches.cc
Last active January 26, 2026 04:06
Benchmark count matching bytes
#include <benchmark/benchmark.h>
#include <cstdint>
static inline uint32_t count_matching_bytes_ctzll(uint64_t mask) {
return __builtin_ctzll(mask);
}
static inline uint32_t count_matching_bytes_ctz32(uint64_t mask) {
uint32_t lo = (uint32_t)mask;
if (lo)
@nmoinvaz
nmoinvaz / benchmark_crc32_tail_copy.cc
Last active January 26, 2026 03:26
Benchmark zlib crc32 tail copy
/* benchmark_crc32_tail_copy.cc -- benchmark different copy strategies for CRC32 tail handling
* Copyright (C) 2022 Nathan Moinvaziri
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <benchmark/benchmark.h>
#include <cstring>
#include <cstdint>
extern "C" {
@nmoinvaz
nmoinvaz / benchmark_tailcopy.cc
Last active January 26, 2026 02:14
Benchmark memory tail copying
/* benchmark_tailcopy.cc -- benchmark different copy strategies for tail handling
* Copyright (C) 2022 Nathan Moinvaziri
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <benchmark/benchmark.h>
#include <cstring>
#include <cstdint>
extern "C" {
@nmoinvaz
nmoinvaz / zlib-ng-2106-pr.md
Created January 17, 2026 01:50
Zlib-ng PR #2106 Benchmarks
OS: Darwin 24.6.0 Darwin Kernel Version 24.6.0: Wed Nov  5 21:28:03 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T8122 arm64
CPU: arm
Timing: Python perf_counter 
Levels: 0-9       
Runs: 70         Trim worst: 40        

Test 1

Develop

@nmoinvaz
nmoinvaz / launch.json
Last active January 8, 2026 23:16
zlib-ng launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "fuzzer_example_small",
"type": "lldb",
"request": "launch",