@@ -3428,48 +3428,6 @@ void dequantize_row_q1_3(const block_q1_3 * restrict x, float * restrict y, int6
3428
3428
const int64_t nb = k / QK1_3;
3429
3429
static_assert(sizeof(x->q) % 4 == 0, "bad block_q1_3.q size");
3430
3430
3431
- // #if defined(__SSE2__)
3432
- // __m128 vscale = _mm_set1_ps(scale);
3433
-
3434
- // for (int64_t i = 0; i < nb; ++i) {
3435
- // for (size_t j = 0; j < sizeof(x->q); j += 4) {
3436
- // __m128 q1 = _mm_cvtpi8_ps(_m_from_int(q1_3_grid[x[i].q[j + 0]]));
3437
- // __m128 q2 = _mm_cvtpi8_ps(_m_from_int(q1_3_grid[x[i].q[j + 1]]));
3438
- // __m128 q3 = _mm_cvtpi8_ps(_m_from_int(q1_3_grid[x[i].q[j + 2]]));
3439
- // __m128 q4 = _mm_cvtpi8_ps(_m_from_int(q1_3_grid[x[i].q[j + 3]]));
3440
- // q1 = _mm_mul_ps(q1, vscale);
3441
- // q2 = _mm_mul_ps(q2, vscale);
3442
- // q3 = _mm_mul_ps(q3, vscale);
3443
- // q4 = _mm_mul_ps(q4, vscale);
3444
-
3445
- // _mm_store_ps(y + 0, q1);
3446
- // _mm_store_ps(y + 4, q2);
3447
- // _mm_store_ps(y + 8, q3);
3448
- // _mm_store_ps(y + 12, q4);
3449
- // y += 16;
3450
- // }
3451
-
3452
- // for (size_t j = 0; j < sizeof(x->q); j += 4) {
3453
- // __m128i q5i = _mm_loadu_si32(x[i].q + j);
3454
- // q5i = _mm_cvtepi8_epi16(q5i);
3455
- // q5i = _mm_add_epi16(q5i, _mm_add_epi16(q5i, q5i));
3456
- // q5i = _mm_srli_epi16(q5i, 8);
3457
- // q5i = _mm_sub_epi16(q5i, _mm_set1_epi16(1));
3458
- // __m128 q5 = _mm_cvtepi32_ps(_mm_cvtepi16_epi32(q5i));
3459
- // q5 = _mm_mul_ps(q5, vscale);
3460
-
3461
- // _mm_store_ps(y, q5);
3462
- // y += 4;
3463
- // }
3464
-
3465
- // for (size_t j = 0; j < sizeof(x->qs); ++j) {
3466
- // __m128 q = _mm_cvtpi8_ps(_m_from_int(q1_3_grid[x[i].qs[j]]));
3467
- // q = _mm_mul_ps(q, vscale);
3468
- // _mm_store_ps(y, q);
3469
- // y += 4;
3470
- // }
3471
- // }
3472
- // #else
3473
3431
for (int64_t i = 0; i < nb; ++i) {
3474
3432
for (size_t j = 0; j < sizeof(x->q); ++j) {
3475
3433
const int8_t * q = (const int8_t *) (q1_3_grid + x[i].q[j]);
@@ -3490,7 +3448,6 @@ void dequantize_row_q1_3(const block_q1_3 * restrict x, float * restrict y, int6
3490
3448
}
3491
3449
}
3492
3450
}
3493
- // #endif
3494
3451
}
3495
3452
3496
3453
// ====================== "True" 2-bit (de)-quantization
@@ -10945,14 +10902,15 @@ void ggml_vec_dot_q1_3_q8_0(int n, float * restrict s, size_t bs, const void * r
10945
10902
__m256 accumf = _mm256_setzero_ps();
10946
10903
10947
10904
for (int i = 0; i < nb; ++i) {
10948
- // const __m128i x12b = _mm_maskload_epi32((const int32_t *) x[i].q , _mm_set_epi32(0, -1, -1, -1));
10949
- // const __m128i x12b = _mm_insert_epi8(x12a, x[i]. qs[0], 12);
10905
+ // const __m128i x12a = _mm_maskload_epi32((const int32_t *) x, _mm_set_epi32(0, -1, -1, -1));
10906
+ // const __m128i x12b = _mm_insert_epi8(x12a, x-> qs[0], 12);
10950
10907
// WARNING: reading 3 bytes further than necessary.
10951
10908
// It's measurably faster than a masked load on an Intel Core m3-8100Y
10952
- const __m128i x12b = _mm_loadu_si128((const __m128i_u *) (x[i].q) );
10909
+ const __m128i x12b = _mm_loadu_si128((const __m128i_u *) x );
10953
10910
const __m256i x12 = MM256_SET_M128I(x12b, x12b);
10954
10911
10955
10912
{
10913
+ // pre-shift the values by 8 bits, and prepare the layout for later packing
10956
10914
__m256i x0l = _mm256_shuffle_epi8(x12, _mm256_set_epi8(5, -1, 5, -1, 5, -1, 5, -1,
10957
10915
4, -1, 4, -1, 4, -1, 4, -1,
10958
10916
1, -1, 1, -1, 1, -1, 1, -1,
@@ -10973,8 +10931,8 @@ void ggml_vec_dot_q1_3_q8_0(int n, float * restrict s, size_t bs, const void * r
10973
10931
3, 9, 27, 81,
10974
10932
3, 9, 27, 81,
10975
10933
3, 9, 27, 81);
10976
- const __m256i shift1l = _mm256_set_epi16(1, 1, 1, 1,
10977
- 1, 1, 1, 1,
10934
+ const __m256i shift1l = _mm256_set_epi16(1, 1, 1, 1,
10935
+ 1, 1, 1, 1,
10978
10936
3, 9, 27, 81,
10979
10937
3, 9, 27, 81);
10980
10938
const __m256i shift1h = _mm256_set_epi16(3, 9, 27, 81,
@@ -10998,18 +10956,21 @@ void ggml_vec_dot_q1_3_q8_0(int n, float * restrict s, size_t bs, const void * r
10998
10956
x0 = _mm256_sub_epi8(x0, _mm256_set1_epi8(1));
10999
10957
x1 = _mm256_sub_epi8(x1, _mm256_set1_epi8(1));
11000
10958
11001
- const __m256i y0 = _mm256_loadu_si256((const __m256i_u *) (y[2*i + 0].qs));
11002
- const __m256i y1 = _mm256_loadu_si256((const __m256i_u *) (y[2*i + 1].qs));
10959
+ const __m256i y0 = _mm256_loadu_si256((const __m256i_u *) (y[0].qs));
10960
+ const __m256i y1 = _mm256_loadu_si256((const __m256i_u *) (y[1].qs));
11003
10961
11004
- const __m256 d0 = _mm256_set1_ps(GGML_FP16_TO_FP32(y[2*i + 0].d));
11005
- const __m256 d1 = _mm256_set1_ps(GGML_FP16_TO_FP32(y[2*i + 1].d));
10962
+ const __m256 d0 = _mm256_set1_ps(GGML_FP16_TO_FP32(y[0].d));
10963
+ const __m256 d1 = _mm256_set1_ps(GGML_FP16_TO_FP32(y[1].d));
11006
10964
11007
- const __m256 q0 = mul_sum_i8_pairs_float(x0, y0 );
11008
- const __m256 q1 = mul_sum_i8_pairs_float(x1, y1 );
10965
+ const __m256 q0 = mul_sum_i8_pairs_float(y0, x0 );
10966
+ const __m256 q1 = mul_sum_i8_pairs_float(y1, x1 );
11009
10967
11010
10968
accumf = _mm256_fmadd_ps(d0, q0, accumf);
11011
10969
accumf = _mm256_fmadd_ps(d1, q1, accumf);
11012
10970
}
10971
+
10972
+ x += 1;
10973
+ y += 2;
11013
10974
}
11014
10975
11015
10976
*s = hsum_float_8(accumf);
0 commit comments