gonum.org/v1/gonum@v0.14.0/internal/asm/f64/div_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 Div(dst, s []float64)
    10  TEXT ·Div(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      div_end
    18  	XORQ    AX, AX             // i = 0
    19  	MOVQ    SI, BX
    20  	ANDQ    $15, BX            // BX = &s & 15
    21  	JZ      div_no_trim        // if BX == 0 { goto div_no_trim }
    22  
    23  	// Align on 16-bit boundary
    24  	MOVSD (DI)(AX*8), X0 // X0 = dst[i]
    25  	DIVSD (SI)(AX*8), X0 // X0 /= s[i]
    26  	MOVSD X0, (DI)(AX*8) // dst[i] = X0
    27  	INCQ  AX             // ++i
    28  	DECQ  CX             // --CX
    29  	JZ    div_end        // if CX == 0 { return }
    30  
    31  div_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   div_tail_start // if CX == 0 { goto div_tail_start }
    36  
    37  div_loop: // Loop unrolled 8x   do {
    38  	MOVUPS (DI)(AX*8), X0   // X0 = dst[i:i+1]
    39  	MOVUPS 16(DI)(AX*8), X1
    40  	MOVUPS 32(DI)(AX*8), X2
    41  	MOVUPS 48(DI)(AX*8), X3
    42  	DIVPD  (SI)(AX*8), X0   // X0 /= s[i:i+1]
    43  	DIVPD  16(SI)(AX*8), X1
    44  	DIVPD  32(SI)(AX*8), X2
    45  	DIVPD  48(SI)(AX*8), X3
    46  	MOVUPS X0, (DI)(AX*8)   // dst[i] = X0
    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   div_loop         // } while --CX > 0
    52  	CMPQ   BX, $0           // if BX == 0 { return }
    53  	JE     div_end
    54  
    55  div_tail_start: // Reset loop registers
    56  	MOVQ BX, CX // Loop counter: CX = BX
    57  
    58  div_tail: // do {
    59  	MOVSD (DI)(AX*8), X0 // X0 = dst[i]
    60  	DIVSD (SI)(AX*8), X0 // X0 /= s[i]
    61  	MOVSD X0, (DI)(AX*8) // dst[i] = X0
    62  	INCQ  AX             // ++i
    63  	LOOP  div_tail       // } while --CX > 0
    64  
    65  div_end:
    66  	RET
    67