Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #define likely(x) __builtin_expect(!!(x), 1)
  2. #define unlikely(x) __builtin_expect(!!(x), 0)
  3.  
  4. int test(int a)
  5. {
  6. if (a < 5)
  7. return 1;
  8. else
  9. return 2;
  10. }
  11.  
  12. int test_likely(int a)
  13. {
  14. if (likely(a < 5))
  15. return 1;
  16. else
  17. return 2;
  18. }
  19.  
  20. int test_unlikely(int a)
  21. {
  22. if (unlikely(a < 5))
  23. return 1;
  24. else
  25. return 2;
  26. }
  27.  
  28.  
  29.  
  30. Disassembly of section .text:
  31.  
  32. 00000000 <test>:
  33. 0: 37 9c ff f4 addi sp,sp,-12
  34. 4: 5b 9b 00 08 sw (sp+8),fp
  35. 8: 5b 9d 00 04 sw (sp+4),ra
  36. c: 34 1b 00 0c mvi fp,12
  37. 10: b7 7c d8 00 add fp,fp,sp
  38. 14: 5b 61 00 00 sw (fp+0),r1
  39. 18: 2b 62 00 00 lw r2,(fp+0)
  40. 1c: 34 01 00 04 mvi r1,4
  41. 20: 48 41 00 03 bg r2,r1,2c <test+0x2c>
  42. 24: 34 01 00 01 mvi r1,1
  43. 28: e0 00 00 02 bi 30 <test+0x30>
  44. 2c: 34 01 00 02 mvi r1,2
  45. 30: 2b 9b 00 08 lw fp,(sp+8)
  46. 34: 2b 9d 00 04 lw ra,(sp+4)
  47. 38: 37 9c 00 0c addi sp,sp,12
  48. 3c: c3 a0 00 00 ret
  49.  
  50. 00000040 <test_likely>:
  51. 40: 37 9c ff f4 addi sp,sp,-12
  52. 44: 5b 9b 00 08 sw (sp+8),fp
  53. 48: 5b 9d 00 04 sw (sp+4),ra
  54. 4c: 34 1b 00 0c mvi fp,12
  55. 50: b7 7c d8 00 add fp,fp,sp
  56. 54: 5b 61 00 00 sw (fp+0),r1
  57. 58: 2b 61 00 00 lw r1,(fp+0)
  58. 5c: 34 02 00 04 mvi r2,4
  59. 60: ec 41 08 00 cmpge r1,r2,r1
  60. 64: b8 20 10 00 mv r2,r1
  61. 68: 34 01 00 00 mvi r1,0
  62. 6c: 44 41 00 03 be r2,r1,78 <test_likely+0x38>
  63. 70: 34 01 00 01 mvi r1,1
  64. 74: e0 00 00 02 bi 7c <test_likely+0x3c>
  65. 78: 34 01 00 02 mvi r1,2
  66. 7c: 2b 9b 00 08 lw fp,(sp+8)
  67. 80: 2b 9d 00 04 lw ra,(sp+4)
  68. 84: 37 9c 00 0c addi sp,sp,12
  69. 88: c3 a0 00 00 ret
  70.  
  71. 0000008c <test_unlikely>:
  72. 8c: 37 9c ff f4 addi sp,sp,-12
  73. 90: 5b 9b 00 08 sw (sp+8),fp
  74. 94: 5b 9d 00 04 sw (sp+4),ra
  75. 98: 34 1b 00 0c mvi fp,12
  76. 9c: b7 7c d8 00 add fp,fp,sp
  77. a0: 5b 61 00 00 sw (fp+0),r1
  78. a4: 2b 61 00 00 lw r1,(fp+0)
  79. a8: 34 02 00 04 mvi r2,4
  80. ac: ec 41 08 00 cmpge r1,r2,r1
  81. b0: b8 20 10 00 mv r2,r1
  82. b4: 34 01 00 00 mvi r1,0
  83. b8: 44 41 00 03 be r2,r1,c4 <test_unlikely+0x38>
  84. bc: 34 01 00 01 mvi r1,1
  85. c0: e0 00 00 02 bi c8 <test_unlikely+0x3c>
  86. c4: 34 01 00 02 mvi r1,2
  87. c8: 2b 9b 00 08 lw fp,(sp+8)
  88. cc: 2b 9d 00 04 lw ra,(sp+4)
  89. d0: 37 9c 00 0c addi sp,sp,12
  90. d4: c3 a0 00 00 ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement