gonum.org/v1/gonum@v0.14.0/internal/asm/f64/cumprod_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  TEXT ·CumProd(SB), NOSPLIT, $0
    10  	MOVQ    dst_base+0(FP), DI // DI = &dst
    11  	MOVQ    dst_len+8(FP), CX  // CX = len(dst)
    12  	MOVQ    s_base+24(FP), SI  // SI = &s
    13  	CMPQ    s_len+32(FP), CX   // CX = max( CX, len(s) )
    14  	CMOVQLE s_len+32(FP), CX
    15  	MOVQ    CX, ret_len+56(FP) // len(ret) = CX
    16  	CMPQ    CX, $0             // if CX == 0 { return }
    17  	JE      cp_end
    18  	XORQ    AX, AX             // i = 0
    19  
    20  	MOVSD  (SI), X5   // p_prod = { s[0], s[0] }
    21  	SHUFPD $0, X5, X5
    22  	MOVSD  X5, (DI)   // dst[0] = s[0]
    23  	INCQ   AX         // ++i
    24  	DECQ   CX         // -- CX
    25  	JZ     cp_end     // if CX == 0 { return }
    26  
    27  	MOVQ CX, BX
    28  	ANDQ $3, BX        // BX = CX % 4
    29  	SHRQ $2, CX        // CX = floor( CX / 4 )
    30  	JZ   cp_tail_start // if CX == 0 { goto cp_tail_start }
    31  
    32  cp_loop: // Loop unrolled 4x   do {
    33  	MOVUPS (SI)(AX*8), X0   // X0 = s[i:i+1]
    34  	MOVUPS 16(SI)(AX*8), X2
    35  	MOVAPS X0, X1           // X1 = X0
    36  	MOVAPS X2, X3
    37  	SHUFPD $1, X1, X1       // { X1[0], X1[1] } = { X1[1], X1[0] }
    38  	SHUFPD $1, X3, X3
    39  	MULPD  X0, X1           // X1 *= X0
    40  	MULPD  X2, X3
    41  	SHUFPD $2, X1, X0       // { X0[0], X0[1] } = { X0[0], X1[1] }
    42  	SHUFPD $3, X1, X1       // { X1[0], X1[1] } = { X1[1], X1[1] }
    43  	SHUFPD $2, X3, X2
    44  	SHUFPD $3, X3, X3
    45  	MULPD  X5, X0           // X0 *= p_prod
    46  	MULPD  X1, X5           // p_prod *= X1
    47  	MULPD  X5, X2
    48  	MOVUPS X0, (DI)(AX*8)   // dst[i] = X0
    49  	MOVUPS X2, 16(DI)(AX*8)
    50  	MULPD  X3, X5
    51  	ADDQ   $4, AX           // i += 4
    52  	LOOP   cp_loop          // } while --CX > 0
    53  
    54  	// if BX == 0 { return }
    55  	CMPQ BX, $0
    56  	JE   cp_end
    57  
    58  cp_tail_start: // Reset loop registers
    59  	MOVQ BX, CX // Loop counter: CX = BX
    60  
    61  cp_tail: // do {
    62  	MULSD (SI)(AX*8), X5 // p_prod *= s[i]
    63  	MOVSD X5, (DI)(AX*8) // dst[i] = p_prod
    64  	INCQ  AX             // ++i
    65  	LOOP  cp_tail        // } while --CX > 0
    66  
    67  cp_end:
    68  	MOVQ DI, ret_base+48(FP) // &ret = &dst
    69  	MOVQ dst_cap+16(FP), SI  // cap(ret) = cap(dst)
    70  	MOVQ SI, ret_cap+64(FP)
    71  	RET