Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-core / src / lib / filter / float_dotprod_sse64.S
1 #
2 # Copyright 2002,2005 Free Software Foundation, Inc.
3
4 # This file is part of GNU Radio
5
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING.  If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
20
21
22
23 # input and taps are guarenteed to be 16 byte aligned.
24 # n_4_float_blocks is != 0
25 #       
26 #
27 #  float 
28 #  float_dotprod_generic (const float *input,
29 #                         const float *taps, unsigned n_4_float_blocks)
30 #  {
31 #    float sum0 = 0;
32 #    float sum1 = 0;
33 #    float sum2 = 0;
34 #    float sum3 = 0;
35 #  
36 #    do {
37 #  
38 #      sum0 += input[0] * taps[0];
39 #      sum1 += input[1] * taps[1];
40 #      sum2 += input[2] * taps[2];
41 #      sum3 += input[3] * taps[3];
42 #  
43 #      input += 4;
44 #      taps += 4;
45 #  
46 #    } while (--n_4_float_blocks != 0);
47 #  
48 #  
49 #    return sum0 + sum1 + sum2 + sum3;
50 #  }
51 #               
52
53 #include "assembly.h"
54
55
56         .file   "float_dotprod_sse64.S"
57         .version        "01.01"
58 .text
59         .p2align 4
60 .globl GLOB_SYMB(float_dotprod_sse)
61         DEF_FUNC_HEAD(float_dotprod_sse)
62 GLOB_SYMB(float_dotprod_sse):
63
64         # intput: rdi, taps: rsi, n_2_ccomplex_blocks: rdx
65
66         mov     %rdx, %rax
67
68         # xmm0 xmm1 xmm2 xmm3 are used to hold taps and the result of mults
69         # xmm4 xmm5 xmm6 xmm7 are used to hold the accumulated results
70
71         xorps   %xmm4, %xmm4            # zero two accumulators
72         xorps   %xmm5, %xmm5            # xmm5 holds zero for use below
73
74         # first handle any non-zero remainder of (n_4_float_blocks % 4)
75
76         and     $0x3, %rax
77         jmp     .L1_test
78
79         .p2align 4
80 .loop1: 
81         movaps  (%rsi), %xmm0
82         mulps   (%rdi), %xmm0
83         add     $0x10, %rdi
84         add     $0x10, %rsi
85         addps   %xmm0, %xmm4
86 .L1_test:       
87         dec     %rax
88         jge     .loop1
89
90         
91         # set up for primary loop which is unrolled 4 times
92         
93         movaps  %xmm5, %xmm6            # zero remaining accumulators
94         movaps  %xmm5, %xmm7 
95
96         shr     $2, %rdx                # n_4_float_blocks / 4
97         je      .cleanup                # if zero, take short path
98
99         # finish setup and loop priming
100
101         movaps  0x00(%rsi), %xmm0
102         movaps  %xmm5, %xmm2            
103         movaps  0x10(%rsi), %xmm1
104         movaps  %xmm5, %xmm3
105
106         # we know rdx is not zero, we checked above,
107         # hence enter loop at top
108
109         .p2align 4
110 .loop2:
111         mulps   (%rdi), %xmm0
112         addps   %xmm2, %xmm6
113         movaps  0x20(%rsi), %xmm2
114
115         mulps   0x10(%rdi), %xmm1
116         addps   %xmm3, %xmm7
117         movaps  0x30(%rsi), %xmm3
118
119         mulps   0x20(%rdi), %xmm2
120         addps   %xmm0, %xmm4
121         movaps  0x40(%rsi), %xmm0
122
123         mulps   0x30(%rdi), %xmm3
124         addps   %xmm1, %xmm5
125         movaps  0x50(%rsi), %xmm1
126
127         add     $0x40, %rdi
128         add     $0x40, %rsi
129         dec     %rdx
130         jne     .loop2
131
132         # OK, now we've done with all the multiplies, but
133         # we still need to handle the unaccumulated
134         # products in xmm2 and xmm3
135
136         addps   %xmm2, %xmm6
137         addps   %xmm3, %xmm7
138
139         # now we want to add all accumulators into xmm4
140
141         addps   %xmm5, %xmm4
142         addps   %xmm6, %xmm7
143         addps   %xmm7, %xmm4
144
145         
146         # At this point, xmm4 contains 4 partial sums.  We need
147         # to compute a "horizontal add" across xmm4.  
148         # This is a fairly nasty operation...
149         
150 .cleanup:                               # xmm4 = d1 d2 d3 d4
151         xorps   %xmm0, %xmm0            # xmm0 = 0 0 0 0  (may be unnecessary)
152         movhlps %xmm4, %xmm0            # xmm0 = 0 0 d1 d2
153         addps   %xmm4, %xmm0            # xmm0 = d1 d2 d1+d3 d2+d4
154         movaps  %xmm0, %xmm1            # xmm1 = d1 d2 d1+d3 d2+d4
155         shufps  $0xE1, %xmm4, %xmm1     # xmm1 = d1 d2 d2+d4 d1+d3
156         addss   %xmm1, %xmm0            # xmm1 = d1 d2 d1+d3 d1+d2+d3+d4
157
158         retq
159
160 FUNC_TAIL(float_dotprod_sse)
161         .ident  "Hand coded x86_64 SSE assembly"