forked from Opendigitalradio/ka9q-fec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dotprod.c
111 lines (95 loc) · 2.08 KB
/
dotprod.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* 16-bit signed integer dot product
* Switch to appropriate versions
* Copyright 2004 Phil Karn
* May be used under the terms of the GNU Lesser General Public License (LGPL)
*/
#include <stdlib.h>
#include "fec.h"
void *initdp_port(signed short coeffs[],int len);
long dotprod_port(void *p,signed short *b);
void freedp_port(void *p);
#ifdef __i386__
void *initdp_mmx(signed short coeffs[],int len);
void *initdp_sse2(signed short coeffs[],int len);
long dotprod_mmx(void *p,signed short *b);
long dotprod_sse2(void *p,signed short *b);
void freedp_mmx(void *p);
void freedp_sse2(void *p);
#endif
#ifdef __VEC__
void *initdp_av(signed short coeffs[],int len);
long dotprod_av(void *p,signed short *b);
void freedp_av(void *p);
#endif
/* Create and return a descriptor for use with the dot product function */
void *initdp(signed short coeffs[],int len){
find_cpu_mode();
switch(Cpu_mode){
case PORT:
default:
return initdp_port(coeffs,len);
#ifdef __i386__
case MMX:
case SSE:
return initdp_mmx(coeffs,len);
case SSE2:
return initdp_sse2(coeffs,len);
#endif
#ifdef __x86_64__
case SSE2:
return initdp_port(coeffs,len);
#endif
#ifdef __VEC__
case ALTIVEC:
return initdp_av(coeffs,len);
#endif
}
}
/* Free a dot product descriptor created earlier */
void freedp(void *p){
switch(Cpu_mode){
case PORT:
default:
return freedp_port(p);
#ifdef __i386__
case MMX:
case SSE:
return freedp_mmx(p);
case SSE2:
return freedp_sse2(p);
#endif
#ifdef __x86_64__
case SSE2:
return freedp_port(p);
#endif
#ifdef __VEC__
case ALTIVEC:
return freedp_av(p);
#endif
}
}
/* Compute a dot product given a descriptor and an input array
* The length is taken from the descriptor
*/
long dotprod(void *p,signed short a[]){
switch(Cpu_mode){
case PORT:
default:
return dotprod_port(p,a);
#ifdef __i386__
case MMX:
case SSE:
return dotprod_mmx(p,a);
case SSE2:
return dotprod_sse2(p,a);
#endif
#ifdef __x86_64__
case SSE2:
return dotprod_port(p,a);
#endif
#ifdef __VEC__
case ALTIVEC:
return dotprod_av(p,a);
#endif
}
}