Skip to content

Instantly share code, notes, and snippets.

View nmoinvaz's full-sized avatar

Nathan Moin Vaziri nmoinvaz

  • Los Angeles, California
View GitHub Profile
@nmoinvaz
nmoinvaz / zlib-ng-2247-results.md
Created July 28, 2026 19:18
zlib-ng PR #2247 — inflate lenbits 10 to 11, measured on Apple M5

zlib-ng PR #2247 — inflate lenbits 10 to 11, measured

Rebased onto upstream/develop (6cfa7d52) and re-measured. Upstream has since introduced MAX_LEN_ROOT_BITS, so the change is now a one-macro bump plus ENOUGH_LENS, with a second commit adding an adaptive gate.

Machine

Apple M5, 4 P-cores + 6 E-cores, 32 GB, macOS 26.5.2, Apple clang 21.0.0. Release build, BUILD_SHARED_LIBS=OFF, WITH_MAINTAINER_WARNINGS=ON.

@nmoinvaz
nmoinvaz / zlib-ng-benchmark_compress_block.cc
Last active July 16, 2026 23:19
zlib-ng: isolating compress_block to measure zng_emit_dist (PR #2363 vs #2364, Apple M5)
/* benchmark_compress_block.cc -- benchmark the compress_block emit loop in isolation
* Copyright (C) 2026 Nathan Moinvaziri
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <stdio.h>
#include <cstring>
#include <benchmark/benchmark.h>
@nmoinvaz
nmoinvaz / zlib-ng-compress-block-literal-batching.md
Last active July 17, 2026 02:27
zlib-ng: batching literals in compress_block (1% to 4.5% faster deflate, Apple M5)

zlib-ng: batching literals in compress_block

Packing up to 3 consecutive literals into a single send_bits makes deflate 1% to 4.5% faster on most data types, with byte-identical output and no regressions.

The idea

compress_block emits one symbol at a time. Each symbol ORs its Huffman code into the 64-bit bit buffer at the running bit position, then updates that position. bi_buf/bi_valid are therefore a loop-carried dependency: symbol N+1 cannot be placed until symbol N's length is known. That chain,

@nmoinvaz
nmoinvaz / zlib-ng-pr1977-adler32-copy-avx2vnni-4accumulator-README.md
Created July 3, 2026 03:10
zlib-ng PR #1977 follow-up: enable adler32_copy_avx2_vnni with unroll x4 / four VPDPBUSD accumulators to pop the data-dependency bubble (checksum bit-exact + spill-free; not yet benchmarked)

zlib-ng — adler32 AVX2-VNNI copy: unroll ×4, four VPDPBUSD accumulators

Follow-up to PR #1977. Enables the disabled (#if 0) adler32_copy_avx2_vnni copy variant by rebuilding it on the same structure as the shipping checksum-only path.

Why the disabled copy was slow

The author left adler32_copy_avx2_vnni under #if 0 with a note about a "data dependency bubble," faster on Gracemont E-cores but slower on Raptor Cove P-cores, and a conversation comment: "I think there may need to be more unrolling."

@nmoinvaz
nmoinvaz / zlib-ng-pr1977-adler32-avx512vnni-4x-unroll-README.md
Created July 3, 2026 03:02
zlib-ng PR #1977 follow-up: unroll adler32 AVX-512-VNNI x4 for more in-flight VPDPBUSD (verified spill-free + bit-exact vs reference; not yet benchmarked)

zlib-ng — adler32 AVX-512-VNNI: unroll ×4 for more in-flight VPDPBUSD

Follow-up idea spun off from PR #1977 (AVX2-VNNI adler32).

Why

adler32_avx512_vnni uses only 2 VPDPBUSD accumulators (vs2, vs2_1). VPDPBUSD has ~5-cycle latency, so two in-flight dot products can't cover it and the 128-byte loop is latency-bound at ~5c/128B — the same ceiling as the AVX2-VNNI path.

@nmoinvaz
nmoinvaz / .nathan-config-sync.yaml
Last active July 29, 2026 21:35
nathan config-sync
name: nathan
description: Configuration files synced by config-sync
url: https://github.com/nmoinvaz/gcs
files:
- path: .claude/skills/security-evidence/SKILL.md
gist: nathan_.claude_skills_security-evidence_SKILL.md
updated_at: 2026-06-12T01:39:34.319047220Z
- path: .claude/skills/security-evidence/scripts/ss-capture.sh
gist: nathan_.claude_skills_security-evidence_scripts_ss-capture.sh
updated_at: 2026-06-12T01:38:43.526802792Z
@nmoinvaz
nmoinvaz / zlib-ng-pr2291-strstart-lookahead-struct-experiment.md
Created May 12, 2026 06:44
zlib-ng PR #2291 struct-local experiment for strstart/lookahead

zlib-ng PR #2291 — struct-local experiment for strstart/lookahead

Follow-up to PR #2291 (nv/develop/deflate-strategy-locals-hoist). After the scalar-local hoist landed, tried two variants in deflate_quick.c to see whether packing the two uint32_t fields into a struct could coax the compiler into 64-bit load/store transfers.

Machine

  • Apple M5, macOS 26.4.1, Apple clang 21.0.0
  • AArch64 native, x86_64 cross-compile via CMAKE_OSX_ARCHITECTURES=x86_64
  • CMake Release, -D BUILD_SHARED_LIBS=OFF
@nmoinvaz
nmoinvaz / zlib-ng-deflate-struct-hoist-benefits.md
Last active May 12, 2026 04:33
zlib-ng deflate-struct-hoist: codegen and benchmark analysis

zlib-ng: deflate-struct-hoist — codegen and benchmark analysis

Branch: nv/develop/deflate-struct-hoist Commit: c435d01e — "Hoist deflate bit-emit state into deflate_emit_hot local" Base: upstream/develop (48087450)

Change

Introduces a deflate_emit_hot struct (bi_buf, bi_valid, pending_buf, pending) and DEFLATE_EMIT_HOT_LOAD/STORE macros that cache bit-emit state in a local at the top of hot loops and write it back once on exit. Converts put_byte/put_short/put_short_msb/put_uint32/put_uint32_msb/put_uint64 from macros to static inline functions taking a deflate_emit_hot *. Cold-path callers in deflate.c (zlib/gzip header and trailer writers, name/comment loops) and deflate_stored.c bracket their put_* clusters with LOAD/STORE.

@nmoinvaz
nmoinvaz / zlib-ng-benchmark-chunkmemset.cc
Created May 11, 2026 22:22
zlib-ng: Microbenchmark for chunkmemset_safe variants (compares byte-by-byte tail vs widened bit-decomposed stores)
/* benchmark_chunkmemset.cc -- benchmark chunkmemset_safe variants
* Copyright (C) 2026 Nathan Moinvaziri
* For conditions of distribution and use, see copyright notice in zlib.h
*/
#include <benchmark/benchmark.h>
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
@nmoinvaz
nmoinvaz / benchmark_dist1.cc
Last active May 10, 2026 06:51
zlib-ng PR #2286: microbenchmark of memset replacements for the dist=1 path in CHUNKMEMSET
/* benchmark_dist1.cc -- compare strategies for the dist=1 path in CHUNKMEMSET */
#include <benchmark/benchmark.h>
extern "C" {
# include "zbuild.h"
# include "zutil.h"
}
#if defined(__ARM_NEON) || defined(__ARM_NEON__)