Skip to content

fix(parquet/utils): make unpack32 NEON profiler-safe - #1300

Merged
zeroshade merged 1 commit into
apache:mainfrom
zeroshade:fix-unpack32-neon-profiling
Sep 8, 2026
Merged

zeroshade merged 1 commit into
apache:mainfrom
zeroshade:fix-unpack32-neon-profiling

Conversation

@zeroshade

Copy link
Copy Markdown
Member

Rationale for this change

Addresses the _unpack32_neon part of #983 following the regeneration approach outlined in #983 (comment).

The previous assembly repurposed Go's reserved registers (R18 platform, R27 REGTMP, R28 g) and adjusted SP through opaque WORD directives, so the assembler's pcsp tables were wrong and sigprof could observe a clobbered g — truncated/invalid tracebacks, and a crash with CGO_ENABLED=0.

What changes are included in this PR?

  • Regenerate bit_packing_neon_arm64.s from _lib/bit_packing_neon.c with -ffixed-x18 -ffixed-x27 -ffixed-x28 -fomit-frame-pointer (per the issue comment, plus omitting the frame). The result is a leaf function with zero stack usage and zero reserved-register usage: constants load via VMOVQ pseudo-instructions and every branch is a real Go branch instruction, so unwind state is always valid.
  • Add _lib/neon2goasm.py, which converts the compiled ELF object into the Go assembly and rejects any instruction touching SP or a reserved register, plus a make bit_packing_neon_arm64.s rule (C_FLAGS_NEON_GOASM) so regeneration is reproducible.
  • Drop the unused <string.h> include so the C compiles freestanding for cross-generation.
  • Add BenchmarkUnpack32 (from the issue) so the packed-decode fast path is exercised under -cpuprofile.
  • Document the new generation path in _lib/README.md.

Verification

  • Semantic equivalence: instruction-by-instruction comparison of the assembled Go function against the source ELF object (branch topology index-normalized, VMOVQ constants resolved and compared against .rodata) — no differences besides the parameter/return glue.
  • go test ./parquet/internal/utils (native NEON), -race, -tags noasm, and go test -tags assert ./parquet/... all pass on Apple Silicon.
  • The issue's failure mode is fixed: CGO_ENABLED=0 go test -bench BenchmarkUnpack32 -cpuprofile no longer crashes, and profiles now show full caller chains:
10ms  utils._unpack32_neon
      utils.unpack32NEON
      utils.(*BitReader).GetBatch
      utils.BenchmarkUnpack32
      testing.(*B).runN
  • Throughput improved ~27% as a side effect of the newer codegen (387 → 280 ns/op on BenchmarkUnpack32, Apple M4).

Are there any user-facing changes?

No API changes. CPU profiles of workloads that hit the ARM64 packed decoder are now correct.

Note: unpack_bool_neon_arm64.s has a smaller instance of the same pattern (one WORD-encoded stp with SP writeback); left for a follow-up to keep this reviewable.

@zeroshade
zeroshade merged commit 98bb02b into apache:main Sep 8, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant