1 // Copyright ©2016 The Gonum Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //+build !noasm,!appengine
10 #define MOVDDUP_X2_X3 BYTE $0xF2; BYTE $0x0F; BYTE $0x12; BYTE $0xDA
12 #define MOVDDUP_X4_X5 BYTE $0xF2; BYTE $0x0F; BYTE $0x12; BYTE $0xEC
14 #define MOVDDUP_X6_X7 BYTE $0xF2; BYTE $0x0F; BYTE $0x12; BYTE $0xFE
16 #define MOVDDUP_X8_X9 BYTE $0xF2; BYTE $0x45; BYTE $0x0F; BYTE $0x12; BYTE $0xC8
19 #define ADDSUBPD_X2_X3 BYTE $0x66; BYTE $0x0F; BYTE $0xD0; BYTE $0xDA
21 #define ADDSUBPD_X4_X5 BYTE $0x66; BYTE $0x0F; BYTE $0xD0; BYTE $0xEC
23 #define ADDSUBPD_X6_X7 BYTE $0x66; BYTE $0x0F; BYTE $0xD0; BYTE $0xFE
25 #define ADDSUBPD_X8_X9 BYTE $0x66; BYTE $0x45; BYTE $0x0F; BYTE $0xD0; BYTE $0xC8
27 // func AxpyInc(alpha complex128, x, y []complex128, n, incX, incY, ix, iy uintptr)
28 TEXT ·AxpyInc(SB), NOSPLIT, $0
29 MOVQ x_base+16(FP), SI // SI = &x
30 MOVQ y_base+40(FP), DI // DI = &y
31 MOVQ n+64(FP), CX // CX = n
32 CMPQ CX, $0 // if n==0 { return }
34 MOVQ ix+88(FP), R8 // R8 = ix // Load the first index
35 SHLQ $4, R8 // R8 *= sizeof(complex128)
36 MOVQ iy+96(FP), R9 // R9 = iy
37 SHLQ $4, R9 // R9 *= sizeof(complex128)
38 LEAQ (SI)(R8*1), SI // SI = &(x[ix])
39 LEAQ (DI)(R9*1), DI // DI = &(y[iy])
40 MOVQ DI, DX // DX = DI // Separate Read/Write pointers
41 MOVQ incX+72(FP), R8 // R8 = incX
42 SHLQ $4, R8 // R8 *= sizeof(complex128)
43 MOVQ incY+80(FP), R9 // R9 = iy
44 SHLQ $4, R9 // R9 *= sizeof(complex128)
45 MOVUPS alpha+0(FP), X0 // X0 = { imag(a), real(a) }
47 SHUFPD $0x1, X1, X1 // X1 = { real(a), imag(a) }
48 MOVAPS X0, X10 // Copy X0 and X1 for pipelining
51 ANDQ $3, CX // CX = n % 4
52 SHRQ $2, BX // BX = floor( n / 4 )
53 JZ axpyi_tail // if BX == 0 { goto axpyi_tail }
56 MOVUPS (SI), X2 // X_i = { imag(x[i]), real(x[i]) }
58 LEAQ (SI)(R8*2), SI // SI = &(SI[incX*2])
62 // X_(i+1) = { real(x[i], real(x[i]) }
68 // X_i = { imag(x[i]), imag(x[i]) }
74 // X_i = { real(a) * imag(x[i]), imag(a) * imag(x[i]) }
75 // X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i]) }
86 // imag(result[i]): imag(a)*real(x[i]) + real(a)*imag(x[i]),
87 // real(result[i]): real(a)*real(x[i]) - imag(a)*imag(x[i])
94 // X_(i+1) = { imag(result[i]) + imag(y[i]), real(result[i]) + real(y[i]) }
97 LEAQ (DX)(R9*2), DX // DX = &(DX[incY*2])
100 MOVUPS X3, (DI) // dst[i] = X_(i+1)
101 MOVUPS X5, (DI)(R9*1)
104 MOVUPS X9, (DI)(R9*1)
105 LEAQ (SI)(R8*2), SI // SI = &(SI[incX*2])
106 LEAQ (DX)(R9*2), DX // DX = &(DX[incY*2])
107 LEAQ (DI)(R9*2), DI // DI = &(DI[incY*2])
109 JNZ axpyi_loop // } while --BX > 0
110 CMPQ CX, $0 // if CX == 0 { return }
114 MOVUPS (SI), X2 // X_i = { imag(x[i]), real(x[i]) }
115 MOVDDUP_X2_X3 // X_(i+1) = { real(x[i], real(x[i]) }
116 SHUFPD $0x3, X2, X2 // X_i = { imag(x[i]), imag(x[i]) }
117 MULPD X1, X2 // X_i = { real(a) * imag(x[i]), imag(a) * imag(x[i]) }
118 MULPD X0, X3 // X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i]) }
121 // imag(result[i]): imag(a)*real(x[i]) + real(a)*imag(x[i]),
122 // real(result[i]): real(a)*real(x[i]) - imag(a)*imag(x[i])
126 // X_(i+1) = { imag(result[i]) + imag(y[i]), real(result[i]) + real(y[i]) }
128 MOVUPS X3, (DI) // y[i] = X_i
129 ADDQ R8, SI // SI = &(SI[incX])
130 ADDQ R9, DI // DI = &(DI[incY])
131 LOOP axpyi_tail // } while --CX > 0