gonum.org/v1/gonum@v0.14.0/internal/asm/c64/dotcinc_amd64.s (about) 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. 4 5 // +build !noasm,!gccgo,!safe 6 7 #include "textflag.h" 8 9 #define MOVSHDUP_X3_X2 LONG $0xD3160FF3 // MOVSHDUP X3, X2 10 #define MOVSHDUP_X5_X4 LONG $0xE5160FF3 // MOVSHDUP X5, X4 11 #define MOVSHDUP_X7_X6 LONG $0xF7160FF3 // MOVSHDUP X7, X6 12 #define MOVSHDUP_X9_X8 LONG $0x160F45F3; BYTE $0xC1 // MOVSHDUP X9, X8 13 14 #define MOVSLDUP_X3_X3 LONG $0xDB120FF3 // MOVSLDUP X3, X3 15 #define MOVSLDUP_X5_X5 LONG $0xED120FF3 // MOVSLDUP X5, X5 16 #define MOVSLDUP_X7_X7 LONG $0xFF120FF3 // MOVSLDUP X7, X7 17 #define MOVSLDUP_X9_X9 LONG $0x120F45F3; BYTE $0xC9 // MOVSLDUP X9, X9 18 19 #define ADDSUBPS_X2_X3 LONG $0xDAD00FF2 // ADDSUBPS X2, X3 20 #define ADDSUBPS_X4_X5 LONG $0xECD00FF2 // ADDSUBPS X4, X5 21 #define ADDSUBPS_X6_X7 LONG $0xFED00FF2 // ADDSUBPS X6, X7 22 #define ADDSUBPS_X8_X9 LONG $0xD00F45F2; BYTE $0xC8 // ADDSUBPS X8, X9 23 24 #define X_PTR SI 25 #define Y_PTR DI 26 #define LEN CX 27 #define TAIL BX 28 #define SUM X0 29 #define P_SUM X1 30 #define INC_X R8 31 #define INCx3_X R9 32 #define INC_Y R10 33 #define INCx3_Y R11 34 #define NEG1 X15 35 #define P_NEG1 X14 36 37 // func DotcInc(x, y []complex64, n, incX, incY, ix, iy uintptr) (sum complex64) 38 TEXT ·DotcInc(SB), NOSPLIT, $0 39 MOVQ x_base+0(FP), X_PTR // X_PTR = &x 40 MOVQ y_base+24(FP), Y_PTR // Y_PTR = &y 41 PXOR SUM, SUM // SUM = 0 42 PXOR P_SUM, P_SUM // P_SUM = 0 43 MOVQ n+48(FP), LEN // LEN = n 44 CMPQ LEN, $0 // if LEN == 0 { return } 45 JE dotc_end 46 MOVQ ix+72(FP), INC_X 47 MOVQ iy+80(FP), INC_Y 48 LEAQ (X_PTR)(INC_X*8), X_PTR // X_PTR = &(X_PTR[ix]) 49 LEAQ (Y_PTR)(INC_Y*8), Y_PTR // Y_PTR = &(Y_PTR[iy]) 50 MOVQ incX+56(FP), INC_X // INC_X = incX * sizeof(complex64) 51 SHLQ $3, INC_X 52 MOVQ incY+64(FP), INC_Y // INC_Y = incY * sizeof(complex64) 53 SHLQ $3, INC_Y 54 MOVSS $(-1.0), NEG1 55 SHUFPS $0, NEG1, NEG1 // { -1, -1, -1, -1 } 56 57 MOVQ LEN, TAIL 58 ANDQ $3, TAIL // TAIL = LEN % 4 59 SHRQ $2, LEN // LEN = floor( LEN / 4 ) 60 JZ dotc_tail // if LEN == 0 { goto dotc_tail } 61 62 MOVUPS NEG1, P_NEG1 // Copy NEG1 for pipelining 63 LEAQ (INC_X)(INC_X*2), INCx3_X // INCx3_X = INC_X * 3 64 LEAQ (INC_Y)(INC_Y*2), INCx3_Y // INCx3_Y = INC_Y * 3 65 66 dotc_loop: // do { 67 MOVSD (X_PTR), X3 // X_i = { imag(x[i]), real(x[i]) } 68 MOVSD (X_PTR)(INC_X*1), X5 69 MOVSD (X_PTR)(INC_X*2), X7 70 MOVSD (X_PTR)(INCx3_X*1), X9 71 72 // X_(i-1) = { imag(x[i]), imag(x[i]) } 73 MOVSHDUP_X3_X2 74 MOVSHDUP_X5_X4 75 MOVSHDUP_X7_X6 76 MOVSHDUP_X9_X8 77 78 // X_i = { real(x[i]), real(x[i]) } 79 MOVSLDUP_X3_X3 80 MOVSLDUP_X5_X5 81 MOVSLDUP_X7_X7 82 MOVSLDUP_X9_X9 83 84 // X_(i-1) = { -imag(x[i]), -imag(x[i]) } 85 MULPS NEG1, X2 86 MULPS P_NEG1, X4 87 MULPS NEG1, X6 88 MULPS P_NEG1, X8 89 90 // X_j = { imag(y[i]), real(y[i]) } 91 MOVSD (Y_PTR), X10 92 MOVSD (Y_PTR)(INC_Y*1), X11 93 MOVSD (Y_PTR)(INC_Y*2), X12 94 MOVSD (Y_PTR)(INCx3_Y*1), X13 95 96 // X_i = { imag(y[i]) * real(x[i]), real(y[i]) * real(x[i]) } 97 MULPS X10, X3 98 MULPS X11, X5 99 MULPS X12, X7 100 MULPS X13, X9 101 102 // X_j = { real(y[i]), imag(y[i]) } 103 SHUFPS $0xB1, X10, X10 104 SHUFPS $0xB1, X11, X11 105 SHUFPS $0xB1, X12, X12 106 SHUFPS $0xB1, X13, X13 107 108 // X_(i-1) = { real(y[i]) * imag(x[i]), imag(y[i]) * imag(x[i]) } 109 MULPS X10, X2 110 MULPS X11, X4 111 MULPS X12, X6 112 MULPS X13, X8 113 114 // X_i = { 115 // imag(result[i]): imag(y[i]) * real(x[i]) + real(y[i]) * imag(x[i]), 116 // real(result[i]): real(y[i]) * real(x[i]) - imag(y[i]) * imag(x[i]) } 117 ADDSUBPS_X2_X3 118 ADDSUBPS_X4_X5 119 ADDSUBPS_X6_X7 120 ADDSUBPS_X8_X9 121 122 // SUM += X_i 123 ADDPS X3, SUM 124 ADDPS X5, P_SUM 125 ADDPS X7, SUM 126 ADDPS X9, P_SUM 127 128 LEAQ (X_PTR)(INC_X*4), X_PTR // X_PTR = &(X_PTR[INC_X*4]) 129 LEAQ (Y_PTR)(INC_Y*4), Y_PTR // Y_PTR = &(Y_PTR[INC_Y*4]) 130 131 DECQ LEN 132 JNZ dotc_loop // } while --LEN > 0 133 134 ADDPS P_SUM, SUM // SUM = { P_SUM + SUM } 135 CMPQ TAIL, $0 // if TAIL == 0 { return } 136 JE dotc_end 137 138 dotc_tail: // do { 139 MOVSD (X_PTR), X3 // X_i = { imag(x[i]), real(x[i]) } 140 MOVSHDUP_X3_X2 // X_(i-1) = { imag(x[i]), imag(x[i]) } 141 MOVSLDUP_X3_X3 // X_i = { real(x[i]), real(x[i]) } 142 MULPS NEG1, X2 // X_(i-1) = { -imag(x[i]), imag(x[i]) } 143 MOVUPS (Y_PTR), X10 // X_j = { imag(y[i]), real(y[i]) } 144 MULPS X10, X3 // X_i = { imag(y[i]) * real(x[i]), real(y[i]) * real(x[i]) } 145 SHUFPS $0x1, X10, X10 // X_j = { real(y[i]), imag(y[i]) } 146 MULPS X10, X2 // X_(i-1) = { real(y[i]) * imag(x[i]), imag(y[i]) * imag(x[i]) } 147 148 // X_i = { 149 // imag(result[i]): imag(y[i])*real(x[i]) + real(y[i])*imag(x[i]), 150 // real(result[i]): real(y[i])*real(x[i]) - imag(y[i])*imag(x[i]) } 151 ADDSUBPS_X2_X3 152 ADDPS X3, SUM // SUM += X_i 153 ADDQ INC_X, X_PTR // X_PTR += INC_X 154 ADDQ INC_Y, Y_PTR // Y_PTR += INC_Y 155 DECQ TAIL 156 JNZ dotc_tail // } while --TAIL > 0 157 158 dotc_end: 159 MOVSD SUM, sum+88(FP) // return SUM 160 RET