Advertisement
micha_b

bogomips.c broken

Oct 5th, 2023
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.49 KB | Help | 0 0
  1. /*
  2.  * bogo.c
  3.  * measure bogoMIPS
  4.  *
  5.  * sc ansi errorrexx math=standard lib=lib:amiga.lib bogo.c link to bogo
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <exec/exec.h>
  10. #include <intuition/intuition.h>
  11. #include <graphics/gfx.h>
  12. #include <dos/dos.h>
  13. #include <clib/timer_protos.h>
  14.  
  15. #include <devices/timer.h>
  16.  
  17. #include <proto/intuition.h>
  18. #include <proto/graphics.h>
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <proto/timer.h>
  22.  
  23. #include <proto/alib.h>
  24.  
  25. #include <intuition/intuition.h>
  26. #include <clib/timer_protos.h>
  27.  
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <time.h>
  31. #include <math.h>
  32.  
  33. char *vers = "\0$VER: bogoMIPS v1.4 (15.10.2023)";  /* Version string */
  34. char *stacksize = "$STACK:32000";    /* only works when started from CLI */
  35.  
  36. struct IntuitionBase *IntuitionBase;    /*  Zeiger auf IntuitionBase-Struktur */
  37. struct GfxBase *GfxBase;    /*  Zeiger auf GfxBase-Struktur */
  38.  
  39. struct Device *TimerBase;
  40. static struct IORequest timereq;
  41. ULONG t;
  42.  
  43. /* --- Fuction proto types --- */
  44. static void delay(unsigned int loops);
  45. ULONG getBogoTime(void);
  46. static void delay(unsigned int loops);
  47.  
  48. /*
  49.  * Function:    delay(void)
  50.  * Portable version
  51.  */
  52. static void delay(unsigned int loops)
  53. {
  54.   long i;
  55.   for (i = loops; i >= 0 ; i--)
  56.     ; /* do nothing */
  57. }
  58.  
  59. /*
  60.  * Function:    getBogoTime(void)
  61.  */
  62. ULONG getBogoTime(void)
  63. {
  64.   unsigned long loops_per_sec = 1;
  65.   unsigned long ticks = 0;
  66.   static struct timeval tv;   /* is it REALLY initialized correctly? */
  67.   static struct timeval tv2;
  68.  
  69.      TimerBase = (struct Device *)FindName(&SysBase->DeviceList,"timer.device");
  70.      
  71.      printf("Calibrating delay loop.. ");
  72.  
  73.      printf("\nDEBUG: CLOCKS_PER_SEC = %lu", CLOCKS_PER_SEC);
  74.      printf("\nDEBUG: loops_per_second = %lu", loops_per_sec);
  75.      
  76.      while ((loops_per_sec <= 1))
  77.      {
  78.        printf("\nDEBUG: (in loop)CLOCKS_PER_SEC = %lu", CLOCKS_PER_SEC);
  79.        printf("\nDEBUG: (in loop) loops_per_second = %lu", loops_per_sec);
  80.  
  81.        /* ERROR: Allways delivers 0 for tv_secs and tv_micro */
  82.        GetSysTime(&tv2);
  83.  
  84.        delay(loops_per_sec);
  85.  
  86.         /* ERROR: As above */
  87.        GetSysTime(&tv);
  88.  
  89.        SubTime(&tv, &tv2);
  90.        
  91.        printf("\nDEBUG: (in loop) tv_secs = %lu", tv.tv_secs);
  92.        printf("\nDEBUG: (in loop) tv_micro = %lu", tv.tv_micro);
  93.        ticks = (tv.tv_secs*50) + (tv.tv_micro/20000);
  94.        printf("\nDEBUG: (in loop) ticks = %lu\n", ticks);
  95.        
  96.        if (ticks >= CLOCKS_PER_SEC)
  97.        {
  98.          loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
  99.          printf("ok - %lu.%02lu BogoMips\n", loops_per_sec/500000, (loops_per_sec/5000) % 100);
  100.          return 0;
  101.        }
  102.      }
  103.      printf("failed\n");
  104. }
  105.  
  106. void main(void)
  107. {
  108.     ULONG result = 0;
  109.     char c;
  110.    
  111.     /*  Intuition Library öffnen */
  112.     IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36L);
  113.     /*  Graphics Library öffnen */
  114.      GfxBase = (struct GfxBase *) OpenLibrary("graphics.library", 0L);
  115.  
  116.     if(!OpenDevice("timer.device", 0, &timereq, 0))
  117.     {
  118.        TimerBase = timereq.io_Device;
  119.        
  120.        printf("\nDEBUG: (in main) TimerBase = %lu", TimerBase);
  121.        
  122.        /* give shell a chance to display TimerBase */
  123.        c = getchar();
  124.        
  125.        result = getBogoTime();
  126.        
  127.        CloseDevice(&timereq);
  128.    
  129.        CloseLibrary((struct Library *) GfxBase);
  130.        CloseLibrary((struct Library *) IntuitionBase);
  131.     }
  132.     else
  133.        puts("Device not opened!");
  134. }
  135.  
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement