home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / program / a / arm3mips / armmips < prev   
Encoding:
Text File  |  1993-01-10  |  4.3 KB  |  120 lines

  1. REM> armmips
  2. version$="1.15"
  3. *Key1 OSCLI("MemoryI "+STR$~code_start+" "+STR$~code_end)|M
  4. copyright$="(c) 1993 Phill Rogers":filename$="mips"
  5. loopsize%=2:useram%=FALSE:maxcount%=2<<24
  6. pwp=12:wsp=12:sp=13:link=14:pc=15:mode_USR=0:mode_FIQ=1:mode_IRQ=2:mode_SVC=3
  7. flag_F=1<<26:flag_I=1<<27:flag_V=1<<28:flag_C=1<<29:flag_Z=1<<30:flag_N=1<<31
  8. SYS "OS_SWINumberFromString",, "OS_WriteI" TO  OS_WriteI
  9. SYS "OS_SWINumberFromString",,"XOS_WriteI" TO XOS_WriteI
  10. MODE 12:PRINT'"ARM pipelining demo."
  11. PRINT "Count up to what (default is ";maxcount%;") "; 
  12. INPUT maxcount%
  13. IF maxcount%=0 THEN maxcount%=2<<24
  14. INPUT "Count in memory rather than register ";yn$
  15. IF LEFT$(yn$,1)="y" OR LEFT$(yn$,1)="Y" THEN useram%=TRUE
  16. IF NOT useram% THEN
  17.   REPEAT
  18.     PRINT "Loopsize determines pipeline efficiency."
  19.     PRINT "Too small and the pileline gets interrupted too often."
  20.     PRINT "Too large wastes the cache, which the OS still uses while this is running."
  21.     PRINT "Best seems to be about 128, the default."
  22.     INPUT "What size loop ";loopsize%
  23.     IF loopsize%=0 THEN loopsize%=128
  24.   UNTIL loopsize%>1 AND loopsize%<maxcount%
  25. ENDIF
  26. size%=512+loopsize%
  27. DIM code% size%
  28. FOR clear%=0 TO size% STEP 4:code%!clear%=0:NEXT
  29. FOR pass%=0 TO 2 STEP 2
  30.   P%=code%
  31.   PROC_assm
  32. NEXT
  33. REM SYS "OS_File",10,filename$,&FFC,,code_start,code_end
  34. cs%=USR code_start
  35. PRINT'"Code length is : "+STR$(code_end-code_start)+" (&"+STR$~(code_end-code_start)+"hex) bytes."
  36. PRINT "Loopsize ";loopsize%;" instructions."
  37. PRINT "Itterations ";maxcount% / loopsize%;" times."
  38. PRINT "Total of ";maxcount%;" instructions."
  39. PRINT "Executed in ";cs%;" centi-seconds."
  40. PRINT "A rating of ";maxcount% / (cs% * 10000);" MIPS"
  41. END
  42. :
  43. DEF PROC_assm:[OPT pass%:ALIGN:.code_start
  44. .mips_c                                 ;MIPS
  45.         STMFD   sp !,{R1-R4,link}
  46.         SWI     "XCache_Flush"          ;comment this out if no ARM3
  47.         ADR     R4,mips_maxcount
  48.         LDR     R4,[R4]                 ;initialize REGISTER counter
  49.         SUB     R4,R4,#3                ;atleast two instuctions lost in timing admin
  50.         ADR     R3,mips_counter
  51.         STR     R4,[R3]                 ;initialize RAM counter
  52.         MOV     R0,#19                  ;wait for video sync
  53.         SWI     "OS_Byte"               ; to get interrups consistent
  54.         SWINV   "OS_IntOff"             ;only jokeing, clock wouldnt work!
  55.         SWI     "OS_ReadMonotonicTime"
  56.         MOV     R1,R0
  57. .mips_loop
  58.         FN_loopin(loopsize%, useram%)   ;number of instructions in the timmed loop
  59.         BGT     mips_loop
  60.         SWI     "OS_ReadMonotonicTime"
  61.         SWINV   "OS_IntOn"              ;only jokeing, clock wouldnt work!
  62.         SUB     R0,R0,R1                ;save time lapsed into r4 for later
  63.         FN_print(FALSE)                 ;optionally print
  64.         LDMFD   sp !,{R1-R4,pc}         ;exit with answer in r0
  65. .mips_maxcount
  66.         EQUD maxcount%
  67. .mips_counter
  68.         EQUD 0
  69. .mips_buffer
  70.         EQUD 0:EQUD 0
  71. ALIGN:.code_end:]:ENDPROC
  72. :
  73. DEF FN_print(yn%)
  74. IF yn% THEN
  75.   [ OPT pass%
  76.     MOV R4,R0
  77.     ADR R1,mips_buffer          ; point to buffer
  78.     MOV R2,#8                   ; length of buffer
  79.     SWI "OS_BinaryToDecimal"    ;convert to ascii
  80.     MOV R0,#0                   ;zero terminator required
  81.     ADD R2,R2,R1                ; r2 = no of chars used
  82.     ADD R2,R2,#1                ; after the end of the text
  83.     STR R0,[R2]                 ; put the zero terminator
  84.     MOV R0,R1                   ;point r0 to text for printing
  85.     SWI "OS_Write0"             ;print it out
  86.     SWI "OS_NewLine"            ;will change this a bit later
  87.     MOV R0,R4                   ;exit with answer in r0
  88.   ]
  89. ENDIF
  90. =0
  91. :
  92. DEF FN_loopin(loopsize%, ram%)
  93.   LOCAL tmp%
  94.   IF ram%=TRUE THEN
  95.       [ OPT  pass%
  96.         LDR  R4,[R3]
  97.         SUBS R4,R4,#4               ;decrement four times because other instructions can't
  98.         STR  R4,[R3]
  99.       ]
  100.   ELSE
  101.     IF loopsize%>3 THEN
  102.       FOR tmp%=3 TO loopsize%
  103.       [ OPT  pass%
  104.         SUBS R4,R4,#1               ;each insr. does itsown decrement
  105.       ]
  106.       NEXT
  107.     ENDIF
  108.     IF loopsize%=3 THEN
  109.       [ OPT  pass%
  110.         SUB  R4,R4,#3               ;decrement thrice because next two instructions can't
  111.         CMP  R4,#0                  ;this is what the C compiler writes (decrement then compare)
  112.       ]
  113.     ELSE
  114.       [ OPT  pass%
  115.         SUBS R4,R4,#2               ;decrement twice because next instruction can't
  116.       ]
  117.     ENDIF
  118.   ENDIF
  119. =0
  120.