A price window, a slot pool, and two charges
PriceWindow<Cap> covers Cap ticks from a lower price, Cap a multiple of 64 from 64 to 4096. reset sets the lower price and the step, and clears the window. set writes one side's quantity. Quantity 0 clears that tick. A price that is not on the step, or that falls outside the window, is refused and the previous quantities stay. best reports the highest occupied bid and the lowest occupied ask. Empty ticks are skipped a machine word at a time. shown_before sums quantity strictly better than a price: higher bids, or lower asks. The quantity at that price is left out. A sum that would overflow leaves the output unchanged and returns false.
publish_batch writes from 1 to Cap slots that share one reader mask, then stores the tail once. A busy slot makes the call return 0. Slots already in the ring stay as they were. ack_span acks consecutive positions for one reader and stops at the first position that reader cannot ack. Positions already acked stay acked.
SlotPool<T, Cap> stores trivially copyable records. Cap is a power of two from 2 to 1024. take refuses id 0, a duplicate id, and a full pool. drop returns the slot to the free stack. find returns a pointer into the pool. That pointer is valid until the id is dropped.
margin_both returns the larger of price * quantity * multiplier * money_num / money_den and per_lot * quantity. A bad argument returns 0. Overflow returns the maximum signed value. right_value uses right 1 for a call and right 2 for a put. An unknown right or a negative price returns -1.
FillRing is one producer and one consumer. claim returns a slot to fill in place. publish makes that slot visible. cancel drops a claim that was not published. take copies the oldest published slot. take_span copies up to a caller-chosen count and stores the consumer index once. Each slot occupies its own cache line. The producer remembers the consumer index it last observed, and the consumer remembers the published index. A shared index is read again only when the local copy says the ring is full or empty. A full ring or a second claim fails, and nothing is overwritten.
ExtremeWindow<Cap> keeps the high and the low among the last Cap positive prices, Cap a power of two from 4 to 256. A non-positive price is refused and the window stays. clear drops every price. The window does not choose a trade.
TimeLine<Cap> stores ids at one price, oldest at the front. Cap is a power of two from 4 to 256. push refuses id 0, a duplicate, and a full line. pop removes the front. erase removes one id and keeps the order of the rest. A refused call leaves the line unchanged.
cover_qty walks prices and quantities the caller already holds. A buy counts a price at or below the limit. A sell counts a price at or above it. Buy and sell are separate loops. On SSE4.2 each step compares two prices in one packed compare. A four-wide scalar peel finishes the rest. Non-positive prices and quantities are skipped. The sum stops at need. The arrays stay as they were.
touch_lines prefetches and loads each cache line of a range, including the last byte. On SSE2 the load is a packed 16-byte read. A null pointer or a zero length does nothing.
util/hint.hpp holds likely / unlikely, hot and cold placement, assume_aligned, cache-line size, and prefetch. With PITLANE_NATIVE on x86_64, builds add -mprefer-vector-width=256 -mno-avx512f. util/simd.hpp holds packed zero_i64, zero_i64_stream, copy_bytes, bytes_eq, and the buy/sell cover helpers. AVX2 clears and compares four int64 values when the build defines it. Both keep a scalar body when the ISA is missing. ByteArena is a fixed-capacity anonymous bump arena; by default it maps with MAP_HUGETLB (no THP) and falls back to ordinary anonymous pages with fallback set when none are reserved; mlock and NUMA bind are attempted by default. A full arena fails the next take. batch_size_for picks an adaptive micro-batch size from backlog. RankBits builds dense ranks with word prefixes and popcount; QuadTab seats static keys four per cache line. SpinLock is a TTAS lock on its own cache line. bound.hpp holds one-compare index checks and a walk budget. DagPlan builds a grey/black topological order. Typed tickets make illegal fills uncallable at compile time. OwnPair keeps two local tops. pick_cut and tandem_lat report how to cut a path from intervals the caller already measured. SeqPublishRing is a no-backpressure sequence ring that may overwrite unread slots. global_scale_set stores a process-wide integer TSC cycle scale. DecideScratch holds scored candidate intents the caller arms. host/ provides sched_setaffinity, scheduling policy and nice, IRQ smp_affinity_list, nr_hugepages / thp_disable, mlockall, and NUMA mbind; refused privileged calls return false.