gonum.org/v1/gonum@v0.14.0/internal/asm/f64/scalincto_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 // Some of the loop unrolling code is copied from: 6 // http://golang.org/src/math/big/arith_amd64.s 7 // which is distributed under these terms: 8 // 9 // Copyright (c) 2012 The Go Authors. All rights reserved. 10 // 11 // Redistribution and use in source and binary forms, with or without 12 // modification, are permitted provided that the following conditions are 13 // met: 14 // 15 // * Redistributions of source code must retain the above copyright 16 // notice, this list of conditions and the following disclaimer. 17 // * Redistributions in binary form must reproduce the above 18 // copyright notice, this list of conditions and the following disclaimer 19 // in the documentation and/or other materials provided with the 20 // distribution. 21 // * Neither the name of Google Inc. nor the names of its 22 // contributors may be used to endorse or promote products derived from 23 // this software without specific prior written permission. 24 // 25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 37 // +build !noasm,!gccgo,!safe 38 39 #include "textflag.h" 40 41 #define X_PTR SI 42 #define DST_PTR DI 43 #define LEN CX 44 #define TAIL BX 45 #define INC_X R8 46 #define INCx3_X R9 47 #define INC_DST R10 48 #define INCx3_DST R11 49 #define ALPHA X0 50 #define ALPHA_2 X1 51 52 // func ScalIncTo(dst []float64, incDst uintptr, alpha float64, x []float64, n, incX uintptr) 53 TEXT ·ScalIncTo(SB), NOSPLIT, $0 54 MOVQ dst_base+0(FP), DST_PTR // DST_PTR = &dst 55 MOVQ incDst+24(FP), INC_DST // INC_DST = incDst 56 SHLQ $3, INC_DST // INC_DST *= sizeof(float64) 57 MOVSD alpha+32(FP), ALPHA // ALPHA = alpha 58 MOVQ x_base+40(FP), X_PTR // X_PTR = &x 59 MOVQ n+64(FP), LEN // LEN = n 60 MOVQ incX+72(FP), INC_X // INC_X = incX 61 SHLQ $3, INC_X // INC_X *= sizeof(float64) 62 CMPQ LEN, $0 63 JE end // if LEN == 0 { return } 64 65 MOVQ LEN, TAIL 66 ANDQ $3, TAIL // TAIL = LEN % 4 67 SHRQ $2, LEN // LEN = floor( LEN / 4 ) 68 JZ tail_start // if LEN == 0 { goto tail_start } 69 70 MOVUPS ALPHA, ALPHA_2 // ALPHA_2 = ALPHA for pipelining 71 LEAQ (INC_X)(INC_X*2), INCx3_X // INCx3_X = INC_X * 3 72 LEAQ (INC_DST)(INC_DST*2), INCx3_DST // INCx3_DST = INC_DST * 3 73 74 loop: // do { // x[i] *= alpha unrolled 4x. 75 MOVSD (X_PTR), X2 // X_i = x[i] 76 MOVSD (X_PTR)(INC_X*1), X3 77 MOVSD (X_PTR)(INC_X*2), X4 78 MOVSD (X_PTR)(INCx3_X*1), X5 79 80 MULSD ALPHA, X2 // X_i *= a 81 MULSD ALPHA_2, X3 82 MULSD ALPHA, X4 83 MULSD ALPHA_2, X5 84 85 MOVSD X2, (DST_PTR) // dst[i] = X_i 86 MOVSD X3, (DST_PTR)(INC_DST*1) 87 MOVSD X4, (DST_PTR)(INC_DST*2) 88 MOVSD X5, (DST_PTR)(INCx3_DST*1) 89 90 LEAQ (X_PTR)(INC_X*4), X_PTR // X_PTR = &(X_PTR[incX*4]) 91 LEAQ (DST_PTR)(INC_DST*4), DST_PTR // DST_PTR = &(DST_PTR[incDst*4]) 92 DECQ LEN 93 JNZ loop // } while --LEN > 0 94 CMPQ TAIL, $0 95 JE end // if TAIL == 0 { return } 96 97 tail_start: // Reset loop registers 98 MOVQ TAIL, LEN // Loop counter: LEN = TAIL 99 SHRQ $1, LEN // LEN = floor( LEN / 2 ) 100 JZ tail_one 101 102 tail_two: 103 MOVSD (X_PTR), X2 // X_i = x[i] 104 MOVSD (X_PTR)(INC_X*1), X3 105 MULSD ALPHA, X2 // X_i *= a 106 MULSD ALPHA, X3 107 MOVSD X2, (DST_PTR) // dst[i] = X_i 108 MOVSD X3, (DST_PTR)(INC_DST*1) 109 110 LEAQ (X_PTR)(INC_X*2), X_PTR // X_PTR = &(X_PTR[incX*2]) 111 LEAQ (DST_PTR)(INC_DST*2), DST_PTR // DST_PTR = &(DST_PTR[incDst*2]) 112 113 ANDQ $1, TAIL 114 JZ end 115 116 tail_one: 117 MOVSD (X_PTR), X2 // X_i = x[i] 118 MULSD ALPHA, X2 // X_i *= ALPHA 119 MOVSD X2, (DST_PTR) // x[i] = X_i 120 121 end: 122 RET