gonum.org/v1/gonum@v0.14.0/internal/asm/f64/scalunitaryto_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 MOVDDUP_ALPHA LONG $0x44120FF2; WORD $0x2024 // @ MOVDDUP 32(SP), X0 /*XMM0, 32[RSP]*/ 42 43 #define X_PTR SI 44 #define DST_PTR DI 45 #define IDX AX 46 #define LEN CX 47 #define TAIL BX 48 #define ALPHA X0 49 #define ALPHA_2 X1 50 51 // func ScalUnitaryTo(dst []float64, alpha float64, x []float64) 52 // This function assumes len(dst) >= len(x). 53 TEXT ·ScalUnitaryTo(SB), NOSPLIT, $0 54 MOVQ x_base+32(FP), X_PTR // X_PTR = &x 55 MOVQ dst_base+0(FP), DST_PTR // DST_PTR = &dst 56 MOVDDUP_ALPHA // ALPHA = { alpha, alpha } 57 MOVQ x_len+40(FP), LEN // LEN = len(x) 58 CMPQ LEN, $0 59 JE end // if LEN == 0 { return } 60 61 XORQ IDX, IDX // IDX = 0 62 MOVQ LEN, TAIL 63 ANDQ $7, TAIL // TAIL = LEN % 8 64 SHRQ $3, LEN // LEN = floor( LEN / 8 ) 65 JZ tail_start // if LEN == 0 { goto tail_start } 66 67 MOVUPS ALPHA, ALPHA_2 // ALPHA_2 = ALPHA for pipelining 68 69 loop: // do { // dst[i] = alpha * x[i] unrolled 8x. 70 MOVUPS (X_PTR)(IDX*8), X2 // X_i = x[i] 71 MOVUPS 16(X_PTR)(IDX*8), X3 72 MOVUPS 32(X_PTR)(IDX*8), X4 73 MOVUPS 48(X_PTR)(IDX*8), X5 74 75 MULPD ALPHA, X2 // X_i *= ALPHA 76 MULPD ALPHA_2, X3 77 MULPD ALPHA, X4 78 MULPD ALPHA_2, X5 79 80 MOVUPS X2, (DST_PTR)(IDX*8) // dst[i] = X_i 81 MOVUPS X3, 16(DST_PTR)(IDX*8) 82 MOVUPS X4, 32(DST_PTR)(IDX*8) 83 MOVUPS X5, 48(DST_PTR)(IDX*8) 84 85 ADDQ $8, IDX // i += 8 86 DECQ LEN 87 JNZ loop // while --LEN > 0 88 CMPQ TAIL, $0 89 JE end // if TAIL == 0 { return } 90 91 tail_start: // Reset loop counters 92 MOVQ TAIL, LEN // Loop counter: LEN = TAIL 93 SHRQ $1, LEN // LEN = floor( TAIL / 2 ) 94 JZ tail_one // if LEN == 0 { goto tail_one } 95 96 tail_two: // do { 97 MOVUPS (X_PTR)(IDX*8), X2 // X_i = x[i] 98 MULPD ALPHA, X2 // X_i *= ALPHA 99 MOVUPS X2, (DST_PTR)(IDX*8) // dst[i] = X_i 100 ADDQ $2, IDX // i += 2 101 DECQ LEN 102 JNZ tail_two // while --LEN > 0 103 104 ANDQ $1, TAIL 105 JZ end // if TAIL == 0 { return } 106 107 tail_one: 108 MOVSD (X_PTR)(IDX*8), X2 // X_i = x[i] 109 MULSD ALPHA, X2 // X_i *= ALPHA 110 MOVSD X2, (DST_PTR)(IDX*8) // dst[i] = X_i 111 112 end: 113 RET