Mibench移植到玄铁e906下,在smart_run平台下跑通-basicmath

发布于:2022-11-04 ⋅ 阅读:(599) ⋅ 点赞:(0)

1:Mibench MiBench Benchmark 总共包含35个嵌入式程序,分成汽车及工业制造、消费电子、办公自动化、网络、安全、通信六个子类。所有程序都使用 ANSI C 编写

       2;具体的修改在smart_run文件夹下又一个makefile文件这个文件大致是一个嵌套的makefile文件里面调用了下图两个头文件

在smart_cfg.mk里面他是用户CASE_LIST这个定义调用了要编译的文件夹

所以这里把basicmath给加进去,并且后面需要生成一个basicmath_build的文件,也要对照其他文件的生成方式给加进去

然后在lib这个文件夹里面也有一个makefile文件这里是文件编译的时候需要给出编译的参数。

这里的CFlAGS就是编译的时候需要使用的参数,这个可以看到coremark应该编译的时候加入的参

 

数很多,把coremark单独给进行了参数的赋值,这里模仿coremark给basicmath也单独的赋值。下载的Mibench里面basicmath包里面的makefile文件有编译的参数加进去就可以了。

3;在basicmath里面的makefile中编译参数-static解释他是指的是使用静态链接库。我们写代码时调用的那些系统中自带的库函数都不是.c或是.cpp这些明文的文件,而是一个个封装起来的库文件,通常分为两类:静态链接库和动态链接库。

首先,静态连接就是gcc会把用到的库文件给拷贝下来复制到程序文件的适当的位置生成可执行文件,所以生成的执行文件就体积大,但是当他执行的时候他就不在需要依赖那些库了。

其次,动态连接相反,他并没有复制用到的库文件功能文件到程序文件中,他只是记录了这些功能模块的位置信息然后直接生成可执行文件。所以可执行文件体积小,但是需要依赖库文件。

4;遇到的问题,这里在修改好makefile文件之后执行make build命令的时候会报错和ld链接器有关的一个错误,这里是因为basicmath文件里面有两个要生成的执行文件basicmath_large.c和basicmath_small.c这两个不能同时编译,需要一个一个的来。去掉一个在执行就可以了

5;之后在smart_run下打开终端,输入csh进入csh模式,输入make buildcase CASE=basicmath

就可以生成case.pat文件,然后执行make runcase CASE=basicmath SIM=vcs就可以进行仿真。

 

6:仿真成功,为了能够使跑出来的代码能够在我们的板子上串口有输出,对其进行了重映射。具体的代码修改如下,在basicmath_large.c里面重新定义fputc函数,这里参考这篇文章。https://blog.csdn.net/qq_40011737/article/details/125228289?spm=1001.2014.3001.5502icon-default.png?t=M85Bhttps://blog.csdn.net/qq_40011737/article/details/125228289?spm=1001.2014.3001.5502

#include "snipmath.h"
#include <math.h>
/* The printf's may be removed to isolate just the math calculations */
#include "datatype.h"
#include "stdio.h"
#include "uart.h"

t_ck_uart_device uart0 = {0xFFFF};
//sys 50Mhz
void delay_ms(int time){
	int i,j;
	for(i=0;i<time;i++){
		for(j=0;j<50000;j++){
			;
		}
	}
}

//重写fputc
int fputc(int ch, FILE *stream)
{ 
	ck_uart_putc(&uart0, (char)ch);
}

  
int main(void)
{
 //int a;
  //--------------------------------------------------------
  // setup uart
  //--------------------------------------------------------
  t_ck_uart_cfig   uart_cfig;
  uart_cfig.baudrate = BAUD;       // any integer value is allowed
  uart_cfig.parity = PARITY_NONE;     // PARITY_NONE / PARITY_ODD / PARITY_EVEN
  uart_cfig.stopbit = STOPBIT_1;      // STOPBIT_1 / STOPBIT_2
  uart_cfig.wordsize = WORDSIZE_8;    // from WORDSIZE_5 to WORDSIZE_8
  uart_cfig.txmode = ENABLE;          // ENABLE or DISABLE
  // open UART device with id = 0 (UART0)
  ck_uart_open(&uart0, 0);
  // initialize uart using uart_cfig structure
  ck_uart_init(&uart0, &uart_cfig);

//Section 1: Function
  printf("printf test!\n");

//Section 2: Uart


  double  a1 = 1.0, b1 = -10.5, c1 = 32.0, d1 = -30.0;
  double  x[3];
  double X;
  int     solutions;
  int i;
  unsigned long l = 0x3fed0169L;
  struct int_sqrt q;
  long n = 0;

  /* solve soem cubic functions */
  printf("********* CUBIC FUNCTIONS ***********\n");
  /* should get 3 solutions: 2, 6 & 2.5   */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 1.0; b1 = -4.5; c1 = 17.0; d1 = -30.0;
  /* should get 1 solution: 2.5           */
  SolveCubic(a1, b1, c1, d1, &solutions, x);  
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 1.0; b1 = -3.5; c1 = 22.0; d1 = -31.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 1.0; b1 = -13.7; c1 = 1.0; d1 = -35.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 3.0; b1 = 12.34; c1 = 5.0; d1 = 12.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = -8.0; b1 = -67.89; c1 = 6.0; d1 = -23.6;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = 45.0; b1 = 8.67; c1 = 7.5; d1 = 34.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  a1 = -12.0; b1 = -1.7; c1 = 5.3; d1 = 16.0;
  SolveCubic(a1, b1, c1, d1, &solutions, x);
  printf("Solutions:");
  for(i=0;i<solutions;i++)
    printf(" %f",x[i]);
  printf("\n");

  /* Now solve some random equations */
  for(a1=1;a1<10;a1+=1) {
    for(b1=10;b1>0;b1-=.25) {
      for(c1=5;c1<15;c1+=0.61) {
	   for(d1=-1;d1>-5;d1-=.451) {
		SolveCubic(a1, b1, c1, d1, &solutions, x);  
		printf("Solutions:");
		for(i=0;i<solutions;i++)
		  printf(" %f",x[i]);
		printf("\n");
	   }
      }
    }
  }


  printf("********* INTEGER SQR ROOTS ***********\n");
  /* perform some integer square roots */
  for (i = 0; i < 100000; i+=2)
    {
      usqrt(i, &q);
			// remainder differs on some machines
     // printf("sqrt(%3d) = %2d, remainder = %2d\n",
     printf("sqrt(%3d) = %2d\n",
	     i, q.sqrt);
    }
  printf("\n");
  for (l = 0x3fed0169L; l < 0x3fed4169L; l++)
    {
	 usqrt(l, &q);
	 //printf("\nsqrt(%lX) = %X, remainder = %X\n", l, q.sqrt, q.frac);
	 printf("sqrt(%lX) = %X\n", l, q.sqrt);
    }


  printf("********* ANGLE CONVERSION ***********\n");
  /* convert some rads to degrees */
/*   for (X = 0.0; X <= 360.0; X += 1.0) */
  for (X = 0.0; X <= 360.0; X += .001)
    printf("%3.0f degrees = %.12f radians\n", X, deg2rad(X));
  puts("");
/*   for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 180)) */
  for (X = 0.0; X <= (2 * PI + 1e-6); X += (PI / 5760))
    printf("%.12f radians = %3.0f degrees\n", X, rad2deg(X));
  
  
  return 0;
}

 6:文章借鉴很多不一一致谢,有不足的地方欢迎指正,并且很希望遇到同道中人,一起探讨。


网站公告

今日签到

点亮在社区的每一天
去签到