//目的:测试程序——用于开发板——验证后移植到863板
//说明:数据经内建信号源产生通过FIR滤波运算,CORDIC算法正余弦运算生成结果
//北京理工大学雷达所
//程序编制:叶有时
//日期:2007年7月2日
#include <stdio.h>
#include <stdlib.h> /* rand(), RAND_MAX */
#include <math.h> /* exp, log */
#include <float.h> /* FLT_MAX */
#include <sys/alt_irq.h>
#include "system.h"
#include "floating_point.h"
#include "sys/alt_timestamp.h"
#include "alt_types.h"
#include "altera_avalon_performance_counter.h"
#define N 12
#define NUM_ITERATIONS 1000
int main(void)
{
alt_u32 time1;
alt_u32 time2;
alt_u32 time3;
// Start Timer:
if(alt_timestamp_start() < 0)
{
printf("Timer init failed \n");
}
//time1 = alt_timestamp();
//**************************
//定点加减乘除
//**************************
float random_a[NUM_ITERATIONS];
float random_b[NUM_ITERATIONS];
float result_CI;
float result_SW;
int i;
alt_irq_context context;
/* Generate random floating point numbers and place them in 2 arrays, one for
* each operand. The range is -FLT_MAX to FLT_MAX. The exp() and log() are
* is used to get a non-linear distribution (without them the numbers aren't
* distributed well).*/
for (i = 0; i < NUM_ITERATIONS; i++)
{
random_a[i] = (float) exp((rand()/(double)RAND_MAX) * log(FLT_MAX));
if (rand() > RAND_MAX / 2) random_a[i] = -random_a[i];
random_b[i] = (float) exp((rand()/(double)RAND_MAX) * log(FLT_MAX));
if (rand() > RAND_MAX / 2) random_b[i] = -random_b[i];
}
time1 = alt_timestamp();
/************************************************
* Floating Point calculations
************************************************/
/************************************************
* ADD
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
// context = alt_irq_disable_all();
//result_CI = fp_add_CI(random_a[i], random_b[i]);
result_SW = fp_add_SW(random_a[i], random_b[i]);
//alt_irq_enable_all(context);
}
printf("\n\n");
/************************************************
* SUBTRACT
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
//context = alt_irq_disable_all();
//result_CI = fp_sub_CI(random_a[i], random_b[i]);
result_SW = fp_sub_SW(random_a[i], random_b[i]);
// alt_irq_enable_all(context);
}
printf("\n\n");
/************************************************
* MULTIPLY
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
//context = alt_irq_disable_all();
//result_CI = fp_mul_CI(random_a[i], random_b[i]);
result_SW = fp_mul_SW(random_a[i], random_b[i]);
//alt_irq_enable_all(context);
}
printf("\n\n");
/************************************************
* DIVIDE
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
//context = alt_irq_disable_all();
//result_CI = fp_div_CI(random_a[i], random_b[i]);
result_SW = fp_div_SW(random_a[i], random_b[i]);
// alt_irq_enable_all(context);
}
printf("\n\n");
time2 = alt_timestamp();
//**************************
//浮点加减乘除
//**************************
/************************************************
* ADD
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
// context = alt_irq_disable_all();
result_CI = fp_add_CI(random_a[i], random_b[i]);
//result_SW = fp_add_SW(random_a[i], random_b[i]);
//alt_irq_enable_all(context);
}
printf("\n\n");
/************************************************
* SUBTRACT
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
// context = alt_irq_disable_all();
result_CI = fp_sub_CI(random_a[i], random_b[i]);
//result_SW = fp_sub_SW(random_a[i], random_b[i]);
//alt_irq_enable_all(context);
}
printf("\n\n");
/************************************************
* MULTIPLY
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
//context = alt_irq_disable_all();
result_CI = fp_mul_CI(random_a[i], random_b[i]);
//result_SW = fp_mul_SW(random_a[i], random_b[i]);
//alt_irq_enable_all(context);
}
printf("\n\n");
/************************************************
* DIVIDE
************************************************/
for (i = 0; i < NUM_ITERATIONS; i++)
{
//context = alt_irq_disable_all();
result_CI = fp_div_CI(random_a[i], random_b[i]);
//result_SW = fp_div_SW(random_a[i], random_b[i]);
// alt_irq_enable_all(context);
}
printf("\n\n");
time3 = alt_timestamp();
printf ("\contant Data Block = %u\n", (unsigned int)(time2-time1));
printf ("\float Data Block = %u\n", (unsigned int)(time3-time2));
printf ("\all Data Block = %u\n", (unsigned int)(time3-time1));
printf ("frequence of timer = %u\n", (unsigned int)alt_timestamp_freq());
}