checkasm-aarch64.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /****************************************************************************
  2. * checkasm-aarch64.S: assembly check tool
  3. *****************************************************************************
  4. * Copyright (C) 2015-2018 x264 project
  5. *
  6. * Authors: Martin Storsjo <martin@martin.st>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  21. *
  22. * This program is also available under a commercial proprietary license.
  23. * For more information, contact us at licensing@x264.com.
  24. *****************************************************************************/
  25. #include "../common/aarch64/asm.S"
  26. const register_init, align=4
  27. .quad 0x21f86d66c8ca00ce
  28. .quad 0x75b6ba21077c48ad
  29. .quad 0xed56bb2dcb3c7736
  30. .quad 0x8bda43d3fd1a7e06
  31. .quad 0xb64a9c9e5d318408
  32. .quad 0xdf9a54b303f1d3a3
  33. .quad 0x4a75479abd64e097
  34. .quad 0x249214109d5d1c88
  35. .quad 0x1a1b2550a612b48c
  36. .quad 0x79445c159ce79064
  37. .quad 0x2eed899d5a28ddcd
  38. .quad 0x86b2536fcd8cf636
  39. .quad 0xb0856806085e7943
  40. .quad 0x3f2bf84fc0fcca4e
  41. .quad 0xacbd382dcf5b8de2
  42. .quad 0xd229e1f5b281303f
  43. .quad 0x71aeaff20b095fd9
  44. .quad 0xab63e2e11fa38ed9
  45. endconst
  46. const error_message
  47. .asciz "failed to preserve register"
  48. endconst
  49. .text
  50. // max number of args used by any x264 asm function.
  51. #define MAX_ARGS 15
  52. #define CLOBBER_STACK ((8*MAX_ARGS + 15) & ~15)
  53. function checkasm_stack_clobber, export=1
  54. mov x3, sp
  55. mov x2, #CLOBBER_STACK
  56. 1:
  57. stp x0, x1, [sp, #-16]!
  58. subs x2, x2, #16
  59. b.gt 1b
  60. mov sp, x3
  61. ret
  62. endfunc
  63. #define ARG_STACK ((8*(MAX_ARGS - 8) + 15) & ~15)
  64. function checkasm_call, export=1
  65. stp x29, x30, [sp, #-16]!
  66. mov x29, sp
  67. stp x19, x20, [sp, #-16]!
  68. stp x21, x22, [sp, #-16]!
  69. stp x23, x24, [sp, #-16]!
  70. stp x25, x26, [sp, #-16]!
  71. stp x27, x28, [sp, #-16]!
  72. stp d8, d9, [sp, #-16]!
  73. stp d10, d11, [sp, #-16]!
  74. stp d12, d13, [sp, #-16]!
  75. stp d14, d15, [sp, #-16]!
  76. movrel x9, register_init
  77. ldp d8, d9, [x9], #16
  78. ldp d10, d11, [x9], #16
  79. ldp d12, d13, [x9], #16
  80. ldp d14, d15, [x9], #16
  81. ldp x19, x20, [x9], #16
  82. ldp x21, x22, [x9], #16
  83. ldp x23, x24, [x9], #16
  84. ldp x25, x26, [x9], #16
  85. ldp x27, x28, [x9], #16
  86. str x1, [sp, #-16]!
  87. sub sp, sp, #ARG_STACK
  88. .equ pos, 0
  89. .rept MAX_ARGS-8
  90. // Skip the first 8 args, that are loaded into registers
  91. ldr x9, [x29, #16 + 8*8 + pos]
  92. str x9, [sp, #pos]
  93. .equ pos, pos + 8
  94. .endr
  95. mov x12, x0
  96. ldp x0, x1, [x29, #16]
  97. ldp x2, x3, [x29, #32]
  98. ldp x4, x5, [x29, #48]
  99. ldp x6, x7, [x29, #64]
  100. blr x12
  101. add sp, sp, #ARG_STACK
  102. ldr x2, [sp]
  103. stp x0, x1, [sp]
  104. movrel x9, register_init
  105. movi v3.8h, #0
  106. .macro check_reg_neon reg1, reg2
  107. ldr q0, [x9], #16
  108. uzp1 v1.2d, v\reg1\().2d, v\reg2\().2d
  109. eor v0.16b, v0.16b, v1.16b
  110. orr v3.16b, v3.16b, v0.16b
  111. .endm
  112. check_reg_neon 8, 9
  113. check_reg_neon 10, 11
  114. check_reg_neon 12, 13
  115. check_reg_neon 14, 15
  116. uqxtn v3.8b, v3.8h
  117. umov x3, v3.d[0]
  118. .macro check_reg reg1, reg2
  119. ldp x0, x1, [x9], #16
  120. eor x0, x0, \reg1
  121. eor x1, x1, \reg2
  122. orr x3, x3, x0
  123. orr x3, x3, x1
  124. .endm
  125. check_reg x19, x20
  126. check_reg x21, x22
  127. check_reg x23, x24
  128. check_reg x25, x26
  129. check_reg x27, x28
  130. cbz x3, 0f
  131. mov w9, #0
  132. str w9, [x2]
  133. movrel x0, error_message
  134. bl EXT(puts)
  135. 0:
  136. ldp x0, x1, [sp], #16
  137. ldp d14, d15, [sp], #16
  138. ldp d12, d13, [sp], #16
  139. ldp d10, d11, [sp], #16
  140. ldp d8, d9, [sp], #16
  141. ldp x27, x28, [sp], #16
  142. ldp x25, x26, [sp], #16
  143. ldp x23, x24, [sp], #16
  144. ldp x21, x22, [sp], #16
  145. ldp x19, x20, [sp], #16
  146. ldp x29, x30, [sp], #16
  147. ret
  148. endfunc