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-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 June 15, 2026 19:23
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__)
@nmoinvaz
nmoinvaz / deflate_quick.patch
Last active May 8, 2026 07:55
zlib-ng: hoist strstart and lookahead in deflate_quick (~12% level 1)
diff --git a/deflate_quick.c b/deflate_quick.c
index 6b84388e..41086525 100644
--- a/deflate_quick.c
+++ b/deflate_quick.c
@@ -49,13 +49,19 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
unsigned char *window;
unsigned last = (flush == Z_FINISH) ? 1 : 0;
+ /* Hold strstart and lookahead in registers across the inner loop.
+ * Sync to s before fill_window (which mutates them) and quick_*_block
@nmoinvaz
nmoinvaz / zlib-ng-insert-string-roll-spill.md
Created May 8, 2026 06:21
zlib-ng: eliminate s->ins_h spill in insert_string_roll inner loop

zlib-ng: eliminate s->ins_h spill in insert_string_roll inner loop

Background

Inspecting AArch64 disassembly of zlib-ng's level-9 deflate path showed that the rolling-hash insert loop emitted a redundant store of the running hash to memory on every byte processed. The cause was visible in the C source and the fix is small and self-contained.

Root cause

@nmoinvaz
nmoinvaz / zlib-ng-pr2281-cache-v2-results.md
Last active May 7, 2026 23:58
zlib-ng PR #2281 — apt-cache v2 results: composite actions + matrix.packages gate

zlib-ng PR #2281 — apt-cache v2 results

PR: zlib-ng/zlib-ng#2281[CI] Cache Ubuntu .deb packages to speed up installing dependencies.

Follow-up to https://gist.github.com/nmoinvaz/978f248ea7d528c954e3d52fb8dc99c0 — measuring the v2 design after the author refactored into composite actions and adopted the matrix.packages gate.

TL;DR

v2 is a clean win across the board. Total apt-install time across Ubuntu jobs is now −71% vs. develop, up from −47% in v1. Default-only jobs no longer pay cache overhead, and warm cache hits skip the write-back step entirely.