⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matscalmult.c

📁 开发环境为visual dsp++3.0的复数矩阵乘法模块
💻 C
字号:
/* MatScalMult.c - Performs a multiplication of a matrix and a   */
/* scalar.														 */
/*																 */
/* The operation is performed twice for the same data.           */
/* The first execution is for SISD mode and the second for SIMD  */
/* mode.                                                         */
/* Benchmark routines are included to record the cycle count for */
/* execution of each mode and are printed to the output window   */
/* upon completion.                                              */
/*                                                               */
/* Analog Devices, 1999 */

#include <stdio.h>

#define rows 30
#define columns 30

float dm input[rows][columns];			/* The matrices can be treated as single dimensional	*/
float pm output_SISD[rows][columns];	/* arrays due to the way they are stored in memory.		*/
float pm output_SIMD[rows][columns];	/* This will optimize the C code for the architecture.	*/

int count_start();
int count_end(int);
volatile int time_temp, SISD_cycle_count, SIMD_cycle_count; /* for benchmark routines */

void main(void)
{
   int i;
   float scalar = 5;
          
   for (i = 0; i < rows * columns; i++)
   	input[0][i] = (float) i;
          
   time_temp = count_start();				/* Benchmark routine start */
   for (i = 0; i < rows * columns; i++)
   	output_SISD[0][i] = input[0][i] * scalar;
   SISD_cycle_count = count_end(time_temp); /* Benchmark routine end   */

   printf("The cycle count for SISD execution is %d cycles.\n",SISD_cycle_count);

   time_temp = count_start();				/* Benchmark routine start */
    #pragma SIMD_for
	for (i = 0; i < rows * columns; i++)
   	output_SIMD[0][i] = input[0][i] * scalar;
   SIMD_cycle_count = count_end(time_temp);	/* Benchmark routine end   */

   printf("The cycle count for SIMD execution is %d cycles.\n",SIMD_cycle_count);

   exit(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -