gonum.org/v1/gonum@v0.14.0/internal/asm/c128/dotcunitary_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 MOVDDUP_XPTR_IDX_8__X3    LONG $0x1C120FF2; BYTE $0xC6 // MOVDDUP (SI)(AX*8), X3
    10  #define MOVDDUP_16_XPTR_IDX_8__X5    LONG $0x6C120FF2; WORD $0x10C6 // MOVDDUP 16(SI)(AX*8), X5
    11  #define MOVDDUP_32_XPTR_IDX_8__X7    LONG $0x7C120FF2; WORD $0x20C6 // MOVDDUP 32(SI)(AX*8), X7
    12  #define MOVDDUP_48_XPTR_IDX_8__X9    LONG $0x120F44F2; WORD $0xC64C; BYTE $0x30 // MOVDDUP 48(SI)(AX*8), X9
    13  
    14  #define MOVDDUP_XPTR_IIDX_8__X2    LONG $0x14120FF2; BYTE $0xD6 // MOVDDUP (SI)(DX*8), X2
    15  #define MOVDDUP_16_XPTR_IIDX_8__X4    LONG $0x64120FF2; WORD $0x10D6 // MOVDDUP 16(SI)(DX*8), X4
    16  #define MOVDDUP_32_XPTR_IIDX_8__X6    LONG $0x74120FF2; WORD $0x20D6 // MOVDDUP 32(SI)(DX*8), X6
    17  #define MOVDDUP_48_XPTR_IIDX_8__X8    LONG $0x120F44F2; WORD $0xD644; BYTE $0x30 // MOVDDUP 48(SI)(DX*8), X8
    18  
    19  #define ADDSUBPD_X2_X3    LONG $0xDAD00F66 // ADDSUBPD X2, X3
    20  #define ADDSUBPD_X4_X5    LONG $0xECD00F66 // ADDSUBPD X4, X5
    21  #define ADDSUBPD_X6_X7    LONG $0xFED00F66 // ADDSUBPD X6, X7
    22  #define ADDSUBPD_X8_X9    LONG $0xD00F4566; BYTE $0xC8 // ADDSUBPD 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 IDX AX
    31  #define I_IDX DX
    32  #define NEG1 X15
    33  #define P_NEG1 X14
    34  
    35  // func DotcUnitary(x, y []complex128) (sum complex128)
    36  TEXT ·DotcUnitary(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  	MOVQ    x_len+8(FP), LEN     // LEN = min( len(x), len(y) )
    40  	CMPQ    y_len+32(FP), LEN
    41  	CMOVQLE y_len+32(FP), LEN
    42  	PXOR    SUM, SUM             // sum = 0
    43  	CMPQ    LEN, $0              // if LEN == 0 { return }
    44  	JE      dot_end
    45  	XORPS   P_SUM, P_SUM         // psum = 0
    46  	MOVSD   $(-1.0), NEG1
    47  	SHUFPD  $0, NEG1, NEG1       // { -1, -1 }
    48  	XORQ    IDX, IDX             // i := 0
    49  	MOVQ    $1, I_IDX            // j := 1
    50  	MOVQ    LEN, TAIL
    51  	ANDQ    $3, TAIL             // TAIL = floor( TAIL / 4 )
    52  	SHRQ    $2, LEN              // LEN = TAIL % 4
    53  	JZ      dot_tail             // if LEN == 0 { goto dot_tail }
    54  
    55  	MOVAPS NEG1, P_NEG1 // Copy NEG1 to P_NEG1 for pipelining
    56  
    57  dot_loop: // do {
    58  	MOVDDUP_XPTR_IDX_8__X3    // X_(i+1) = { real(x[i], real(x[i]) }
    59  	MOVDDUP_16_XPTR_IDX_8__X5
    60  	MOVDDUP_32_XPTR_IDX_8__X7
    61  	MOVDDUP_48_XPTR_IDX_8__X9
    62  
    63  	MOVDDUP_XPTR_IIDX_8__X2    // X_i = { imag(x[i]), imag(x[i]) }
    64  	MOVDDUP_16_XPTR_IIDX_8__X4
    65  	MOVDDUP_32_XPTR_IIDX_8__X6
    66  	MOVDDUP_48_XPTR_IIDX_8__X8
    67  
    68  	// X_i = { -imag(x[i]), -imag(x[i]) }
    69  	MULPD NEG1, X2
    70  	MULPD P_NEG1, X4
    71  	MULPD NEG1, X6
    72  	MULPD P_NEG1, X8
    73  
    74  	// X_j = { imag(y[i]), real(y[i]) }
    75  	MOVUPS (Y_PTR)(IDX*8), X10
    76  	MOVUPS 16(Y_PTR)(IDX*8), X11
    77  	MOVUPS 32(Y_PTR)(IDX*8), X12
    78  	MOVUPS 48(Y_PTR)(IDX*8), X13
    79  
    80  	// X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i])  }
    81  	MULPD X10, X3
    82  	MULPD X11, X5
    83  	MULPD X12, X7
    84  	MULPD X13, X9
    85  
    86  	// X_j = { real(y[i]), imag(y[i]) }
    87  	SHUFPD $0x1, X10, X10
    88  	SHUFPD $0x1, X11, X11
    89  	SHUFPD $0x1, X12, X12
    90  	SHUFPD $0x1, X13, X13
    91  
    92  	// X_i     = { real(a) * imag(x[i]), imag(a) * imag(x[i])  }
    93  	MULPD X10, X2
    94  	MULPD X11, X4
    95  	MULPD X12, X6
    96  	MULPD X13, X8
    97  
    98  	// X_(i+1) = {
    99  	//	imag(result[i]):  imag(a)*real(x[i]) + real(a)*imag(x[i]),
   100  	//	real(result[i]):  real(a)*real(x[i]) - imag(a)*imag(x[i])
   101  	//  }
   102  	ADDSUBPD_X2_X3
   103  	ADDSUBPD_X4_X5
   104  	ADDSUBPD_X6_X7
   105  	ADDSUBPD_X8_X9
   106  
   107  	// psum += result[i]
   108  	ADDPD X3, SUM
   109  	ADDPD X5, P_SUM
   110  	ADDPD X7, SUM
   111  	ADDPD X9, P_SUM
   112  
   113  	ADDQ  $8, IDX    // IDX += 8
   114  	ADDQ  $8, I_IDX  // I_IDX += 8
   115  	DECQ  LEN
   116  	JNZ   dot_loop   // } while --LEN > 0
   117  	ADDPD P_SUM, SUM // sum += psum
   118  	CMPQ  TAIL, $0   // if TAIL == 0 { return }
   119  	JE    dot_end
   120  
   121  dot_tail: // do {
   122  	MOVDDUP_XPTR_IDX_8__X3     // X_(i+1) = {  real(x[i])          ,  real(x[i])           }
   123  	MOVDDUP_XPTR_IIDX_8__X2    // X_i     = {  imag(x[i])          ,  imag(x[i])           }
   124  	MULPD  NEG1, X2            // X_i     = { -imag(x[i])          , -imag(x[i])           }
   125  	MOVUPS (Y_PTR)(IDX*8), X10 // X_j     = {  imag(y[i])          ,  real(y[i])           }
   126  	MULPD  X10, X3             // X_(i+1) = {  imag(a) * real(x[i]),  real(a) * real(x[i]) }
   127  	SHUFPD $0x1, X10, X10      // X_j     = {  real(y[i])          ,  imag(y[i])           }
   128  	MULPD  X10, X2             // X_i     = {  real(a) * imag(x[i]),  imag(a) * imag(x[i]) }
   129  
   130  	// X_(i+1) = {
   131  	//	imag(result[i]):  imag(a)*real(x[i]) + real(a)*imag(x[i]),
   132  	//	real(result[i]):  real(a)*real(x[i]) - imag(a)*imag(x[i])
   133  	//  }
   134  	ADDSUBPD_X2_X3
   135  	ADDPD X3, SUM   // SUM += result[i]
   136  	ADDQ  $2, IDX   // IDX += 2
   137  	ADDQ  $2, I_IDX // I_IDX += 2
   138  	DECQ  TAIL
   139  	JNZ   dot_tail  // }  while --TAIL > 0
   140  
   141  dot_end:
   142  	MOVUPS SUM, sum+48(FP)
   143  	RET