C INT8_CONV2D — symmetric per-tensor int8 2D direct convolution C with int32 accumulation. Stride 1, no padding, no dilation. C Single-batch, multi-channel. C C Reference: B. Jacob et al., "Quantization and Training of Neural C Networks for Efficient Integer-Arithmetic-Only Inference", C CVPR 2018 (arXiv:1712.05877). The classic NHWC/NCHW direct loop C form, written in the textbook six-nested-loop arrangement C (cf. Sze et al., "Efficient Processing of Deep Neural Networks", C MIT Press 2020, Ch. 4). C C Hand-written reference for the Dark Factory's Phase 3 C inference-kernel ladder, 2026-05-23. Public domain. C C Shapes (column-major, NCHW layout): C X is W_IN x H_IN x C_IN (INTEGER*1) input feature map C W is K_W x K_H x C_IN x C_OUT (INTEGER*1) kernel weights C Y is W_OUT x H_OUT x C_OUT (INTEGER) output, int32 C C Output spatial dims (valid convolution, stride 1): C W_OUT = W_IN - K_W + 1 C H_OUT = H_IN - K_H + 1 C C Overflow note: each output element accumulates K_W * K_H * C_IN C signed int8 x int8 products. Worst case product magnitude is C 127 * 127 = 16129, so a 32-bit accumulator is safe while C K_W * K_H * C_IN <= 133164. SUBROUTINE INT8_CONV2D (W_IN, H_IN, C_IN, K_W, K_H, C_OUT, + X, W, Y) C Inputs: C W_IN, H_IN, C_IN — input width, height, channels (positive) C K_W, K_H — kernel width, height (positive, <= input) C C_OUT — number of output channels (positive) C X — input tensor, W_IN x H_IN x C_IN int8 C W — weight tensor, K_W x K_H x C_IN x C_OUT int8 C Output: C Y — output tensor, (W_IN-K_W+1) x (H_IN-K_H+1) C x C_OUT int32 INTEGER W_IN, H_IN, C_IN, K_W, K_H, C_OUT INTEGER*1 X(W_IN, H_IN, C_IN) INTEGER*1 W(K_W, K_H, C_IN, C_OUT) INTEGER Y(W_IN - K_W + 1, H_IN - K_H + 1, C_OUT) INTEGER OC, OY, OX, IC, KY, KX, ACC DO 60 OC = 1, C_OUT DO 50 OY = 1, H_IN - K_H + 1 DO 40 OX = 1, W_IN - K_W + 1 ACC = 0 DO 30 IC = 1, C_IN DO 20 KY = 1, K_H DO 10 KX = 1, K_W ACC = ACC + X(OX + KX - 1, OY + KY - 1, IC) + * W(KX, KY, IC, OC) 10 CONTINUE 20 CONTINUE 30 CONTINUE Y(OX, OY, OC) = ACC 40 CONTINUE 50 CONTINUE 60 CONTINUE RETURN END