一:移植过程中遇到的问题
1;总体的思路和之前的那个basic math是一样的makefile文件的修改可以参考之前的basicmath。这里gcc编译产生的可执行文件是需要给bitcount传进去一个迭代次数itrations,为了能在自己搭建的平台下面跑通这里我给他在bitcnts.c里面直接修改这个数值itrations
这个数值可以根据源代码里面的runme_larg.sh和small.sh修改的这李修改为小的值75000
2:编译成功但是仿真不成功的问题,编译成功如下
但是runcase仿真就出错的问题如下图。
二:解决方法:这个问题首先看一下这个程序。有七个函数会被调用,并通过一个函数指针调用的,编译能过就是仿真能够跑到start=clock()这里就出问题了这个东西配合后面的stop=clock()是用来计算调用的函数的运行时间的,仿真到start=clock()这就进行不下去了,这里要看一下这个clock()函数是在头文件time.h里面定义的,这里应该换成smart_run平台下面的timer.h头文件的。可以理解为time.h是自己电脑的定义而timer.h是smart_run平台下的头文件,所以获取的时间也应该是samrt_run自己写的。解释起来有点困难。
/* +++Date last modified: 05-Jul-1997 */
/*
** BITCNTS.C - Test program for bit counting functions
**
** public domain by Bob Stout & Auke Reitsma
*/
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
#include <limits.h>
#include <time.h>
#include <float.h>
#include "bitops.h"
#define FUNCS 7
static int CDECL bit_shifter(long int x);
int main(int argc, char *argv[])
{
clock_t start, stop;
double ct, cmin = DBL_MAX, cmax = 0;
int i, cminix, cmaxix;
long j, n, seed;
int iterations=2;
static int (* CDECL pBitCntFunc[FUNCS])(long) = {
bit_count,
bitcount,
ntbl_bitcnt,
ntbl_bitcount,
/* btbl_bitcnt, DOESNT WORK*/
BW_btbl_bitcount,
AR_btbl_bitcount,
bit_shifter
};
static char *text[FUNCS] = {
"Optimized 1 bit/loop counter",
"Ratko's mystery algorithm",
"Recursive bit count by nybbles",
"Non-recursive bit count by nybbles",
/* "Recursive bit count by bytes",*/
"Non-recursive bit count by bytes (BW)",
"Non-recursive bit count by bytes (AR)",
"Shift and count bits"
};
if (argc<2) {
fprintf(stderr,"Usage: bitcnts <iterations>\n");
exit(-1);
}
iterations=atoi(argv[1]);
puts("Bit counter algorithm benchmark\n");
for (i = 0; i < FUNCS; i++) {
start = clock();
for (j = n = 0, seed = rand(); j < iterations; j++, seed += 13)
n += pBitCntFunc[i](seed);
stop = clock();
ct = (stop - start) / (double)CLOCKS_PER_SEC;
if (ct < cmin) {
cmin = ct;
cminix = i;
}
if (ct > cmax) {
cmax = ct;
cmaxix = i;
}
printf("%-38s> Time: %7.3f sec.; Bits: %ld\n", text[i], ct, n);
}
printf("\nBest > %s\n", text[cminix]);
printf("Worst > %s\n", text[cmaxix]);
return 0;
}
static int CDECL bit_shifter(long int x)
{
int i, n;
for (i = n = 0; x && (i < (sizeof(long) * CHAR_BIT)); ++i, x >>= 1)
n += (int)(x & 1L);
return n;
}
这两个文件就是我从samrt_run下面的test/lib文件夹下面复制过来的,。把bitcnts.c里面的time.h头文件替换掉,并且要把samrt_run下面的test/lib文件夹下这两个文件给删除掉。如果不删除就会出现编译不过的问题,Loop_Num这个问题,如下图。只要删除这个问题就解决了。
3:最后贴一下修改后的代码
/* +++Date last modified: 05-Jul-1997 */
/*
** BITCNTS.C - Test program for bit counting functions
**
** public domain by Bob Stout & Auke Reitsma
*/
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
#include <limits.h>
//#include <time.h>
#include"timer.h"
#include"config.h"
#include <float.h>
#include "bitops.h"
#include"datatype.h"
#include"uart.h"
#define FUNCS 7
static int CDECL bit_shifter(long int x);
/*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(int argc, char *argv[])
{
/*
//--------------------------------------------------------
// 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);
*/
clock_t start, stop;
double ct, cmin = DBL_MAX, cmax = 0;
int i, cminix, cmaxix;
long j, n, seed;
int iterations;
static int (* CDECL pBitCntFunc[FUNCS])(long) = {
bit_count,
bitcount,
ntbl_bitcnt,
ntbl_bitcount,
/* btbl_bitcnt, DOESNT WORK*/
BW_btbl_bitcount,
AR_btbl_bitcount,
bit_shifter
};
static char *text[FUNCS] = {
"Optimized 1 bit/loop counter",
"Ratko's mystery algorithm",
"Recursive bit count by nybbles",
"Non-recursive bit count by nybbles",
/* "Recursive bit count by bytes",*/
"Non-recursive bit count by bytes (BW)",
"Non-recursive bit count by bytes (AR)",
"Shift and count bits"
};
/* if (argc<2) {
fprintf(stderr,"Usage: bitcnts <iterations>\n");
exit(-1);
}*/
//iterations=atoi(argv[1]);
iterations=7500;
puts("Bit counter algorithm benchmark\n");
for (i = 0; i < FUNCS; i++) {
//start = clock();
start=get_timer();
for (j = n = 0, seed = rand(); j < iterations; j++, seed += 13)
n += pBitCntFunc[i](seed);
// stop = clock();
stop=get_timer();
ct = (stop - start) / (double)CLOCKS_PER_SEC;
if (ct < cmin) {
cmin = ct;
cminix = i;
}
if (ct > cmax) {
cmax = ct;
cmaxix = i;
}
printf("%-38s> Time: %7.3f sec.; Bits: %ld\n", text[i], ct, n);
}
printf("\nBest > %s\n", text[cminix]);
printf("Worst > %s\n", text[cmaxix]);
return 0;
}
static int CDECL bit_shifter(long int x)
{
int i, n;
for (i = n = 0; x && (i < (sizeof(long) * CHAR_BIT)); ++i, x >>= 1)
n += (int)(x & 1L);
return n;
}
4:总结,表达欠缺。继续加油把,这是成功后的图