okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-own-2a (7c09c4a75) into f-own-int: the Strata quant layer and the x86 CPU rows9c143c403

main
35.7 KiB1004 linesraw
1// src/quant/dot_generic.cpp - the Generic-contract dot products: one weight row against one quantized activation row, plain C++.
2//
3// Derived from ggml-cpu's `ggml_vec_dot_*_generic` (llama.cpp ggml/src/ggml-cpu/quants.c at 3cf03257f219afbe7334045ff7c6a06ac68c627d,
4// Copyright (c) 2023-2026 The ggml authors, MIT; third_party/strata-ggml/LICENSE), ported to C++ and to the layer's signature.  These are the
5// layer's scalar REFERENCE: what a build without SIMD gives (ggml's STRATA_ISA_FLOOR=none flavour), and what the self-checks compare against.
6// Float accumulation is sequential in block order, exactly as in ggml's `_generic` code.
7#define STRATA_QUANT_TABLES
8#include "internal.hpp"
9
10#include <cassert>
11
12#include <cstdlib>
13
14#include "registry.hpp"
15#include "strata/quant/dot.hpp"
16
17namespace strata::quant {
18namespace generic {
19
20#define UNUSED(x) (void) (x)
21
22void dot_q2_0_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
23    const int qk = QK2_0;
24    const int nb = n / qk;
25
26    assert(n % qk == 0);
27
28    const block_q2_0* STRATA_RESTRICT x = (const block_q2_0*) vx;
29    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
30
31    float sumf = 0.0f;
32
33    for (int i = 0; i < nb; i++) {
34        const float d0 = fp16_to_fp32(x[i].d);
35
36        float sumi = 0.0f;
37
38        // group 64: one Q2_0 block (64 weights) maps to two Q8_0 blocks (2 * 32 = 64)
39        for (int k = 0; k < 2; k++) {
40            const block_q8_0 * STRATA_RESTRICT yb = &y[i * 2 + k];
41            const float d1 = fp16_to_fp32(yb->d);
42            int sumi_block = 0;
43
44            const uint8_t * STRATA_RESTRICT qs = &x[i].qs[k * 8];
45            const int8_t  * STRATA_RESTRICT qy = yb->qs;
46
47            for (int b = 0; b < 8; ++b) {
48                const uint8_t byte = qs[b];
49                // Extract 4 two-bit values, map {0,1,2,3} -> {-1,0,1,2}
50                sumi_block += ((int)((byte >> 0) & 3) - 1) * qy[b*4 + 0];
51                sumi_block += ((int)((byte >> 2) & 3) - 1) * qy[b*4 + 1];
52                sumi_block += ((int)((byte >> 4) & 3) - 1) * qy[b*4 + 2];
53                sumi_block += ((int)((byte >> 6) & 3) - 1) * qy[b*4 + 3];
54            }
55
56            sumi += d1 * sumi_block;
57        }
58
59        sumf += d0 * sumi;
60    }
61
62    *s = sumf;
63}
64
65void dot_q4_0_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
66    const int qk = QK8_0;
67    const int nb = n / qk;
68
69    assert(n % qk == 0);
70
71    const block_q4_0* STRATA_RESTRICT x = (const block_q4_0*) vx;
72    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
73
74    int ib = 0;
75    float sumf = 0;
76
77    for (; ib < nb; ++ib) {
78        int sumi0 = 0;
79        int sumi1 = 0;
80
81        for (int j = 0; j < qk/2; ++j) {
82            const int v0 = (x[ib].qs[j] & 0x0F) - 8;
83            const int v1 = (x[ib].qs[j] >>   4) - 8;
84
85            sumi0 += (v0 * y[ib].qs[j]);
86            sumi1 += (v1 * y[ib].qs[j + qk/2]);
87        }
88
89        int sumi = sumi0 + sumi1;
90        sumf += sumi*fp16_to_fp32(x[ib].d)*fp16_to_fp32(y[ib].d);
91    }
92
93    *s = sumf;
94}
95
96void dot_q4_1_q8_1_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
97    const int qk = QK8_1;
98    const int nb = n / qk;
99
100    assert(n % qk == 0);
101
102    const block_q4_1* STRATA_RESTRICT x = (const block_q4_1*) vx;
103    const block_q8_1* STRATA_RESTRICT y = (const block_q8_1*) vy;
104
105    int ib = 0;
106    float sumf = 0;
107
108    for (; ib < nb; ++ib) {
109        int sumi0 = 0;
110        int sumi1 = 0;
111
112        for (int j = 0; j < qk/2; ++j) {
113            const int v0 = (x[ib].qs[j] & 0x0F);
114            const int v1 = (x[ib].qs[j] >>   4);
115
116            sumi0 += (v0 * y[ib].qs[j]);
117            sumi1 += (v1 * y[ib].qs[j + qk/2]);
118        }
119
120        int sumi = sumi0 + sumi1;
121        sumf += (fp16_to_fp32(x[ib].d)*fp16_to_fp32(y[ib].d))*sumi + fp16_to_fp32(x[ib].m)*fp16_to_fp32(y[ib].s);
122    }
123
124    *s = sumf;
125}
126
127void dot_q5_0_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
128    const int qk = QK8_0;
129    const int nb = n / qk;
130
131    int ib = 0;
132    float sumf = 0;
133
134    assert(n % qk == 0);
135    assert(qk == QK5_0);
136
137    const block_q5_0* STRATA_RESTRICT x = (const block_q5_0*) vx;
138    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
139
140    for (; ib < nb; ++ib) {
141        uint32_t qh;
142        memcpy(&qh, x[ib].qh, sizeof(qh));
143
144        int sumi0 = 0;
145        int sumi1 = 0;
146
147        for (int j = 0; j < qk/2; ++j) {
148            const uint8_t xh_0 = ((qh & (1u << (j + 0 ))) >> (j + 0 )) << 4;
149            const uint8_t xh_1 = ((qh & (1u << (j + 16))) >> (j + 12));
150
151            const int32_t x0 = (int8_t)(((x[ib].qs[j] & 0x0F) | xh_0) - 16);
152            const int32_t x1 = (int8_t)(((x[ib].qs[j] >>   4) | xh_1) - 16);
153
154            sumi0 += (x0 * y[ib].qs[j]);
155            sumi1 += (x1 * y[ib].qs[j + qk/2]);
156        }
157
158        int sumi = sumi0 + sumi1;
159        sumf += (fp16_to_fp32(x[ib].d)*fp16_to_fp32(y[ib].d)) * sumi;
160    }
161
162    *s = sumf;
163}
164
165void dot_q5_1_q8_1_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
166    const int qk = QK8_1;
167    const int nb = n / qk;
168
169    int ib = 0;
170    float sumf = 0;
171
172    assert(n % qk == 0);
173    assert(qk == QK5_1);
174
175    const block_q5_1* STRATA_RESTRICT x = (const block_q5_1*) vx;
176    const block_q8_1* STRATA_RESTRICT y = (const block_q8_1*) vy;
177
178    for (; ib < nb; ++ib) {
179        uint32_t qh;
180        memcpy(&qh, x[ib].qh, sizeof(qh));
181
182        int sumi0 = 0;
183        int sumi1 = 0;
184
185        for (int j = 0; j < qk/2; ++j) {
186            const uint8_t xh_0 = ((qh >> (j +  0)) << 4) & 0x10;
187            const uint8_t xh_1 = ((qh >> (j + 12))     ) & 0x10;
188
189            const int32_t x0 = (x[ib].qs[j] & 0xF) | xh_0;
190            const int32_t x1 = (x[ib].qs[j] >>  4) | xh_1;
191
192            sumi0 += (x0 * y[ib].qs[j]);
193            sumi1 += (x1 * y[ib].qs[j + qk/2]);
194        }
195
196        int sumi = sumi0 + sumi1;
197        sumf += (fp16_to_fp32(x[ib].d)*fp16_to_fp32(y[ib].d))*sumi + fp16_to_fp32(x[ib].m)*fp16_to_fp32(y[ib].s);
198    }
199
200    *s = sumf;
201}
202
203void dot_q8_0_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
204    const int qk = QK8_0;
205    const int nb = n / qk;
206
207    assert(n % qk == 0);
208
209    const block_q8_0* STRATA_RESTRICT x = (const block_q8_0*) vx;
210    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
211
212    int ib = 0;
213    float sumf = 0;
214
215    for (; ib < nb; ++ib) {
216        int sumi = 0;
217
218        for (int j = 0; j < qk; j++) {
219            sumi += x[ib].qs[j]*y[ib].qs[j];
220        }
221
222        sumf += sumi*(fp16_to_fp32(x[ib].d)*fp16_to_fp32(y[ib].d));
223    }
224
225    *s = sumf;
226}
227
228void dot_iq4_nl_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
229    assert(n % QK4_NL == 0);
230    static_assert(QK4_NL == QK8_0, "QK4_NL and QK8_0 must be the same");
231
232    const block_iq4_nl* STRATA_RESTRICT x = (const block_iq4_nl*) vx;
233    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
234
235    const int nb = n / QK4_NL;
236
237    int ib = 0;
238    float sumf = 0;
239
240    for (; ib < nb; ++ib) {
241        const float d = fp16_to_fp32(y[ib].d)*fp16_to_fp32(x[ib].d);
242        int sumi1 = 0, sumi2 = 0;
243        for (int j = 0; j < QK4_NL/2; ++j) {
244            sumi1 += y[ib].qs[j+       0] * kvalues_iq4nl[x[ib].qs[j] & 0xf];
245            sumi2 += y[ib].qs[j+QK4_NL/2] * kvalues_iq4nl[x[ib].qs[j] >>  4];
246        }
247        sumf += d * (sumi1 + sumi2);
248    }
249    *s = sumf;
250}
251
252void dot_mxfp4_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
253    assert(n % QK_MXFP4 == 0);
254    static_assert(QK_MXFP4 == QK8_0, "QK_MXFP4 and QK8_0 must be the same");
255
256    const block_mxfp4* STRATA_RESTRICT x = (const block_mxfp4*) vx;
257    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
258
259    const int nb = n / QK_MXFP4;
260
261    int ib = 0;
262    float sumf = 0;
263
264    for (; ib < nb; ++ib) {
265        const float d = fp16_to_fp32(y[ib].d)*e8m0_to_fp32_half(x[ib].e);
266
267        int sumi1 = 0;
268        int sumi2 = 0;
269        for (int j = 0; j < QK_MXFP4/2; ++j) {
270            sumi1 += y[ib].qs[j +          0] * kvalues_mxfp4[x[ib].qs[j] & 0xf];
271            sumi2 += y[ib].qs[j + QK_MXFP4/2] * kvalues_mxfp4[x[ib].qs[j] >>  4];
272        }
273        sumf += d * (sumi1 + sumi2);
274    }
275    *s = sumf;
276}
277
278void dot_nvfp4_q8_0_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
279    assert(n % QK_NVFP4 == 0);
280
281    const block_nvfp4* STRATA_RESTRICT x = (const block_nvfp4*) vx;
282    const block_q8_0* STRATA_RESTRICT y = (const block_q8_0*) vy;
283
284    const int nb = n / QK_NVFP4;
285
286    float sumf = 0;
287
288    for (int ib = 0; ib < nb; ++ib) {
289        for (int s_idx = 0; s_idx < 4; ++s_idx) {
290            const float d = ue4m3_to_fp32(x[ib].d[s_idx]);
291            const int q8_block = s_idx / 2;
292            const int q8_off   = (s_idx % 2) * QK_NVFP4_SUB;
293            const float dy = fp16_to_fp32(y[2*ib + q8_block].d);
294
295            int sumi_lo = 0, sumi_hi = 0;
296            for (int j = 0; j < QK_NVFP4_SUB/2; ++j) {
297                const uint8_t qv = x[ib].qs[s_idx*(QK_NVFP4_SUB/2) + j];
298                sumi_lo += y[2*ib + q8_block].qs[q8_off + j +               0] * kvalues_mxfp4[qv & 0xf];
299                sumi_hi += y[2*ib + q8_block].qs[q8_off + j + QK_NVFP4_SUB/2] * kvalues_mxfp4[qv >>  4];
300            }
301
302            sumf += dy * d * (sumi_lo + sumi_hi);
303        }
304    }
305    *s = sumf;
306}
307
308void dot_q2_K_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
309
310    const block_q2_K* STRATA_RESTRICT x = (const block_q2_K*) vx;
311    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
312
313    const int nb = n / QK_K;
314
315    float sumf = 0;
316
317    for (int i = 0; i < nb; ++i) {
318
319        const uint8_t * q2 = x[i].qs;
320        const  int8_t * q8 = y[i].qs;
321        const uint8_t * sc = x[i].scales;
322
323        int summs = 0;
324        for (int j = 0; j < 16; ++j) {
325            summs += y[i].bsums[j] * (sc[j] >> 4);
326        }
327
328        const float dall = y[i].d * fp16_to_fp32(x[i].d);
329        const float dmin = y[i].d * fp16_to_fp32(x[i].dmin);
330
331        int isum = 0;
332        int is = 0;
333        int d;
334        for (int k = 0; k < QK_K/128; ++k) {
335            int shift = 0;
336            for (int j = 0; j < 4; ++j) {
337                d = sc[is++] & 0xF;
338                int isuml = 0;
339                for (int l =  0; l < 16; ++l) isuml += q8[l] * ((q2[l] >> shift) & 3);
340                isum += d * isuml;
341                d = sc[is++] & 0xF;
342                isuml = 0;
343                for (int l = 16; l < 32; ++l) isuml += q8[l] * ((q2[l] >> shift) & 3);
344                isum += d * isuml;
345                shift += 2;
346                q8 += 32;
347            }
348            q2 += 32;
349        }
350        sumf += dall * isum - dmin * summs;
351    }
352    *s = sumf;
353}
354
355void dot_q3_K_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
356    assert(n % QK_K == 0);
357
358    const uint32_t kmask1 = 0x03030303;
359    const uint32_t kmask2 = 0x0f0f0f0f;
360
361    const block_q3_K* STRATA_RESTRICT x = (const block_q3_K*) vx;
362    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
363
364    const int nb = n / QK_K;
365
366    // scalar version
367    // This function is written like this so the compiler can manage to vectorize most of it
368    // Using -Ofast, GCC and clang manage to produce code that is within a factor of 2 or so from the
369    // manually vectorized version above. Every other version I tried would run at least 4 times slower.
370    // The ideal situation would be if we could just write the code once, and the compiler would
371    // automatically produce the best possible set of machine instructions, instead of us having to manually
372    // write vectorized versions for AVX, ARM_NEON, etc.
373
374    int8_t  aux8[QK_K];
375    int16_t aux16[8];
376    float   sums [8];
377    int32_t aux32[8];
378    memset(sums, 0, 8*sizeof(float));
379
380    uint32_t auxs[4];
381    const int8_t * scales = (const int8_t*)auxs;
382
383    float sumf = 0;
384    for (int i = 0; i < nb; ++i) {
385        const uint8_t * STRATA_RESTRICT q3 = x[i].qs;
386        const uint8_t * STRATA_RESTRICT hm = x[i].hmask;
387        const  int8_t * STRATA_RESTRICT q8 = y[i].qs;
388        memset(aux32, 0, 8*sizeof(int32_t));
389        int8_t * STRATA_RESTRICT a = aux8;
390        uint8_t m = 1;
391        for (int j = 0; j < QK_K; j += 128) {
392            for (int l = 0; l < 32; ++l) a[l] = q3[l] & 3;
393            for (int l = 0; l < 32; ++l) a[l] -= (hm[l] & m ? 0 : 4);
394            a += 32; m <<= 1;
395            for (int l = 0; l < 32; ++l) a[l] = (q3[l] >> 2) & 3;
396            for (int l = 0; l < 32; ++l) a[l] -= (hm[l] & m ? 0 : 4);
397            a += 32; m <<= 1;
398            for (int l = 0; l < 32; ++l) a[l] = (q3[l] >> 4) & 3;
399            for (int l = 0; l < 32; ++l) a[l] -= (hm[l] & m ? 0 : 4);
400            a += 32; m <<= 1;
401            for (int l = 0; l < 32; ++l) a[l] = (q3[l] >> 6) & 3;
402            for (int l = 0; l < 32; ++l) a[l] -= (hm[l] & m ? 0 : 4);
403            a += 32; m <<= 1;
404            q3 += 32;
405        }
406        a = aux8;
407
408        memcpy(auxs, x[i].scales, 12);
409        uint32_t tmp = auxs[2];
410        auxs[2] = ((auxs[0] >> 4) & kmask2) | (((tmp >> 4) & kmask1) << 4);
411        auxs[3] = ((auxs[1] >> 4) & kmask2) | (((tmp >> 6) & kmask1) << 4);
412        auxs[0] = (auxs[0] & kmask2) | (((tmp >> 0) & kmask1) << 4);
413        auxs[1] = (auxs[1] & kmask2) | (((tmp >> 2) & kmask1) << 4);
414        for (int j = 0; j < QK_K/16; ++j) {
415            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
416            for (int l = 0; l < 8; ++l) aux32[l] += (scales[j] - 32) * aux16[l];
417            q8 += 8; a += 8;
418            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
419            for (int l = 0; l < 8; ++l) aux32[l] += (scales[j] - 32) * aux16[l];
420            q8 += 8; a += 8;
421        }
422        const float d = fp16_to_fp32(x[i].d) * y[i].d;
423        for (int l = 0; l < 8; ++l) sums[l] += d * aux32[l];
424    }
425    for (int l = 0; l < 8; ++l) sumf += sums[l];
426    *s = sumf;
427}
428
429void dot_q4_K_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
430    assert(n % QK_K == 0);
431
432    const block_q4_K* STRATA_RESTRICT x = (const block_q4_K*) vx;
433    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
434
435    const int nb = n / QK_K;
436
437    static const uint32_t kmask1 = 0x3f3f3f3f;
438    static const uint32_t kmask2 = 0x0f0f0f0f;
439    static const uint32_t kmask3 = 0x03030303;
440
441    uint32_t utmp[4];
442
443    const uint8_t * scales = (const uint8_t*)&utmp[0];
444    const uint8_t * mins   = (const uint8_t*)&utmp[2];
445
446    int8_t  aux8[QK_K];
447    int16_t aux16[8];
448    float   sums [8];
449    int32_t aux32[8];
450    memset(sums, 0, 8*sizeof(float));
451
452    float sumf = 0;
453    for (int i = 0; i < nb; ++i) {
454        const uint8_t * STRATA_RESTRICT q4 = x[i].qs;
455        const  int8_t * STRATA_RESTRICT q8 = y[i].qs;
456        memset(aux32, 0, 8*sizeof(int32_t));
457        int8_t * STRATA_RESTRICT a = aux8;
458        for (int j = 0; j < QK_K/64; ++j) {
459            for (int l = 0; l < 32; ++l) a[l] = (int8_t)(q4[l] & 0xF);
460            a += 32;
461            for (int l = 0; l < 32; ++l) a[l] = (int8_t)(q4[l]  >> 4);
462            a += 32; q4 += 32;
463        }
464        memcpy(utmp, x[i].scales, 12);
465        utmp[3] = ((utmp[2] >> 4) & kmask2) | (((utmp[1] >> 6) & kmask3) << 4);
466        const uint32_t uaux = utmp[1] & kmask1;
467        utmp[1] = (utmp[2] & kmask2) | (((utmp[0] >> 6) & kmask3) << 4);
468        utmp[2] = uaux;
469        utmp[0] &= kmask1;
470
471        int sumi = 0;
472        for (int j = 0; j < QK_K/16; ++j) sumi += y[i].bsums[j] * mins[j/2];
473        a = aux8;
474        int is = 0;
475        for (int j = 0; j < QK_K/32; ++j) {
476            int32_t scale = scales[is++];
477            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
478            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
479            q8 += 8; a += 8;
480            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
481            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
482            q8 += 8; a += 8;
483            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
484            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
485            q8 += 8; a += 8;
486            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
487            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
488            q8 += 8; a += 8;
489        }
490        const float d = fp16_to_fp32(x[i].d) * y[i].d;
491        for (int l = 0; l < 8; ++l) sums[l] += d * aux32[l];
492        const float dmin = fp16_to_fp32(x[i].dmin) * y[i].d;
493        sumf -= dmin * sumi;
494    }
495    for (int l = 0; l < 8; ++l) sumf += sums[l];
496    *s = sumf;
497}
498
499void dot_q5_K_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
500    assert(n % QK_K == 0);
501
502    const block_q5_K* STRATA_RESTRICT x = (const block_q5_K*) vx;
503    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
504
505    const int nb = n / QK_K;
506
507    static const uint32_t kmask1 = 0x3f3f3f3f;
508    static const uint32_t kmask2 = 0x0f0f0f0f;
509    static const uint32_t kmask3 = 0x03030303;
510
511    uint32_t utmp[4];
512
513    const uint8_t * scales = (const uint8_t*)&utmp[0];
514    const uint8_t * mins   = (const uint8_t*)&utmp[2];
515
516    int8_t  aux8[QK_K];
517    int16_t aux16[8];
518    float   sums [8];
519    int32_t aux32[8];
520    memset(sums, 0, 8*sizeof(float));
521
522    float sumf = 0;
523    for (int i = 0; i < nb; ++i) {
524        const uint8_t * STRATA_RESTRICT q4 = x[i].qs;
525        const uint8_t * STRATA_RESTRICT hm = x[i].qh;
526        const  int8_t * STRATA_RESTRICT q8 = y[i].qs;
527        memset(aux32, 0, 8*sizeof(int32_t));
528        int8_t * STRATA_RESTRICT a = aux8;
529        uint8_t m = 1;
530        for (int j = 0; j < QK_K/64; ++j) {
531            for (int l = 0; l < 32; ++l) a[l] = (int8_t)(q4[l] & 0xF);
532            for (int l = 0; l < 32; ++l) a[l] += (hm[l] & m ? 16 : 0);
533            a += 32; m <<= 1;
534            for (int l = 0; l < 32; ++l) a[l] = (int8_t)(q4[l]  >> 4);
535            for (int l = 0; l < 32; ++l) a[l] += (hm[l] & m ? 16 : 0);
536            a += 32; m <<= 1;
537            q4 += 32;
538        }
539        memcpy(utmp, x[i].scales, 12);
540        utmp[3] = ((utmp[2] >> 4) & kmask2) | (((utmp[1] >> 6) & kmask3) << 4);
541        const uint32_t uaux = utmp[1] & kmask1;
542        utmp[1] = (utmp[2] & kmask2) | (((utmp[0] >> 6) & kmask3) << 4);
543        utmp[2] = uaux;
544        utmp[0] &= kmask1;
545
546        int sumi = 0;
547        for (int j = 0; j < QK_K/16; ++j) sumi += y[i].bsums[j] * mins[j/2];
548        a = aux8;
549        int is = 0;
550        for (int j = 0; j < QK_K/32; ++j) {
551            int32_t scale = scales[is++];
552            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
553            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
554            q8 += 8; a += 8;
555            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
556            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
557            q8 += 8; a += 8;
558            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
559            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
560            q8 += 8; a += 8;
561            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
562            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
563            q8 += 8; a += 8;
564        }
565        const float d = fp16_to_fp32(x[i].d) * y[i].d;
566        for (int l = 0; l < 8; ++l) sums[l] += d * aux32[l];
567        const float dmin = fp16_to_fp32(x[i].dmin) * y[i].d;
568        sumf -= dmin * sumi;
569    }
570    for (int l = 0; l < 8; ++l) sumf += sums[l];
571    *s = sumf;
572}
573
574void dot_q6_K_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
575    assert(n % QK_K == 0);
576
577    const block_q6_K* STRATA_RESTRICT x = (const block_q6_K*) vx;
578    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
579
580    const int nb = n / QK_K;
581
582    int8_t  aux8[QK_K];
583    int16_t aux16[8];
584    float   sums [8];
585    int32_t aux32[8];
586    memset(sums, 0, 8*sizeof(float));
587
588    float sumf = 0;
589    for (int i = 0; i < nb; ++i) {
590        const uint8_t * STRATA_RESTRICT q4 = x[i].ql;
591        const uint8_t * STRATA_RESTRICT qh = x[i].qh;
592        const  int8_t * STRATA_RESTRICT q8 = y[i].qs;
593        memset(aux32, 0, 8*sizeof(int32_t));
594        int8_t * STRATA_RESTRICT a = aux8;
595        for (int j = 0; j < QK_K; j += 128) {
596            for (int l = 0; l < 32; ++l) {
597                a[l +  0] = (int8_t)((q4[l +  0] & 0xF) | (((qh[l] >> 0) & 3) << 4)) - 32;
598                a[l + 32] = (int8_t)((q4[l + 32] & 0xF) | (((qh[l] >> 2) & 3) << 4)) - 32;
599                a[l + 64] = (int8_t)((q4[l +  0] >>  4) | (((qh[l] >> 4) & 3) << 4)) - 32;
600                a[l + 96] = (int8_t)((q4[l + 32] >>  4) | (((qh[l] >> 6) & 3) << 4)) - 32;
601            }
602            a  += 128;
603            q4 += 64;
604            qh += 32;
605        }
606        a = aux8;
607        int is = 0;
608        for (int j = 0; j < QK_K/16; ++j) {
609            int scale = x[i].scales[is++];
610            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
611            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
612            q8 += 8; a += 8;
613            for (int l = 0; l < 8; ++l) aux16[l] = q8[l] * a[l];
614            for (int l = 0; l < 8; ++l) aux32[l] += scale * aux16[l];
615            q8 += 8; a += 8;
616        }
617        const float d = fp16_to_fp32(x[i].d) * y[i].d;
618        for (int l = 0; l < 8; ++l) sums[l] += d * aux32[l];
619    }
620    for (int l = 0; l < 8; ++l) sumf += sums[l];
621    *s = sumf;
622}
623
624void dot_iq1_s_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
625    assert(n % QK_K == 0);
626
627    const block_iq1_s* STRATA_RESTRICT x = (const block_iq1_s*) vx;
628    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
629
630    const int nb = n / QK_K;
631
632    float sumf = 0;
633    for (int i = 0; i < nb; i++) {
634
635        const int8_t   * q8 = y[i].qs;
636        const uint8_t  * qs = x[i].qs;
637        const uint16_t * qh = x[i].qh;
638
639        int sumi = 0, sumi1 = 0;
640        for (int ib = 0; ib < QK_K/32; ++ib) {
641            const int ls = 2*((qh[ib] >> 12) & 7) + 1;
642            const int delta = qh[ib] & 0x8000 ? -1 : 1;
643            int lsum = 0;
644            for (int l = 0; l < 4; ++l) {
645                const int8_t * grid = (const int8_t *)(iq1s_grid + (qs[l] | (((qh[ib] >> 3*l) & 7) << 8)));
646                for (int j = 0; j < 8; ++j) {
647                    lsum += q8[j] * grid[j];
648                }
649                q8 += 8;
650            }
651            sumi  += ls * lsum;
652            sumi1 += ls * delta * (y[i].bsums[2*ib+0] + y[i].bsums[2*ib+1]);
653            qs += 4;
654        }
655
656        sumf += fp16_to_fp32(x[i].d) * y[i].d * (sumi + IQ1S_DELTA * sumi1);
657    }
658
659    *s = sumf;
660}
661
662void dot_iq1_m_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
663    assert(n % QK_K == 0);
664
665    const block_iq1_m* STRATA_RESTRICT x = (const block_iq1_m*) vx;
666    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
667
668    const int nb = n / QK_K;
669
670    iq1m_scale_t scale;
671
672    int sum1[2], sum2[2], delta[4];
673
674    float sumf = 0;
675    for (int i = 0; i < nb; i++) {
676
677        const int8_t   * q8 = y[i].qs;
678        const uint8_t  * qs = x[i].qs;
679        const uint8_t  * qh = x[i].qh;
680        const uint16_t * sc = (const uint16_t *)x[i].scales;
681
682        scale.u16 = (sc[0] >> 12) | ((sc[1] >> 8) & 0x00f0) | ((sc[2] >> 4) & 0x0f00) | (sc[3] & 0xf000);
683
684        int sumi1 = 0, sumi2 = 0;
685        for (int ib = 0; ib < QK_K/32; ++ib) {
686            delta[0] = qh[0] & 0x08 ? -1 : 1;
687            delta[1] = qh[0] & 0x80 ? -1 : 1;
688            delta[2] = qh[1] & 0x08 ? -1 : 1;
689            delta[3] = qh[1] & 0x80 ? -1 : 1;
690            sum1[0] = sum1[1] = sum2[0] = sum2[1] = 0;
691            for (int l = 0; l < 4; ++l) {
692                const int8_t * grid = (const int8_t *)(iq1s_grid + (qs[l] | (((uint16_t)qh[l/2] << (8 - 4*(l%2))) & 0x700)));
693                int lsum1 = 0, lsum2 = 0;
694                for (int j = 0; j < 8; ++j) {
695                    lsum1 += q8[j] * grid[j];
696                    lsum2 += q8[j];
697                }
698                q8 += 8;
699                sum1[l/2] += lsum1;
700                sum2[l/2] += lsum2*delta[l];
701            }
702
703            const int ls1 = 2*((sc[ib/2] >> (6*(ib%2)+0)) & 0x7) + 1;
704            const int ls2 = 2*((sc[ib/2] >> (6*(ib%2)+3)) & 0x7) + 1;
705
706            sumi1 += sum1[0] * ls1 + sum1[1] * ls2;
707            sumi2 += sum2[0] * ls1 + sum2[1] * ls2;
708            qs += 4;
709            qh += 2;
710        }
711
712        sumf += fp16_to_fp32(scale.f16) * y[i].d * (sumi1 + IQ1M_DELTA * sumi2);
713    }
714
715    *s = sumf;
716}
717
718void dot_iq2_xxs_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
719    assert(n % QK_K == 0);
720
721    const block_iq2_xxs* STRATA_RESTRICT x = (const block_iq2_xxs*) vx;
722    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
723
724    const int nb = n / QK_K;
725
726    uint32_t aux32[2];
727    const uint8_t * aux8 = (const uint8_t *)aux32;
728
729    float sumf = 0.f;
730    for (int i = 0; i < nb; ++i) {
731        const float d = fp16_to_fp32(x[i].d) * y[i].d;
732        const uint16_t * STRATA_RESTRICT q2 = x[i].qs;
733        const int8_t   * STRATA_RESTRICT q8 = y[i].qs;
734        int32_t bsum = 0;
735        for (int ib32 = 0; ib32 < QK_K/32; ++ib32) {
736            memcpy(aux32, q2, 2*sizeof(uint32_t));
737            q2 += 4;
738            const uint32_t ls = 2*(aux32[1] >> 28) + 1;
739            int32_t sumi = 0;
740            for (int l = 0; l < 4; ++l) {
741                const uint8_t * grid = (const uint8_t *)(iq2xxs_grid + aux8[l]);
742                const uint8_t  signs = ksigns_iq2xs[(aux32[1] >> 7*l) & 127];
743                for (int j = 0; j < 8; ++j) {
744                    sumi += grid[j] * q8[j] * (signs & kmask_iq2xs[j] ? -1 : 1);
745                }
746                q8 += 8;
747            }
748            bsum += sumi * ls;
749        }
750        sumf += d * bsum;
751    }
752    *s = 0.125f * sumf;
753}
754
755void dot_iq2_xs_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
756    assert(n % QK_K == 0);
757
758    const block_iq2_xs* STRATA_RESTRICT x = (const block_iq2_xs*) vx;
759    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
760
761    const int nb = n / QK_K;
762
763    float sumf = 0.f;
764    for (int i = 0; i < nb; ++i) {
765        const float d = fp16_to_fp32(x[i].d) * y[i].d;
766        const uint16_t * STRATA_RESTRICT q2 = x[i].qs;
767        const uint8_t  * STRATA_RESTRICT sc = x[i].scales;
768        const int8_t   * STRATA_RESTRICT q8 = y[i].qs;
769        int32_t bsum = 0;
770        for (int ib32 = 0; ib32 < QK_K/32; ++ib32) {
771            const uint16_t ls1 = 2*(sc[ib32] & 0xf) + 1;
772            const uint16_t ls2 = 2*(sc[ib32] >>  4) + 1;
773            int32_t sumi = 0;
774            for (int l = 0; l < 2; ++l) {
775                const uint8_t * grid = (const uint8_t *)(iq2xs_grid + (q2[l] & 511));
776                const uint8_t  signs = ksigns_iq2xs[q2[l] >> 9];
777                for (int j = 0; j < 8; ++j) {
778                    sumi += grid[j] * q8[j] * (signs & kmask_iq2xs[j] ? -1 : 1);
779                }
780                q8 += 8;
781            }
782            bsum += sumi * ls1;
783            sumi = 0;
784            for (int l = 2; l < 4; ++l) {
785                const uint8_t * grid = (const uint8_t *)(iq2xs_grid + (q2[l] & 511));
786                const uint8_t  signs = ksigns_iq2xs[q2[l] >> 9];
787                for (int j = 0; j < 8; ++j) {
788                    sumi += grid[j] * q8[j] * (signs & kmask_iq2xs[j] ? -1 : 1);
789                }
790                q8 += 8;
791            }
792            bsum += sumi * ls2;
793            q2 += 4;
794        }
795        sumf += d * bsum;
796    }
797    *s = 0.125f * sumf;
798}
799
800void dot_iq2_s_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
801    assert(n % QK_K == 0);
802
803    const block_iq2_s* STRATA_RESTRICT x = (const block_iq2_s*) vx;
804    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
805
806    const int nb = n / QK_K;
807
808    float sumf = 0;
809    for (int i = 0; i < nb; i++) {
810
811        const float d = fp16_to_fp32(x[i].d) * y[i].d;
812        const int8_t  * q8 = y[i].qs;
813        const uint8_t * qs = x[i].qs;
814        const uint8_t * qh = x[i].qh;
815        const uint8_t * signs = qs + QK_K/8;
816
817        int bsum = 0;
818        for (int ib32 = 0; ib32 < QK_K/32; ++ib32) {
819            int ls1 = 1 + 2*(x[i].scales[ib32] & 0xf);
820            int ls2 = 1 + 2*(x[i].scales[ib32] >>  4);
821            int sumi1 = 0, sumi2 = 0;
822            for (int l = 0; l < 2; ++l) {
823                const uint8_t * grid = (const uint8_t *)(iq2s_grid + (qs[l] | (qh[ib32] << (8-2*l) & 0x300)));
824                for (int j = 0; j < 8; ++j) {
825                    sumi1 += q8[j] * grid[j] * (signs[l] & kmask_iq2xs[j] ? -1 : 1);
826                }
827                q8 += 8;
828            }
829            for (int l = 2; l < 4; ++l) {
830                const uint8_t * grid = (const uint8_t *)(iq2s_grid + (qs[l] | (qh[ib32] << (8-2*l) & 0x300)));
831                for (int j = 0; j < 8; ++j) {
832                    sumi2 += q8[j] * grid[j] * (signs[l] & kmask_iq2xs[j] ? -1 : 1);
833                }
834                q8 += 8;
835            }
836            bsum += ls1 * sumi1 + ls2 * sumi2;
837            qs += 4;
838            signs += 4;
839        }
840
841        sumf += d * bsum;
842    }
843
844    *s = 0.125f * sumf;
845}
846
847void dot_iq3_xxs_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
848    assert(n % QK_K == 0);
849
850    const block_iq3_xxs* STRATA_RESTRICT x = (const block_iq3_xxs*) vx;
851    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
852
853    const int nb = n / QK_K;
854
855    uint32_t aux32;
856
857    float sumf = 0.f;
858    for (int i = 0; i < nb; ++i) {
859        const float d = fp16_to_fp32(x[i].d) * y[i].d;
860        const uint8_t * STRATA_RESTRICT q3 = x[i].qs;
861        const uint8_t * STRATA_RESTRICT gas = x[i].qs + QK_K/4;
862        const int8_t  * STRATA_RESTRICT q8 = y[i].qs;
863        int32_t bsum = 0;
864        for (int ib32 = 0; ib32 < QK_K/32; ++ib32) {
865            memcpy(&aux32, gas, sizeof(uint32_t)); gas += sizeof(uint32_t);
866            const uint32_t ls = 2*(aux32 >> 28) + 1;
867            int32_t sumi = 0;
868            for (int l = 0; l < 4; ++l) {
869                const uint8_t * grid1 = (const uint8_t *)(iq3xxs_grid + q3[2*l+0]);
870                const uint8_t * grid2 = (const uint8_t *)(iq3xxs_grid + q3[2*l+1]);
871                const uint8_t  signs = ksigns_iq2xs[(aux32 >> 7*l) & 127];
872                for (int j = 0; j < 4; ++j) {
873                    sumi += grid1[j] * q8[j+0] * (signs & kmask_iq2xs[j+0] ? -1 : 1);
874                    sumi += grid2[j] * q8[j+4] * (signs & kmask_iq2xs[j+4] ? -1 : 1);
875                }
876                q8 += 8;
877            }
878            q3 += 8;
879            bsum += sumi * ls;
880        }
881        sumf += d * bsum;
882    }
883    *s = 0.25f * sumf;
884}
885
886void dot_iq3_s_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
887    assert(n % QK_K == 0);
888
889    const block_iq3_s* STRATA_RESTRICT x = (const block_iq3_s*) vx;
890    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
891
892    const int nb = n / QK_K;
893
894    float sumf = 0.f;
895    for (int i = 0; i < nb; ++i) {
896        const float d = fp16_to_fp32(x[i].d) * y[i].d;
897        const uint8_t * STRATA_RESTRICT qs = x[i].qs;
898        const uint8_t * STRATA_RESTRICT qh = x[i].qh;
899        const uint8_t * STRATA_RESTRICT signs = x[i].signs;
900        const int8_t  * STRATA_RESTRICT q8 = y[i].qs;
901        int32_t bsum = 0;
902        for (int ib32 = 0; ib32 < QK_K/32; ib32 += 2) {
903            const uint32_t ls1 = 2*(x[i].scales[ib32/2] & 0xf) + 1;
904            const uint32_t ls2 = 2*(x[i].scales[ib32/2] >>  4) + 1;
905            int32_t sumi = 0;
906            for (int l = 0; l < 4; ++l) {
907                const uint8_t * grid1 = (const uint8_t *)(iq3s_grid + (qs[2*l+0] | ((qh[ib32+0] << (8-2*l)) & 256)));
908                const uint8_t * grid2 = (const uint8_t *)(iq3s_grid + (qs[2*l+1] | ((qh[ib32+0] << (7-2*l)) & 256)));
909                for (int j = 0; j < 4; ++j) {
910                    sumi += grid1[j] * q8[j+0] * (signs[l] & kmask_iq2xs[j+0] ? -1 : 1);
911                    sumi += grid2[j] * q8[j+4] * (signs[l] & kmask_iq2xs[j+4] ? -1 : 1);
912                }
913                q8 += 8;
914            }
915            qs += 8;
916            signs += 4;
917            bsum += sumi * ls1;
918            sumi = 0;
919            for (int l = 0; l < 4; ++l) {
920                const uint8_t * grid1 = (const uint8_t *)(iq3s_grid + (qs[2*l+0] | ((qh[ib32+1] << (8-2*l)) & 256)));
921                const uint8_t * grid2 = (const uint8_t *)(iq3s_grid + (qs[2*l+1] | ((qh[ib32+1] << (7-2*l)) & 256)));
922                for (int j = 0; j < 4; ++j) {
923                    sumi += grid1[j] * q8[j+0] * (signs[l] & kmask_iq2xs[j+0] ? -1 : 1);
924                    sumi += grid2[j] * q8[j+4] * (signs[l] & kmask_iq2xs[j+4] ? -1 : 1);
925                }
926                q8 += 8;
927            }
928            qs += 8;
929            signs += 4;
930            bsum += sumi * ls2;
931        }
932        sumf += d * bsum;
933    }
934    *s = sumf;
935}
936
937void dot_iq4_xs_q8_K_generic(int n, float* STRATA_RESTRICT s, const void* STRATA_RESTRICT vx, const void* STRATA_RESTRICT vy) {
938    assert(n % QK_K == 0);
939
940    const block_iq4_xs* STRATA_RESTRICT x = (const block_iq4_xs*) vx;
941    const block_q8_K* STRATA_RESTRICT y = (const block_q8_K*) vy;
942
943    const int nb = n / QK_K;
944
945    float sumf = 0;
946    for (int ibl = 0; ibl < nb; ++ibl) {
947        const float d4d8 = fp16_to_fp32(x[ibl].d) * y[ibl].d;
948        uint16_t h = x[ibl].scales_h;
949        const uint8_t * qs = x[ibl].qs;
950        const int8_t  * q8 = y[ibl].qs;
951        for (int ib = 0; ib < QK_K/32; ib += 2) {
952            const uint8_t ls1 = (x[ibl].scales_l[ib/2] & 0xf) | ((h << 4) & 0x30);
953            const uint8_t ls2 = (x[ibl].scales_l[ib/2] >>  4) | ((h << 2) & 0x30);
954            h >>= 4;
955            const float d1 = d4d8*(ls1 - 32);
956            const float d2 = d4d8*(ls2 - 32);
957            int sumi1 = 0, sumi2 = 0;
958            for (int j = 0; j < 16; ++j) {
959                sumi1 += q8[j+ 0] * kvalues_iq4nl[qs[j] & 0xf];
960                sumi2 += q8[j+16] * kvalues_iq4nl[qs[j] >>  4];
961            }
962            sumf += d1 * (sumi1 + sumi2);
963            qs += 16;
964            q8 += 32;
965            sumi1 = sumi2 = 0;
966            for (int j = 0; j < 16; ++j) {
967                sumi1 += q8[j+ 0] * kvalues_iq4nl[qs[j] & 0xf];
968                sumi2 += q8[j+16] * kvalues_iq4nl[qs[j] >>  4];
969            }
970            sumf += d2 * (sumi1 + sumi2);
971            qs += 16;
972            q8 += 32;
973        }
974    }
975    *s = sumf;
976}
977
978}  // namespace generic
979
980namespace {
981#define ENTRY(T, ACT, NAME) {generic::dot_##NAME##_generic, Type::T, Type::ACT, Arith::Generic, Isa::Scalar, "generic_" #NAME}
982const DotKernel kGeneric[] = {
983    ENTRY(Q2_0, Q8_0, q2_0_q8_0),   ENTRY(Q4_0, Q8_0, q4_0_q8_0),   ENTRY(Q4_1, Q8_1, q4_1_q8_1),   ENTRY(Q5_0, Q8_0, q5_0_q8_0),
984    ENTRY(Q5_1, Q8_1, q5_1_q8_1),   ENTRY(Q8_0, Q8_0, q8_0_q8_0),   ENTRY(IQ4_NL, Q8_0, iq4_nl_q8_0), ENTRY(MXFP4, Q8_0, mxfp4_q8_0),
985    ENTRY(NVFP4, Q8_0, nvfp4_q8_0), ENTRY(Q2_K, Q8_K, q2_K_q8_K),   ENTRY(Q3_K, Q8_K, q3_K_q8_K),   ENTRY(Q4_K, Q8_K, q4_K_q8_K),
986    ENTRY(Q5_K, Q8_K, q5_K_q8_K),   ENTRY(Q6_K, Q8_K, q6_K_q8_K),   ENTRY(IQ1_S, Q8_K, iq1_s_q8_K),  ENTRY(IQ1_M, Q8_K, iq1_m_q8_K),
987    ENTRY(IQ2_XXS, Q8_K, iq2_xxs_q8_K), ENTRY(IQ2_XS, Q8_K, iq2_xs_q8_K), ENTRY(IQ2_S, Q8_K, iq2_s_q8_K), ENTRY(IQ3_XXS, Q8_K, iq3_xxs_q8_K),
988    ENTRY(IQ3_S, Q8_K, iq3_s_q8_K), ENTRY(IQ4_XS, Q8_K, iq4_xs_q8_K),
989};
990#undef ENTRY
991}  // namespace
992
993DotTable generic_dot_table() noexcept { return {kGeneric, (int) (sizeof kGeneric / sizeof kGeneric[0])}; }
994
995void dot_ref(Type w, int n, float* s, const void* wrow, const void* act) {
996    for (const DotKernel& k : kGeneric)
997        if (k.weight == w) {
998            k.fn(n, s, wrow, act);
999            return;
1000        }
1001    std::abort();
1002}
1003
1004}  // namespace strata::quant