gonum.org/v1/gonum@v0.14.0/internal/asm/c64/dotuinc_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  
    35  // func DotuInc(x, y []complex64, n, incX, incY, ix, iy uintptr) (sum complex64)
    36  TEXT ·DotuInc(SB), NOSPLIT, $0
    37  	MOVQ x_base+0(FP), X_PTR     // X_PTR = &x
    38  	MOVQ y_base+24(FP), Y_PTR    // Y_PTR = &y
    39  	PXOR SUM, SUM                // SUM = 0
    40  	PXOR P_SUM, P_SUM            // P_SUM = 0
    41  	MOVQ n+48(FP), LEN           // LEN = n
    42  	CMPQ LEN, $0                 // if LEN == 0 { return }
    43  	JE   dotu_end
    44  	MOVQ ix+72(FP), INC_X
    45  	MOVQ iy+80(FP), INC_Y
    46  	LEAQ (X_PTR)(INC_X*8), X_PTR // X_PTR = &(X_PTR[ix])
    47  	LEAQ (Y_PTR)(INC_Y*8), Y_PTR // Y_PTR = &(Y_PTR[iy])
    48  	MOVQ incX+56(FP), INC_X      // INC_X = incX * sizeof(complex64)
    49  	SHLQ $3, INC_X
    50  	MOVQ incY+64(FP), INC_Y      // INC_Y = incY * sizeof(complex64)
    51  	SHLQ $3, INC_Y
    52  
    53  	MOVQ LEN, TAIL
    54  	ANDQ $3, TAIL  // TAIL = LEN % 4
    55  	SHRQ $2, LEN   // LEN = floor( LEN / 4 )
    56  	JZ   dotu_tail // if TAIL == 0 { goto dotu_tail }
    57  
    58  	LEAQ (INC_X)(INC_X*2), INCx3_X // INCx3_X = INC_X * 3
    59  	LEAQ (INC_Y)(INC_Y*2), INCx3_Y // INCx3_Y = INC_Y * 3
    60  
    61  dotu_loop: // do {
    62  	MOVSD (X_PTR), X3            // X_i = { imag(x[i]), real(x[i]) }
    63  	MOVSD (X_PTR)(INC_X*1), X5
    64  	MOVSD (X_PTR)(INC_X*2), X7
    65  	MOVSD (X_PTR)(INCx3_X*1), X9
    66  
    67  	// X_(i-1) = { imag(x[i]), imag(x[i]) }
    68  	MOVSHDUP_X3_X2
    69  	MOVSHDUP_X5_X4
    70  	MOVSHDUP_X7_X6
    71  	MOVSHDUP_X9_X8
    72  
    73  	// X_i = { real(x[i]), real(x[i]) }
    74  	MOVSLDUP_X3_X3
    75  	MOVSLDUP_X5_X5
    76  	MOVSLDUP_X7_X7
    77  	MOVSLDUP_X9_X9
    78  
    79  	// X_j = { imag(y[i]), real(y[i]) }
    80  	MOVSD (Y_PTR), X10
    81  	MOVSD (Y_PTR)(INC_Y*1), X11
    82  	MOVSD (Y_PTR)(INC_Y*2), X12
    83  	MOVSD (Y_PTR)(INCx3_Y*1), X13
    84  
    85  	// X_i = { imag(y[i]) * real(x[i]), real(y[i]) * real(x[i]) }
    86  	MULPS X10, X3
    87  	MULPS X11, X5
    88  	MULPS X12, X7
    89  	MULPS X13, X9
    90  
    91  	// X_j = { real(y[i]), imag(y[i]) }
    92  	SHUFPS $0xB1, X10, X10
    93  	SHUFPS $0xB1, X11, X11
    94  	SHUFPS $0xB1, X12, X12
    95  	SHUFPS $0xB1, X13, X13
    96  
    97  	// X_(i-1) = { real(y[i]) * imag(x[i]), imag(y[i]) * imag(x[i]) }
    98  	MULPS X10, X2
    99  	MULPS X11, X4
   100  	MULPS X12, X6
   101  	MULPS X13, X8
   102  
   103  	// X_i = {
   104  	//	imag(result[i]):  imag(y[i]) * real(x[i]) + real(y[i]) * imag(x[i]),
   105  	//	real(result[i]):  real(y[i]) * real(x[i]) - imag(y[i]) * imag(x[i])  }
   106  	ADDSUBPS_X2_X3
   107  	ADDSUBPS_X4_X5
   108  	ADDSUBPS_X6_X7
   109  	ADDSUBPS_X8_X9
   110  
   111  	// SUM += X_i
   112  	ADDPS X3, SUM
   113  	ADDPS X5, P_SUM
   114  	ADDPS X7, SUM
   115  	ADDPS X9, P_SUM
   116  
   117  	LEAQ (X_PTR)(INC_X*4), X_PTR // X_PTR = &(X_PTR[INC_X*4])
   118  	LEAQ (Y_PTR)(INC_Y*4), Y_PTR // Y_PTR = &(Y_PTR[INC_Y*4])
   119  
   120  	DECQ LEN
   121  	JNZ  dotu_loop // } while --LEN > 0
   122  
   123  	ADDPS P_SUM, SUM // SUM = { P_SUM + SUM }
   124  	CMPQ  TAIL, $0   // if TAIL == 0 { return }
   125  	JE    dotu_end
   126  
   127  dotu_tail: // do {
   128  	MOVSD  (X_PTR), X3    // X_i = { imag(x[i]), real(x[i]) }
   129  	MOVSHDUP_X3_X2        // X_(i-1) = { imag(x[i]), imag(x[i]) }
   130  	MOVSLDUP_X3_X3        // X_i = { real(x[i]), real(x[i]) }
   131  	MOVUPS (Y_PTR), X10   // X_j = { imag(y[i]), real(y[i]) }
   132  	MULPS  X10, X3        // X_i = { imag(y[i]) * real(x[i]), real(y[i]) * real(x[i]) }
   133  	SHUFPS $0x1, X10, X10 // X_j = { real(y[i]), imag(y[i]) }
   134  	MULPS  X10, X2        // X_(i-1) = { real(y[i]) * imag(x[i]), imag(y[i]) * imag(x[i]) }
   135  
   136  	// X_i = {
   137  	//	imag(result[i]):  imag(y[i])*real(x[i]) + real(y[i])*imag(x[i]),
   138  	//	real(result[i]):  real(y[i])*real(x[i]) - imag(y[i])*imag(x[i])  }
   139  	ADDSUBPS_X2_X3
   140  	ADDPS X3, SUM      // SUM += X_i
   141  	ADDQ  INC_X, X_PTR // X_PTR += INC_X
   142  	ADDQ  INC_Y, Y_PTR // Y_PTR += INC_Y
   143  	DECQ  TAIL
   144  	JNZ   dotu_tail    // } while --TAIL > 0
   145  
   146  dotu_end:
   147  	MOVSD SUM, sum+88(FP) // return SUM
   148  	RET