#include typedef unsigned char u8; typedef signed char i8; typedef unsigned int u32; static inline float maximum(float a,float b){return a>b?a:b;} static inline float scale_at(const u8 *p) { float f; __builtin_memcpy(&f,p,4); return f; } /* Q4 rows are groups of 32. Each byte packs columns j and j+16. */ void unpack(const u8 *w,float *out,int n) { for(int i=0;i>4)-8); } } } static inline v128_t dot16(v128_t a,v128_t b) { v128_t low=wasm_i32x4_dot_i16x8(wasm_i16x8_extend_low_i8x16(a),wasm_i16x8_extend_low_i8x16(b)); v128_t high=wasm_i32x4_dot_i16x8(wasm_i16x8_extend_high_i8x16(a),wasm_i16x8_extend_high_i8x16(b)); return wasm_i32x4_add(low,high); } /* Quantize activations per group; a GEMV reads only the selected bank. */ static inline __attribute__((always_inline)) void matvec(const u8 *w,const float *x,float *y,int rows,int cols,i8 *activ,float *scales, int bits) { for(int j=0;j