gonum.org/v1/gonum@v0.14.0/internal/asm/c128/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 MOVDDUP_XPTR__X3 LONG $0x1E120FF2 // MOVDDUP (SI), X3 10 #define MOVDDUP_XPTR_INCX__X5 LONG $0x120F42F2; WORD $0x062C // MOVDDUP (SI)(R8*1), X5 11 #define MOVDDUP_XPTR_INCX_2__X7 LONG $0x120F42F2; WORD $0x463C // MOVDDUP (SI)(R8*2), X7 12 #define MOVDDUP_XPTR_INCx3X__X9 LONG $0x120F46F2; WORD $0x0E0C // MOVDDUP (SI)(R9*1), X9 13 14 #define MOVDDUP_8_XPTR__X2 LONG $0x56120FF2; BYTE $0x08 // MOVDDUP 8(SI), X2 15 #define MOVDDUP_8_XPTR_INCX__X4 LONG $0x120F42F2; WORD $0x0664; BYTE $0x08 // MOVDDUP 8(SI)(R8*1), X4 16 #define MOVDDUP_8_XPTR_INCX_2__X6 LONG $0x120F42F2; WORD $0x4674; BYTE $0x08 // MOVDDUP 8(SI)(R8*2), X6 17 #define MOVDDUP_8_XPTR_INCx3X__X8 LONG $0x120F46F2; WORD $0x0E44; BYTE $0x08 // MOVDDUP 8(SI)(R9*1), 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 INC_X R8 31 #define INCx3_X R9 32 #define INC_Y R10 33 #define INCx3_Y R11 34 35 // func DotuInc(x, y []complex128, n, incX, incY, ix, iy uintptr) (sum complex128) 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 MOVQ n+48(FP), LEN // LEN = n 40 PXOR SUM, SUM // sum = 0 41 CMPQ LEN, $0 // if LEN == 0 { return } 42 JE dot_end 43 MOVQ ix+72(FP), INC_X // INC_X = ix * sizeof(complex128) 44 SHLQ $4, INC_X 45 MOVQ iy+80(FP), INC_Y // INC_Y = iy * sizeof(complex128) 46 SHLQ $4, INC_Y 47 LEAQ (X_PTR)(INC_X*1), X_PTR // X_PTR = &(X_PTR[ix]) 48 LEAQ (Y_PTR)(INC_Y*1), Y_PTR // Y_PTR = &(Y_PTR[iy]) 49 MOVQ incX+56(FP), INC_X // INC_X = incX 50 SHLQ $4, INC_X // INC_X *= sizeof(complex128) 51 MOVQ incY+64(FP), INC_Y // INC_Y = incY 52 SHLQ $4, INC_Y // INC_Y *= sizeof(complex128) 53 MOVQ LEN, TAIL 54 ANDQ $3, TAIL // LEN = LEN % 4 55 SHRQ $2, LEN // LEN = floor( LEN / 4 ) 56 JZ dot_tail // if LEN <= 4 { goto dot_tail } 57 PXOR P_SUM, P_SUM // psum = 0 58 LEAQ (INC_X)(INC_X*2), INCx3_X // INCx3_X = 3 * incX * sizeof(complex128) 59 LEAQ (INC_Y)(INC_Y*2), INCx3_Y // INCx3_Y = 3 * incY * sizeof(complex128) 60 61 dot_loop: // do { 62 MOVDDUP_XPTR__X3 // X_(i+1) = { real(x[i], real(x[i]) } 63 MOVDDUP_XPTR_INCX__X5 64 MOVDDUP_XPTR_INCX_2__X7 65 MOVDDUP_XPTR_INCx3X__X9 66 67 MOVDDUP_8_XPTR__X2 // X_i = { imag(x[i]), imag(x[i]) } 68 MOVDDUP_8_XPTR_INCX__X4 69 MOVDDUP_8_XPTR_INCX_2__X6 70 MOVDDUP_8_XPTR_INCx3X__X8 71 72 // X_j = { imag(y[i]), real(y[i]) } 73 MOVUPS (Y_PTR), X10 74 MOVUPS (Y_PTR)(INC_Y*1), X11 75 MOVUPS (Y_PTR)(INC_Y*2), X12 76 MOVUPS (Y_PTR)(INCx3_Y*1), X13 77 78 // X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i]) } 79 MULPD X10, X3 80 MULPD X11, X5 81 MULPD X12, X7 82 MULPD X13, X9 83 84 // X_j = { real(y[i]), imag(y[i]) } 85 SHUFPD $0x1, X10, X10 86 SHUFPD $0x1, X11, X11 87 SHUFPD $0x1, X12, X12 88 SHUFPD $0x1, X13, X13 89 90 // X_i = { real(a) * imag(x[i]), imag(a) * imag(x[i]) } 91 MULPD X10, X2 92 MULPD X11, X4 93 MULPD X12, X6 94 MULPD X13, X8 95 96 // X_(i+1) = { 97 // imag(result[i]): imag(a)*real(x[i]) + real(a)*imag(x[i]), 98 // real(result[i]): real(a)*real(x[i]) - imag(a)*imag(x[i]) 99 // } 100 ADDSUBPD_X2_X3 101 ADDSUBPD_X4_X5 102 ADDSUBPD_X6_X7 103 ADDSUBPD_X8_X9 104 105 // psum += result[i] 106 ADDPD X3, SUM 107 ADDPD X5, P_SUM 108 ADDPD X7, SUM 109 ADDPD X9, P_SUM 110 111 LEAQ (X_PTR)(INC_X*4), X_PTR // X_PTR = &(X_PTR[incX*4]) 112 LEAQ (Y_PTR)(INC_Y*4), Y_PTR // Y_PTR = &(Y_PTR[incY*4]) 113 114 DECQ LEN 115 JNZ dot_loop // } while --BX > 0 116 ADDPD P_SUM, SUM // sum += psum 117 CMPQ TAIL, $0 // if TAIL == 0 { return } 118 JE dot_end 119 120 dot_tail: // do { 121 MOVDDUP_XPTR__X3 // X_(i+1) = { real(x[i], real(x[i]) } 122 MOVDDUP_8_XPTR__X2 // X_i = { imag(x[i]), imag(x[i]) } 123 MOVUPS (Y_PTR), X10 // X_j = { imag(y[i]) , real(y[i]) } 124 MULPD X10, X3 // X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i]) } 125 SHUFPD $0x1, X10, X10 // X_j = { real(y[i]) , imag(y[i]) } 126 MULPD X10, X2 // X_i = { real(a) * imag(x[i]), imag(a) * imag(x[i]) } 127 128 // X_(i+1) = { 129 // imag(result[i]): imag(a)*real(x[i]) + real(a)*imag(x[i]), 130 // real(result[i]): real(a)*real(x[i]) - imag(a)*imag(x[i]) 131 // } 132 ADDSUBPD_X2_X3 133 ADDPD X3, SUM // sum += result[i] 134 ADDQ INC_X, X_PTR // X_PTR += incX 135 ADDQ INC_Y, Y_PTR // Y_PTR += incY 136 DECQ TAIL // --TAIL 137 JNZ dot_tail // } while TAIL > 0 138 139 dot_end: 140 MOVUPS SUM, sum+88(FP) 141 RET