gonum.org/v1/gonum@v0.14.0/internal/asm/f64/add_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 // func Add(dst, s []float64) 10 TEXT ·Add(SB), NOSPLIT, $0 11 MOVQ dst_base+0(FP), DI // DI = &dst 12 MOVQ dst_len+8(FP), CX // CX = len(dst) 13 MOVQ s_base+24(FP), SI // SI = &s 14 CMPQ s_len+32(FP), CX // CX = max( CX, len(s) ) 15 CMOVQLE s_len+32(FP), CX 16 CMPQ CX, $0 // if CX == 0 { return } 17 JE add_end 18 XORQ AX, AX 19 MOVQ DI, BX 20 ANDQ $0x0F, BX // BX = &dst & 15 21 JZ add_no_trim // if BX == 0 { goto add_no_trim } 22 23 // Align on 16-bit boundary 24 MOVSD (SI)(AX*8), X0 // X0 = s[i] 25 ADDSD (DI)(AX*8), X0 // X0 += dst[i] 26 MOVSD X0, (DI)(AX*8) // dst[i] = X0 27 INCQ AX // i++ 28 DECQ CX // --CX 29 JE add_end // if CX == 0 { return } 30 31 add_no_trim: 32 MOVQ CX, BX 33 ANDQ $7, BX // BX = len(dst) % 8 34 SHRQ $3, CX // CX = floor( len(dst) / 8 ) 35 JZ add_tail_start // if CX == 0 { goto add_tail_start } 36 37 add_loop: // Loop unrolled 8x do { 38 MOVUPS (SI)(AX*8), X0 // X_i = s[i:i+1] 39 MOVUPS 16(SI)(AX*8), X1 40 MOVUPS 32(SI)(AX*8), X2 41 MOVUPS 48(SI)(AX*8), X3 42 ADDPD (DI)(AX*8), X0 // X_i += dst[i:i+1] 43 ADDPD 16(DI)(AX*8), X1 44 ADDPD 32(DI)(AX*8), X2 45 ADDPD 48(DI)(AX*8), X3 46 MOVUPS X0, (DI)(AX*8) // dst[i:i+1] = X_i 47 MOVUPS X1, 16(DI)(AX*8) 48 MOVUPS X2, 32(DI)(AX*8) 49 MOVUPS X3, 48(DI)(AX*8) 50 ADDQ $8, AX // i += 8 51 LOOP add_loop // } while --CX > 0 52 CMPQ BX, $0 // if BX == 0 { return } 53 JE add_end 54 55 add_tail_start: // Reset loop registers 56 MOVQ BX, CX // Loop counter: CX = BX 57 58 add_tail: // do { 59 MOVSD (SI)(AX*8), X0 // X0 = s[i] 60 ADDSD (DI)(AX*8), X0 // X0 += dst[i] 61 MOVSD X0, (DI)(AX*8) // dst[i] = X0 62 INCQ AX // ++i 63 LOOP add_tail // } while --CX > 0 64 65 add_end: 66 RET