• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* 16-bit signed integer dot product
2  * Switch to appropriate versions
3  * Copyright 2004 Phil Karn
4  * May be used under the terms of the GNU Lesser General Public License (LGPL)
5  */
6 #include <stdlib.h>
7 #include "fec.h"
8 
9 void *initdp_port(signed short coeffs[],int len);
10 long dotprod_port(void *p,signed short *b);
11 void freedp_port(void *p);
12 
13 #ifdef __i386__
14 void *initdp_mmx(signed short coeffs[],int len);
15 void *initdp_sse2(signed short coeffs[],int len);
16 long dotprod_mmx(void *p,signed short *b);
17 long dotprod_sse2(void *p,signed short *b);
18 void freedp_mmx(void *p);
19 void freedp_sse2(void *p);
20 #endif
21 
22 #ifdef __VEC__
23 void *initdp_av(signed short coeffs[],int len);
24 long dotprod_av(void *p,signed short *b);
25 void freedp_av(void *p);
26 #endif
27 
28 /* Create and return a descriptor for use with the dot product function */
initdp(signed short coeffs[],int len)29 void *initdp(signed short coeffs[],int len){
30   find_cpu_mode();
31 
32   switch(Cpu_mode){
33   case PORT:
34   default:
35     return initdp_port(coeffs,len);
36 #ifdef __i386__
37   case MMX:
38   case SSE:
39     return initdp_mmx(coeffs,len);
40   case SSE2:
41     return initdp_sse2(coeffs,len);
42 #endif
43 
44 #ifdef __VEC__
45   case ALTIVEC:
46     return initdp_av(coeffs,len);
47 #endif
48   }
49 }
50 
51 
52 /* Free a dot product descriptor created earlier */
freedp(void * p)53 void freedp(void *p){
54   switch(Cpu_mode){
55   case PORT:
56   default:
57 #ifdef __i386__
58   case MMX:
59   case SSE:
60     return freedp_mmx(p);
61   case SSE2:
62     return freedp_sse2(p);
63 #endif
64 #ifdef __VEC__
65   case ALTIVEC:
66     return freedp_av(p);
67 #endif
68   }
69 }
70 
71 /* Compute a dot product given a descriptor and an input array
72  * The length is taken from the descriptor
73  */
dotprod(void * p,signed short a[])74 long dotprod(void *p,signed short a[]){
75   switch(Cpu_mode){
76   case PORT:
77   default:
78     return dotprod_port(p,a);
79 #ifdef __i386__
80   case MMX:
81   case SSE:
82     return dotprod_mmx(p,a);
83   case SSE2:
84     return dotprod_sse2(p,a);
85 #endif
86 
87 #ifdef __VEC__
88   case ALTIVEC:
89     return dotprod_av(p,a);
90 #endif
91   }
92 }
93 
94 
95