github.com/gopherd/gonum@v0.0.4/internal/asm/c128/scalinc_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 SRC SI
    10  #define DST SI
    11  #define LEN CX
    12  #define TAIL BX
    13  #define INC R9
    14  #define INC3 R10
    15  #define ALPHA X0
    16  #define ALPHA_C X1
    17  #define ALPHA2 X10
    18  #define ALPHA_C2 X11
    19  
    20  #define MOVDDUP_X2_X3    LONG $0xDA120FF2 // MOVDDUP X2, X3
    21  #define MOVDDUP_X4_X5    LONG $0xEC120FF2 // MOVDDUP X4, X5
    22  #define MOVDDUP_X6_X7    LONG $0xFE120FF2 // MOVDDUP X6, X7
    23  #define MOVDDUP_X8_X9    LONG $0x120F45F2; BYTE $0xC8 // MOVDDUP X8, X9
    24  
    25  #define ADDSUBPD_X2_X3    LONG $0xDAD00F66 // ADDSUBPD X2, X3
    26  #define ADDSUBPD_X4_X5    LONG $0xECD00F66 // ADDSUBPD X4, X5
    27  #define ADDSUBPD_X6_X7    LONG $0xFED00F66 // ADDSUBPD X6, X7
    28  #define ADDSUBPD_X8_X9    LONG $0xD00F4566; BYTE $0xC8 // ADDSUBPD X8, X9
    29  
    30  // func ScalInc(alpha complex128, x []complex128, n, inc uintptr)
    31  TEXT ·ScalInc(SB), NOSPLIT, $0
    32  	MOVQ x_base+16(FP), SRC // SRC = &x
    33  	MOVQ n+40(FP), LEN      // LEN = len(x)
    34  	CMPQ LEN, $0
    35  	JE   scal_end           // if LEN == 0 { return }
    36  
    37  	MOVQ inc+48(FP), INC    // INC = inc
    38  	SHLQ $4, INC            // INC = INC * sizeof(complex128)
    39  	LEAQ (INC)(INC*2), INC3 // INC3 = 3 * INC
    40  
    41  	MOVUPS alpha+0(FP), ALPHA     // ALPHA = { imag(alpha), real(alpha) }
    42  	MOVAPS ALPHA, ALPHA_C
    43  	SHUFPD $0x1, ALPHA_C, ALPHA_C // ALPHA_C = { real(alpha), imag(alpha) }
    44  
    45  	MOVAPS ALPHA, ALPHA2     // Copy ALPHA and ALPHA_C for pipelining
    46  	MOVAPS ALPHA_C, ALPHA_C2
    47  	MOVQ   LEN, TAIL
    48  	SHRQ   $2, LEN           // LEN = floor( n / 4 )
    49  	JZ     scal_tail         // if BX == 0 { goto scal_tail }
    50  
    51  scal_loop: // do {
    52  	MOVUPS (SRC), X2         // X_i = { imag(x[i]), real(x[i]) }
    53  	MOVUPS (SRC)(INC*1), X4
    54  	MOVUPS (SRC)(INC*2), X6
    55  	MOVUPS (SRC)(INC3*1), X8
    56  
    57  	// X_(i+1) = { real(x[i], real(x[i]) }
    58  	MOVDDUP_X2_X3
    59  	MOVDDUP_X4_X5
    60  	MOVDDUP_X6_X7
    61  	MOVDDUP_X8_X9
    62  
    63  	// X_i = { imag(x[i]), imag(x[i]) }
    64  	SHUFPD $0x3, X2, X2
    65  	SHUFPD $0x3, X4, X4
    66  	SHUFPD $0x3, X6, X6
    67  	SHUFPD $0x3, X8, X8
    68  
    69  	// X_i     = { real(ALPHA) * imag(x[i]), imag(ALPHA) * imag(x[i])  }
    70  	// X_(i+1) = { imag(ALPHA) * real(x[i]), real(ALPHA) * real(x[i])  }
    71  	MULPD ALPHA_C, X2
    72  	MULPD ALPHA, X3
    73  	MULPD ALPHA_C2, X4
    74  	MULPD ALPHA2, X5
    75  	MULPD ALPHA_C, X6
    76  	MULPD ALPHA, X7
    77  	MULPD ALPHA_C2, X8
    78  	MULPD ALPHA2, X9
    79  
    80  	// X_(i+1) = {
    81  	//	imag(result[i]):  imag(ALPHA)*real(x[i]) + real(ALPHA)*imag(x[i]),
    82  	//	real(result[i]):  real(ALPHA)*real(x[i]) - imag(ALPHA)*imag(x[i])
    83  	//  }
    84  	ADDSUBPD_X2_X3
    85  	ADDSUBPD_X4_X5
    86  	ADDSUBPD_X6_X7
    87  	ADDSUBPD_X8_X9
    88  
    89  	MOVUPS X3, (DST)         // x[i] = X_(i+1)
    90  	MOVUPS X5, (DST)(INC*1)
    91  	MOVUPS X7, (DST)(INC*2)
    92  	MOVUPS X9, (DST)(INC3*1)
    93  
    94  	LEAQ (SRC)(INC*4), SRC // SRC = &(SRC[inc*4])
    95  	DECQ LEN
    96  	JNZ  scal_loop         // } while --BX > 0
    97  
    98  scal_tail:
    99  	ANDQ $3, TAIL // TAIL = TAIL % 4
   100  	JE   scal_end // if TAIL == 0 { return }
   101  
   102  scal_tail_loop: // do {
   103  	MOVUPS (SRC), X2    // X_i = { imag(x[i]), real(x[i]) }
   104  	MOVDDUP_X2_X3       // X_(i+1) = { real(x[i], real(x[i]) }
   105  	SHUFPD $0x3, X2, X2 // X_i = { imag(x[i]), imag(x[i]) }
   106  	MULPD  ALPHA_C, X2  // X_i     = { real(ALPHA) * imag(x[i]), imag(ALPHA) * imag(x[i])  }
   107  	MULPD  ALPHA, X3    // X_(i+1) = { imag(ALPHA) * real(x[i]), real(ALPHA) * real(x[i])  }
   108  
   109  	// X_(i+1) = {
   110  	//	imag(result[i]):  imag(ALPHA)*real(x[i]) + real(ALPHA)*imag(x[i]),
   111  	//	real(result[i]):  real(ALPHA)*real(x[i]) - imag(ALPHA)*imag(x[i])
   112  	//  }
   113  	ADDSUBPD_X2_X3
   114  
   115  	MOVUPS X3, (DST)      // x[i] = X_i
   116  	ADDQ   INC, SRC       // SRC = &(SRC[incX])
   117  	DECQ   TAIL
   118  	JNZ    scal_tail_loop // } while --TAIL > 0
   119  
   120  scal_end:
   121  	RET