dapx.c (1631B)
1 /** 2 * @license Apache-2.0 3 * 4 * Copyright (c) 2020 The Stdlib Authors. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #include "stdlib/blas/ext/base/dapx.h" 20 #include <stdint.h> 21 22 /** 23 * Adds a constant to each element in a double-precision floating-point strided array. 24 * 25 * @param N number of indexed elements 26 * @param alpha scalar 27 * @param X input array 28 * @param stride index increment 29 */ 30 void c_dapx( const int64_t N, const double alpha, double *X, const int64_t stride ) { 31 int64_t ix; 32 int64_t m; 33 int64_t i; 34 35 if ( N <= 0 || alpha == 0.0 ) { 36 return; 37 } 38 // Use loop unrolling if the stride is equal to `1`... 39 if ( stride == 1 ) { 40 m = N % 5; 41 42 // If we have a remainder, run a clean-up loop... 43 if ( m > 0 ) { 44 for ( i = 0; i < m; i++ ) { 45 X[ i ] += alpha; 46 } 47 } 48 if ( N < 5 ) { 49 return; 50 } 51 for ( i = m; i < N; i += 5 ) { 52 X[ i ] += alpha; 53 X[ i+1 ] += alpha; 54 X[ i+2 ] += alpha; 55 X[ i+3 ] += alpha; 56 X[ i+4 ] += alpha; 57 } 58 return; 59 } 60 if ( stride < 0 ) { 61 ix = (1-N) * stride; 62 } else { 63 ix = 0; 64 } 65 for ( i = 0; i < N; i++ ) { 66 X[ ix ] += alpha; 67 ix += stride; 68 } 69 return; 70 }