summaryrefslogtreecommitdiff
path: root/liboil/i386_amd64/sum.c
blob: 6946450f0f9977a8eff49e83ca9fbc3a04d49a9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#include <liboil/liboilfunction.h>
#include <liboil/liboilclasses.h>


void
sum_s16_mmx (int16_t *d, int16_t *s, int n)
{
  int16_t sum = 0;
  int16_t a[4];

  while(n&15) {
    sum += s[0];
    s++;
    n--;
  }
  if (n > 0) {

    n >>= 4;
    asm volatile ("\n"
        "  pxor %%mm0, %%mm0\n"
        "1:\n"
        "  paddw 0(%0), %%mm0\n"
        "  paddw 8(%0), %%mm0\n"
        "  paddw 16(%0), %%mm0\n"
        "  paddw 24(%0), %%mm0\n"
        "  add $32, %0\n"
        "  decl %1\n"
        "  jnz 1b\n"
        "  movq %%mm0, 0(%2)\n"
        "  emms\n"
        : "+r" (s), "+r" (n)
        : "r" (a)
        : "memory");

    sum += a[0];
    sum += a[1];
    sum += a[2];
    sum += a[3];
  }

  d[0] = sum;
}
OIL_DEFINE_IMPL_FULL (sum_s16_mmx, sum_s16, OIL_IMPL_FLAG_MMX);