time-to-botec

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

dcopy.c (1766B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 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/base/dcopy.h"
     20 
     21 /**
     22 * Copies values from `X` into `Y`.
     23 *
     24 * @param N        number of elements to copy
     25 * @param X        input array
     26 * @param strideX  X stride length
     27 * @param Y        destination array
     28 * @param strideY  Y stride length
     29 */
     30 void c_dcopy( const int N, const double *X, const int strideX, double *Y, const int strideY ) {
     31 	int ix;
     32 	int iy;
     33 	int i;
     34 	int m;
     35 
     36 	if ( N <= 0 ) {
     37 		return;
     38 	}
     39 	// If both strides are equal to `1`, use unrolled loops...
     40 	if ( strideX == 1 && strideY == 1 ) {
     41 		m = N % 7;
     42 
     43 		// If we have a remainder, do a clean-up loop...
     44 		if ( m > 0 ) {
     45 			for ( i = 0; i < m; i++ ) {
     46 				Y[ i ] = X[ i ];
     47 			}
     48 			if ( N < 7 ) {
     49 				return;
     50 			}
     51 		}
     52 		for ( i = m; i < N; i += 7 ) {
     53 			Y[ i ] = X[ i ];
     54 			Y[ i+1 ] = X[ i+1 ];
     55 			Y[ i+2 ] = X[ i+2 ];
     56 			Y[ i+3 ] = X[ i+3 ];
     57 			Y[ i+4 ] = X[ i+4 ];
     58 			Y[ i+5 ] = X[ i+5 ];
     59 			Y[ i+6 ] = X[ i+6 ];
     60 		}
     61 		return;
     62 	}
     63 	if ( strideX < 0 ) {
     64 		ix = (1-N) * strideX;
     65 	} else {
     66 		ix = 0;
     67 	}
     68 	if ( strideY < 0 ) {
     69 		iy = (1-N) * strideY;
     70 	} else {
     71 		iy = 0;
     72 	}
     73 	for ( i = 0; i < N; i++ ) {
     74 		Y[ iy ] = X[ ix ];
     75 		ix += strideX;
     76 		iy += strideY;
     77 	}
     78 	return;
     79 }