commit 445f751aceb58da4012431734742011229962bea
parent 3c1ff085bd23764d9ade055decf074f17d7761e0
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Mon, 27 Apr 2026 09:47:01 -0700
cc/util: round buf caps to powers of two
bv_capacity_for now returns the smallest pow2 >= n (was > n), so
asking for 2^k bytes lands a 2^k buffer instead of 2^(k+1). Drop the
"-1" workaround; constants are exact powers of two.
Diffstat:
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/cc/util.scm b/cc/util.scm
@@ -126,17 +126,15 @@
;; 64 MiB heap. Bump these when a workload overflows; the buf-overflow
;; die() reports off/len/cap so misses are easy to diagnose.
;;
-;; Each cap is one less than a power of two: scheme1's bv_capacity_for
-;; rounds the requested length up to the smallest power of two STRICTLY
-;; GREATER than it, so asking for 2^k bytes actually consumes 2^(k+1)
-;; of heap. Using 2^k - 1 gives the next-pow2 step EQUAL to 2^k, which
-;; is the storage we actually intended.
-(define %BUF-CAP-TEXT 8388607) ; ≈8 MiB: .text + entry stub
-(define %BUF-CAP-DATA 2097151) ; ≈2 MiB: .data (strings, globals)
-(define %BUF-CAP-BSS 2097151) ; ≈2 MiB: .bss
-(define %BUF-CAP-FN 262143) ; ≈256 KiB: per-fn body asm
-(define %BUF-CAP-PROLOGUE 16383) ; ≈16 KiB: per-fn prologue
-(define %BUF-CAP-DEFAULT 65535) ; ≈64 KiB: make-buf fallback
+;; Each cap is a power of two. scheme1's bv_capacity_for rounds the
+;; requested length up to the smallest power of two ≥ n, so asking for
+;; 2^k bytes consumes exactly 2^k of heap.
+(define %BUF-CAP-TEXT 8388608) ; 8 MiB: .text + entry stub
+(define %BUF-CAP-DATA 2097152) ; 2 MiB: .data (strings, globals)
+(define %BUF-CAP-BSS 2097152) ; 2 MiB: .bss
+(define %BUF-CAP-FN 262144) ; 256 KiB: per-fn body asm
+(define %BUF-CAP-PROLOGUE 16384) ; 16 KiB: per-fn prologue
+(define %BUF-CAP-DEFAULT 65536) ; 64 KiB: make-buf fallback
(define-record-type buf
(%buf storage offset cap)