Commit 34bb65674 for llama.cpp

commit 34bb65674c44746c9278fa25d79c97b26ca015b0
Author: Aaron Teo <aaron.teo1@ibm.com>
Date:   Fri Dec 4 21:43:55 2026 +0800

    ggml-cpu(s390x): use optimized kernels (#33260)

    Signed-off-by: Aaron Teo <aaron.teo1@ibm.com>

diff --git a/ggml/src/ggml-cpu/arch/s390/quants.c b/ggml/src/ggml-cpu/arch/s390/quants.c
index 53a3d14ec..5c6a57436 100644
--- a/ggml/src/ggml-cpu/arch/s390/quants.c
+++ b/ggml/src/ggml-cpu/arch/s390/quants.c
@@ -1390,6 +1390,8 @@ void ggml_vec_dot_iq4_nl_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const v
     const int8x16_t v_k = vec_xl(0, kvalues_iq4nl);
     const uint8x16_t v_m = vec_splat_u8(0x0F);

+    float32x4_t acc = vec_splats(0.0f);
+
     for (; ib < nb; ++ib) {
         const block_iq4_nl * GGML_RESTRICT x0 = &x[ib];
         const block_q8_0   * GGML_RESTRICT y0 = &y[ib];
@@ -1404,10 +1406,13 @@ void ggml_vec_dot_iq4_nl_q8_0(int n, float * GGML_RESTRICT s, size_t bs, const v
         const int8x16_t v_yl = vec_xl(0      , y0->qs);
         const int8x16_t v_yh = vec_xl(QK8_0/2, y0->qs);
         const int32x4_t v_xy = ggml_vec_dot_s32(ggml_vec_dot_s32(vec_splats(0), v_xl, v_yl), v_xh, v_yh);
+        const float32x4_t v_d = vec_splats(GGML_CPU_FP16_TO_FP32(x0->d) * GGML_CPU_FP16_TO_FP32(y0->d));

-        sumf += GGML_CPU_FP16_TO_FP32(x0->d) * GGML_CPU_FP16_TO_FP32(y0->d) * vec_hsum_i32x4(v_xy);
+        acc = vec_madd(vec_float(v_xy), v_d, acc);
     }

+    sumf = vec_hsum_f32x4(acc);
+
     *s = sumf;
 #else
     UNUSED(x);
diff --git a/ggml/src/ggml-cpu/llamafile/sgemm.cpp b/ggml/src/ggml-cpu/llamafile/sgemm.cpp
index 5ddb850fa..256ffa451 100644
--- a/ggml/src/ggml-cpu/llamafile/sgemm.cpp
+++ b/ggml/src/ggml-cpu/llamafile/sgemm.cpp
@@ -1529,10 +1529,13 @@ class tinyBLAS_QK_VXE {

                 // the columns are in the inner loop, so that their sums do not wait for each other
                 int32x4_t v_dot[RN] = {};
-                for (int32_t g = 0; g < n_group; ++g) {
+                for (int32_t g = 0; g < n_group; g += group_step) {
                     for (int32_t j = 0; j < RN; ++j) {
                         const int8x16_t v_y = vec_xl(0, y_qs[j] + 16 * g);
-                        const int16x8_t v_xy = vec_meadd(v_x[g], v_y, vec_mulo(v_x[g], v_y));
+                        int16x8_t v_xy = vec_meadd(v_x[g], v_y, vec_mulo(v_x[g], v_y));
+                        if (group_step == 2) {
+                            v_xy = ggml_vec_dot_s16(v_xy, v_x[g + 1], vec_xl(0, y_qs[j] + 16 * (g + 1)));
+                        }
                         v_dot[j] = vec_meadd(v_xy, v_scale[g], vec_moadd(v_xy, v_scale[g], v_dot[j]));
                     }
                 }
@@ -1572,6 +1575,9 @@ class tinyBLAS_QK_VXE {
     // Q3_K and Q6_K have no minimum, their weights are loaded as signed values.
     static constexpr bool has_min = !std::is_same<TA, block_q3_K>::value && !std::is_same<TA, block_q6_K>::value;

+    // Q4_K and Q5_K sum 2 groups with the same scale in 16 bits, 4 products of at most 31 * 127 fit
+    static constexpr int32_t group_step = std::is_same<TA, block_q4_K>::value || std::is_same<TA, block_q5_K>::value ? 2 : 1;
+
     static float dmin(const block_q2_K & x) { return unhalf(x.dmin); }
     static float dmin(const block_q4_K & x) { return unhalf(x.dmin); }
     static float dmin(const block_q5_K & x) { return unhalf(x.dmin); }