github.com/gopherd/gonum@v0.0.4/internal/asm/f64/divto_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 DivTo(dst, x, y []float64) 10 TEXT ·DivTo(SB), NOSPLIT, $0 11 MOVQ dst_base+0(FP), DI // DI = &dst 12 MOVQ dst_len+8(FP), CX // CX = len(dst) 13 MOVQ x_base+24(FP), SI // SI = &x 14 MOVQ y_base+48(FP), DX // DX = &y 15 CMPQ x_len+32(FP), CX // CX = max( len(dst), len(x), len(y) ) 16 CMOVQLE x_len+32(FP), CX 17 CMPQ y_len+56(FP), CX 18 CMOVQLE y_len+56(FP), CX 19 MOVQ CX, ret_len+80(FP) // len(ret) = CX 20 CMPQ CX, $0 // if CX == 0 { return } 21 JE div_end 22 XORQ AX, AX // i = 0 23 MOVQ DX, BX 24 ANDQ $15, BX // BX = &y & OxF 25 JZ div_no_trim // if BX == 0 { goto div_no_trim } 26 27 // Align on 16-bit boundary 28 MOVSD (SI)(AX*8), X0 // X0 = s[i] 29 DIVSD (DX)(AX*8), X0 // X0 /= t[i] 30 MOVSD X0, (DI)(AX*8) // dst[i] = X0 31 INCQ AX // ++i 32 DECQ CX // --CX 33 JZ div_end // if CX == 0 { return } 34 35 div_no_trim: 36 MOVQ CX, BX 37 ANDQ $7, BX // BX = len(dst) % 8 38 SHRQ $3, CX // CX = floor( len(dst) / 8 ) 39 JZ div_tail_start // if CX == 0 { goto div_tail_start } 40 41 div_loop: // Loop unrolled 8x do { 42 MOVUPS (SI)(AX*8), X0 // X0 = x[i:i+1] 43 MOVUPS 16(SI)(AX*8), X1 44 MOVUPS 32(SI)(AX*8), X2 45 MOVUPS 48(SI)(AX*8), X3 46 DIVPD (DX)(AX*8), X0 // X0 /= y[i:i+1] 47 DIVPD 16(DX)(AX*8), X1 48 DIVPD 32(DX)(AX*8), X2 49 DIVPD 48(DX)(AX*8), X3 50 MOVUPS X0, (DI)(AX*8) // dst[i:i+1] = X0 51 MOVUPS X1, 16(DI)(AX*8) 52 MOVUPS X2, 32(DI)(AX*8) 53 MOVUPS X3, 48(DI)(AX*8) 54 ADDQ $8, AX // i += 8 55 LOOP div_loop // } while --CX > 0 56 CMPQ BX, $0 // if BX == 0 { return } 57 JE div_end 58 59 div_tail_start: // Reset loop registers 60 MOVQ BX, CX // Loop counter: CX = BX 61 62 div_tail: // do { 63 MOVSD (SI)(AX*8), X0 // X0 = x[i] 64 DIVSD (DX)(AX*8), X0 // X0 /= y[i] 65 MOVSD X0, (DI)(AX*8) 66 INCQ AX // ++i 67 LOOP div_tail // } while --CX > 0 68 69 div_end: 70 MOVQ DI, ret_base+72(FP) // &ret = &dst 71 MOVQ dst_cap+16(FP), DI // cap(ret) = cap(dst) 72 MOVQ DI, ret_cap+88(FP) 73 RET