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