Hifitest.c

From Linux/Xtensa
Jump to navigation Jump to search
  #include <stdio.h>
  #include <time.h>
  #include <xtensa/tie/xt_hifi2.h>
  
  #define INC 1
  
  main(int argc, char **argv)
  {
    int inc;
    int inc2;
    register ae_p24x2s p24_cnt;
    register ae_p24x2s p24_inc;
    register ae_p24x2s p24_pid;
    int cnt;
    int cnt2;
    int pid;
    int pid2;
    volatile int i, j, k, l;
    time_t time0 = time(NULL);
    time_t time1 = time(NULL);
  
  restart:
    cnt = 0;
    cnt2 = 0;
    inc = INC;
    pid = getpid();
    p24_cnt = AE_ZEROP48();
    p24_inc = AE_MOVPA24(inc);
    p24_pid = AE_MOVPA24(pid);
  
    while (1)
      {
        int errors = 0;
  
        if ((cnt & 0xffffff) == 0) {
  	time0 = time1;
  	time1 = time(NULL);
  	printf("cnt:0x%x, pid:%d; Eatting cpu; time:%ld\n", cnt, pid, (time1 - time0));
  	for(i = 0; i<1000; i++) {
  	    for(j = 0; j < 1000; j++) {
  	        for(k = 0; k < 10; k++) {
  			l++;
  	    	}
  	    }
  	}
  	time0 = time1;
  	time1 = time(NULL);
  	printf("cnt:0x%x, pid:%d; Eating Tie; time:%ld\n", cnt, pid, (time1 - time0));
        }	
        cnt = (cnt + inc) & 0xffffff;
        p24_cnt = AE_ADDP24(p24_cnt, p24_inc);
        cnt2 = AE_MOVAP24S_L(p24_cnt) & 0xffffff;
        pid2 = AE_MOVAP24S_L(p24_pid) & 0xffffff;
        inc2 = AE_MOVAP24S_L(p24_inc) & 0xffffff;
  
        if (cnt2 != cnt)
  	{
  	  swapon("/tmp/cmt2", 0);
  	  printf("Error: cnt2:0x%x != cnt:0x%x\n", cnt2, cnt);
  	  errors++;
  	}
        if (inc2 != inc)
  	{
  	  swapon("/tmp/inc2", 0);
  	  printf("Error: inc2:%d != inc:%d\n", cnt2, cnt);
  	  errors++;
  	}
        if ( pid2 != pid)
  	{
  	  swapon("/tmp/pid2", 0);
  	  printf("Error: pid2:%d != pid:%d\n", pid2, pid);
  	  errors++;
  	}
  
  	if (errors) {
  	    printf("for...\n");
  	    for(i=0; i < 0x3FFFF; i++) 
  		j++;
  	    printf("sleep 10\n");
  	    sleep(10);	
  	    printf("for...\n");
  		for(i=0; i < 0x3FFFF; i++)
  			j++;	
  	    printf("restart\n");	
  	    goto restart;
  	}
      }
  }