Debian Codegraph @

gcc/testsuite/gcc.dg/vect/pr117888-1.c

raw
1 /* { dg-do compile } */
2 /* { dg-options "-O3 -funroll-loops -fdump-tree-vect-details" } */
3 /* { dg-require-effective-target vect_int } */
4 /* { dg-require-effective-target vect_shift } */
5 /* { dg-additional-options "-mavx2" { target x86_64-*-* i?86-*-* } } */
6 /* { dg-additional-options "--param max-completely-peeled-insns=200" { target powerpc64*-*-* } } */
7 /* { dg-additional-options "-mlsx" { target loongarch64-*-* } } */
8 /* { dg-additional-options "--param max-completely-peeled-insns=200 --param min-vect-loop-bound=0" { target s390*-*-* } } */
9
10 typedef unsigned short ggml_fp16_t;
11 static float table_f32_f16[1 << 16];
12
13 inline static float ggml_lookup_fp16_to_fp32(ggml_fp16_t f) {
14 unsigned short s;
15 __builtin_memcpy(&s, &f, sizeof(unsigned short));
16 return table_f32_f16[s];
17 }
18
19 typedef struct {
20 ggml_fp16_t d;
21 ggml_fp16_t m;
22 unsigned char qh[4];
23 unsigned char qs[32 / 2];
24 } block_q5_1;
25
26 typedef struct {
27 float d;
28 float s;
29 char qs[32];
30 } block_q8_1;
31
32 void ggml_vec_dot_q5_1_q8_1(const int n, float * restrict s, const void * restrict vx, const void * restrict vy) {
33 const int qk = 32;
34 const int nb = n / qk;
35
36 const block_q5_1 * restrict x = vx;
37 const block_q8_1 * restrict y = vy;
38
39 float sumf = 0.0;
40
41 for (int i = 0; i < nb; i++) {
42 unsigned qh;
43 __builtin_memcpy(&qh, x[i].qh, sizeof(qh));
44
45 int sumi = 0;
46
47 if (qh) {
48 for (int j = 0; j < qk/2; ++j) {
49 const unsigned char xh_0 = ((qh >> (j + 0)) << 4) & 0x10;
50 const unsigned char xh_1 = ((qh >> (j + 12)) ) & 0x10;
51
52 const int x0 = (x[i].qs[j] & 0xF) | xh_0;
53 const int x1 = (x[i].qs[j] >> 4) | xh_1;
54
55 sumi += (x0 * y[i].qs[j]) + (x1 * y[i].qs[j + qk/2]);
56 }
57 }
58 else {
59 for (int j = 0; j < qk/2; ++j) {
60 const int x0 = (x[i].qs[j] & 0xF);
61 const int x1 = (x[i].qs[j] >> 4);
62
63 sumi += (x0 * y[i].qs[j]) + (x1 * y[i].qs[j + qk/2]);
64 }
65 }
66
67 sumf += (ggml_lookup_fp16_to_fp32(x[i].d)*y[i].d)*sumi + ggml_lookup_fp16_to_fp32(x[i].m)*y[i].s;
68 }
69
70 *s = sumf;
71 }
72
73 /* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */