github.com/gopherd/gonum@v0.0.4/internal/asm/f64/cumsum_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 ·CumSum(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      cs_end
    18  	XORQ    AX, AX             // i = 0
    19  	PXOR    X5, X5             // p_sum = 0
    20  	MOVQ    CX, BX
    21  	ANDQ    $3, BX             // BX = CX % 4
    22  	SHRQ    $2, CX             // CX = floor( CX / 4 )
    23  	JZ      cs_tail_start      // if CX == 0 { goto cs_tail_start }
    24  
    25  cs_loop: // Loop unrolled 4x   do {
    26  	MOVUPS (SI)(AX*8), X0   // X0 = s[i:i+1]
    27  	MOVUPS 16(SI)(AX*8), X2
    28  	MOVAPS X0, X1           // X1 = X0
    29  	MOVAPS X2, X3
    30  	SHUFPD $1, X1, X1       // { X1[0], X1[1] } = { X1[1], X1[0] }
    31  	SHUFPD $1, X3, X3
    32  	ADDPD  X0, X1           // X1 += X0
    33  	ADDPD  X2, X3
    34  	SHUFPD $2, X1, X0       // { X0[0], X0[1] } = { X0[0], X1[1] }
    35  	SHUFPD $3, X1, X1       // { X1[0], X1[1] } = { X1[1], X1[1] }
    36  	SHUFPD $2, X3, X2
    37  	SHUFPD $3, X3, X3
    38  	ADDPD  X5, X0           // X0 += p_sum
    39  	ADDPD  X1, X5           // p_sum += X1
    40  	ADDPD  X5, X2
    41  	MOVUPS X0, (DI)(AX*8)   // dst[i] = X0
    42  	MOVUPS X2, 16(DI)(AX*8)
    43  	ADDPD  X3, X5
    44  	ADDQ   $4, AX           // i += 4
    45  	LOOP   cs_loop          // } while --CX > 0
    46  
    47  	// if BX == 0 { return }
    48  	CMPQ BX, $0
    49  	JE   cs_end
    50  
    51  cs_tail_start: // Reset loop registers
    52  	MOVQ BX, CX // Loop counter: CX = BX
    53  
    54  cs_tail: // do {
    55  	ADDSD (SI)(AX*8), X5 // p_sum *= s[i]
    56  	MOVSD X5, (DI)(AX*8) // dst[i] = p_sum
    57  	INCQ  AX             // ++i
    58  	LOOP  cs_tail        // } while --CX > 0
    59  
    60  cs_end:
    61  	MOVQ DI, ret_base+48(FP) // &ret = &dst
    62  	MOVQ dst_cap+16(FP), SI  // cap(ret) = cap(dst)
    63  	MOVQ SI, ret_cap+64(FP)
    64  	RET