Advertisement
Guest User

Untitled

a guest
Nov 28th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.44 KB | None | 0 0
  1. .text
  2. .global _start
  3. _start:
  4. BL CONFIG_VIRTUAL_MEMORY
  5.  
  6. // Configure PMN0 to count cycles
  7. MOV R0, #0 // Write 0 into R0 then PMSELR
  8. MCR p15, 0, R0, c9, c12, 5 // Write 0 into PMSELR selects PMN0
  9. MOV R1, #0x11 // Event 0x11 is CPU cycles
  10. MCR p15, 0, R1, c9, c13, 1 // Write 0x11 into PMXEVTYPER (PMN0 measure CPU cycles)
  11.  
  12. // Configure PMN1 to count data cache misses
  13. MOV R11, #1 // Write 1 into R0 then PMSELR
  14. MCR p15, 0, R11, c9, c12, 5 // Write 0 into PMSELR selects PMN1
  15. MOV R1, #0x3 // Event 0x3 is CPU cycles
  16. MCR p15, 0, R1, c9, c13, 1 // Write 0x3 into PMXEVTYPER (PMN1 measure data cache)
  17.  
  18. // Configure PMN2 to count number of load instructions
  19. MOV R2, #2 // Write 2 into R0 then PMSELR
  20. MCR p15, 0, R2, c9, c12, 5 // Write 0 into PMSELR selects PMN2
  21. MOV R1, #0x6 // Event 0x6 is CPU cycles
  22. MCR p15, 0, R1, c9, c13, 1 // Write 0x6 into PMXEVTYPER (PMN2 measure load instructions)
  23.  
  24. // Enable PMN0-PMN2
  25. mov R0, #0b1 // Setting bits 0-2 to 1 in PMCNTENSET
  26. mov R11, #0b10 // Setting bits 0-2 to 1 in PMCNTENSET
  27. mov R2, #0b100 // Setting bits 0-2 to 1 in PMCNTENSET
  28.  
  29. MCR p15, 0, R0, c9, c12, 1 // Setting bit 0 of PMCNTENSET enables PMN0-PMN2
  30. MCR p15, 0, R11, c9, c12, 1
  31. MCR p15, 0, R2, c9, c12, 1
  32.  
  33. // Clear all counters and start counters
  34. mov r0, #3 // bits 0 (start counters) and 1 (reset counters)
  35. MCR p15, 0, r0, c9, c12, 0 // Setting PMCR to 3
  36.  
  37. // Code we wish to profile using hardware counters
  38. mov r1, #0x00100000 // base of array
  39. mov r2, #0x100 // iterations of inner loop
  40. mov r3, #2 // iterations of outer loop
  41. mov r4, #0 // i=0 (outer loop counter)
  42. L_outer_loop:
  43. mov r5, #0 // j=0 (inner loop counter)
  44. L_inner_loop:
  45. ldr r6, [r1, r5, LSL #6] // read data from memory
  46. add r5, r5, #1 // j=j+1
  47. cmp r5, r2 // compare j with 256
  48. blt L_inner_loop // branch if less than
  49. add r4, r4, #1 // i=i+1
  50. cmp r4, r3 // compare i with 2
  51. blt L_outer_loop // branch if less than
  52.  
  53. // Stop counters
  54. mov r0, #0
  55. MCR p15, 0, r0, c9, c12, 0 // Write 0 to PMCR to stop counters
  56.  
  57. // Select PMN0 and read out result into R3
  58. mov r0, #0 // PMN0
  59. MCR p15, 0, r0, c9, c12, 5 // Write 0 to PMSELR
  60. MRC p15, 0, r3, c9, c13, 2 // Read PMXEVCNTR into r3 - CPU
  61.  
  62. mov r11, #1 // PMN1
  63. MCR p15, 0, r11, c9, c12, 5 // Write 1 to PMSELR
  64. MRC p15, 0, r4, c9, c13, 2 // Read PMXEVCNTR into r4 - data miss
  65.  
  66. mov r2, #2 // PMN2
  67. MCR p15, 0, r2, c9, c12, 5 // Write 2 to PMSELR
  68. MRC p15, 0, r5, c9, c13, 2 // Read PMXEVCNTR into r5 - load instructions
  69.  
  70. end: b end // wait here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement