| 1 |
/* { dg-options "-Ofast" } */ |
| 2 |
/* { dg-final { check-function-bodies "**" "" "" } } */ |
| 3 |
|
| 4 |
#include <arm_neon.h> |
| 5 |
#include <stddef.h> |
| 6 |
#include <stdbool.h> |
| 7 |
|
| 8 |
/* |
| 9 |
** simple_gemm: |
| 10 |
** ... |
| 11 |
** tbnz [^\n]+ |
| 12 |
** ld1 [^\n]+ |
| 13 |
** fadd [^\n]+ |
| 14 |
** fadd [^\n]+ |
| 15 |
** st1 [^\n]+ |
| 16 |
** ret |
| 17 |
*/ |
| 18 |
void simple_gemm( |
| 19 |
float* restrict out, |
| 20 |
float const* restrict a, |
| 21 |
float const* restrict b, |
| 22 |
size_t k, bool zero_out |
| 23 |
) { |
| 24 |
register float32x4x2_t o0; |
| 25 |
o0.val[0] = vdupq_n_f32(0.0f); |
| 26 |
o0.val[1] = vdupq_n_f32(0.0f); |
| 27 |
|
| 28 |
// begin dot |
| 29 |
{ |
| 30 |
register float32x4_t a0; |
| 31 |
register float32x4x2_t b0; |
| 32 |
|
| 33 |
while (k >= 1) { |
| 34 |
b0 = vld1q_f32_x2(b); |
| 35 |
a0 = vdupq_n_f32(a[0]); |
| 36 |
|
| 37 |
o0.val[0] = vfmaq_f32(o0.val[0], a0, b0.val[0]); |
| 38 |
o0.val[1] = vfmaq_f32(o0.val[1], a0, b0.val[1]); |
| 39 |
|
| 40 |
b += 8; |
| 41 |
a += 1; |
| 42 |
k -= 1; |
| 43 |
} |
| 44 |
} // end dot |
| 45 |
|
| 46 |
// begin writeback |
| 47 |
{ |
| 48 |
if (!zero_out) { |
| 49 |
register float32x4x2_t t0; |
| 50 |
t0 = vld1q_f32_x2(out); |
| 51 |
|
| 52 |
o0.val[0] = vaddq_f32(o0.val[0], t0.val[0]); |
| 53 |
o0.val[1] = vaddq_f32(o0.val[1], t0.val[1]); |
| 54 |
} |
| 55 |
|
| 56 |
// TODO: both clang and gcc generates redundant mov because of bad register allocation. |
| 57 |
vst1q_f32_x2(out, o0); |
| 58 |
} // end writeback |
| 59 |
} |