gonum.org/v1/gonum@v0.14.0/internal/asm/c128/dotuunitary_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 33 // func DotuUnitary(x, y []complex128) (sum complex128) 34 TEXT ·DotuUnitary(SB), NOSPLIT, $0 35 MOVQ x_base+0(FP), X_PTR // X_PTR = &x 36 MOVQ y_base+24(FP), Y_PTR // Y_PTR = &y 37 MOVQ x_len+8(FP), LEN // LEN = min( len(x), len(y) ) 38 CMPQ y_len+32(FP), LEN 39 CMOVQLE y_len+32(FP), LEN 40 PXOR SUM, SUM // SUM = 0 41 CMPQ LEN, $0 // if LEN == 0 { return } 42 JE dot_end 43 PXOR P_SUM, P_SUM // P_SUM = 0 44 XORQ IDX, IDX // IDX = 0 45 MOVQ $1, DX // j = 1 46 MOVQ LEN, TAIL 47 ANDQ $3, TAIL // TAIL = floor( LEN / 4 ) 48 SHRQ $2, LEN // LEN = LEN % 4 49 JZ dot_tail // if LEN == 0 { goto dot_tail } 50 51 dot_loop: // do { 52 MOVDDUP_XPTR_IDX_8__X3 // X_(i+1) = { real(x[i], real(x[i]) } 53 MOVDDUP_16_XPTR_IDX_8__X5 54 MOVDDUP_32_XPTR_IDX_8__X7 55 MOVDDUP_48_XPTR_IDX_8__X9 56 57 MOVDDUP_XPTR_IIDX_8__X2 // X_i = { imag(x[i]), imag(x[i]) } 58 MOVDDUP_16_XPTR_IIDX_8__X4 59 MOVDDUP_32_XPTR_IIDX_8__X6 60 MOVDDUP_48_XPTR_IIDX_8__X8 61 62 // X_j = { imag(y[i]), real(y[i]) } 63 MOVUPS (Y_PTR)(IDX*8), X10 64 MOVUPS 16(Y_PTR)(IDX*8), X11 65 MOVUPS 32(Y_PTR)(IDX*8), X12 66 MOVUPS 48(Y_PTR)(IDX*8), X13 67 68 // X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i]) } 69 MULPD X10, X3 70 MULPD X11, X5 71 MULPD X12, X7 72 MULPD X13, X9 73 74 // X_j = { real(y[i]), imag(y[i]) } 75 SHUFPD $0x1, X10, X10 76 SHUFPD $0x1, X11, X11 77 SHUFPD $0x1, X12, X12 78 SHUFPD $0x1, X13, X13 79 80 // X_i = { real(a) * imag(x[i]), imag(a) * imag(x[i]) } 81 MULPD X10, X2 82 MULPD X11, X4 83 MULPD X12, X6 84 MULPD X13, X8 85 86 // X_(i+1) = { 87 // imag(result[i]): imag(a)*real(x[i]) + real(a)*imag(x[i]), 88 // real(result[i]): real(a)*real(x[i]) - imag(a)*imag(x[i]) 89 // } 90 ADDSUBPD_X2_X3 91 ADDSUBPD_X4_X5 92 ADDSUBPD_X6_X7 93 ADDSUBPD_X8_X9 94 95 // psum += result[i] 96 ADDPD X3, SUM 97 ADDPD X5, P_SUM 98 ADDPD X7, SUM 99 ADDPD X9, P_SUM 100 101 ADDQ $8, IDX // IDX += 8 102 ADDQ $8, I_IDX // I_IDX += 8 103 DECQ LEN 104 JNZ dot_loop // } while --LEN > 0 105 ADDPD P_SUM, SUM // SUM += P_SUM 106 CMPQ TAIL, $0 // if TAIL == 0 { return } 107 JE dot_end 108 109 dot_tail: // do { 110 MOVDDUP_XPTR_IDX_8__X3 // X_(i+1) = { real(x[i] , real(x[i]) } 111 MOVDDUP_XPTR_IIDX_8__X2 // X_i = { imag(x[i]) , imag(x[i]) } 112 MOVUPS (Y_PTR)(IDX*8), X10 // X_j = { imag(y[i]) , real(y[i]) } 113 MULPD X10, X3 // X_(i+1) = { imag(a) * real(x[i]), real(a) * real(x[i]) } 114 SHUFPD $0x1, X10, X10 // X_j = { real(y[i]) , imag(y[i]) } 115 MULPD X10, X2 // X_i = { real(a) * imag(x[i]), imag(a) * imag(x[i]) } 116 117 // X_(i+1) = { 118 // imag(result[i]): imag(a)*real(x[i]) + real(a)*imag(x[i]), 119 // real(result[i]): real(a)*real(x[i]) - imag(a)*imag(x[i]) 120 // } 121 ADDSUBPD_X2_X3 122 ADDPD X3, SUM // psum += result[i] 123 ADDQ $2, IDX // IDX += 2 124 ADDQ $2, I_IDX // I_IDX += 2 125 DECQ TAIL // --TAIL 126 JNZ dot_tail // } while TAIL > 0 127 128 dot_end: 129 MOVUPS SUM, sum+48(FP) 130 RET