time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

sfill.c (1675B)


      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/sfill.h"
     20 #include <stdint.h>
     21 
     22 /**
     23 * Fills a single-precision floating-point strided array with a specified scalar constant.
     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_sfill( const int64_t N, const float alpha, float *X, const int64_t stride ) {
     31 	int64_t ix;
     32 	int64_t m;
     33 	int64_t i;
     34 
     35 	if ( N <= 0 ) {
     36 		return;
     37 	}
     38 	// Use loop unrolling if the stride is equal to `1`...
     39 	if ( stride == 1 ) {
     40 		m = N % 8;
     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 < 8 ) {
     49 			return;
     50 		}
     51 		for ( i = m; i < N; i += 8 ) {
     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 			X[ i+5 ] = alpha;
     58 			X[ i+6 ] = alpha;
     59 			X[ i+7 ] = alpha;
     60 		}
     61 		return;
     62 	}
     63 	if ( stride < 0 ) {
     64 		ix = (1-N) * stride;
     65 	} else {
     66 		ix = 0;
     67 	}
     68 	for ( i = 0; i < N; i++ ) {
     69 		X[ ix ] = alpha;
     70 		ix += stride;
     71 	}
     72 	return;
     73 }