mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-26 06:34:20 +08:00
A Uint8ClampedArray store called scr_bytes_to_u8_clamp for every element, which kept loops of clamped stores scalar. The store now computes ToUint8Clamp in line: NaN and values at most 0 store 0, values at least 255 store 255, and values between round through (v + 2^52) - 2^52, which rounds a value in (0, 255) to the nearest integer, ties to even, as the runtime function does. In worker-enabled programs, every typed-array element access tests the view's shared storage and branches between a relaxed atomic access and the ordinary one, so loops over thread-owned views kept one branch per access. A view's shared storage is fixed at construction, like its length, so the typed-array loop version guard now tests it once for each invariant receiver, and the fast copy reads and writes those views directly. In worker programs a loop is versioned for this even when no bound needs a guard. When any receiver is shared, the checked copy runs unchanged. Programs without workers emit the same code as before. Adds a Uint8ClampedArray brighten kernel to the typed-array-kernels workload.