time-to-botec

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

cswap.c (1694B)


      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/base/cswap.h"
     20 
     21 /**
     22 * Interchanges two complex single-precision floating-point vectors.
     23 *
     24 * @param N        number of elements to swap
     25 * @param X        first input array
     26 * @param strideX  X stride length
     27 * @param Y        second input array
     28 * @param strideY  Y stride length
     29 */
     30 void c_cswap( const int N, void *X, const int strideX, void *Y, const int strideY ) {
     31 	float *x = (float *)X;
     32 	float *y = (float *)Y;
     33 	float tmp;
     34 	int ix;
     35 	int iy;
     36 	int i;
     37 	int j;
     38 
     39 	if ( N <= 0 ) {
     40 		return;
     41 	}
     42 	if ( strideX == 1 && strideY == 1 ) {
     43 		for ( i = 0; i < N*2; i += 2 ) {
     44 			tmp = x[ i ];
     45 			x[ i ] = y[ i ];
     46 			y[ i ] = tmp;
     47 
     48 			j = i + 1;
     49 			tmp = x[ j ];
     50 			x[ j ] = y[ j ];
     51 			y[ j ] = tmp;
     52 		}
     53 		return;
     54 	}
     55 	if ( strideX < 0 ) {
     56 		ix = 2 * (1-N) * strideX;
     57 	} else {
     58 		ix = 0;
     59 	}
     60 	if ( strideY < 0 ) {
     61 		iy = 2 * (1-N) * strideY;
     62 	} else {
     63 		iy = 0;
     64 	}
     65 	for ( i = 0; i < N; i++ ) {
     66 		tmp = x[ ix ];
     67 		x[ ix ] = y[ iy ];
     68 		y[ iy ] = tmp;
     69 
     70 		tmp = x[ ix+1 ];
     71 		x[ ix+1 ] = y[ iy+1 ];
     72 		y[ iy+1 ] = tmp;
     73 
     74 		ix += strideX * 2;
     75 		iy += strideY * 2;
     76 	}
     77 	return;
     78 }