asm.S 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config.h"
  21. #ifdef __ELF__
  22. # define ELF
  23. #else
  24. # define ELF @
  25. #endif
  26. #if CONFIG_THUMB
  27. # define A @
  28. # define T
  29. #else
  30. # define A
  31. # define T @
  32. #endif
  33. #if HAVE_NEON
  34. .arch armv7-a
  35. #elif HAVE_ARMV6T2
  36. .arch armv6t2
  37. #elif HAVE_ARMV6
  38. .arch armv6
  39. #elif HAVE_ARMV5TE
  40. .arch armv5te
  41. #endif
  42. #if HAVE_AS_OBJECT_ARCH
  43. ELF .object_arch armv4
  44. #endif
  45. #if HAVE_NEON
  46. .fpu neon
  47. ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
  48. ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch
  49. #elif HAVE_VFP
  50. .fpu vfp
  51. ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
  52. #endif
  53. .syntax unified
  54. T .thumb
  55. ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
  56. .macro function name, export=0
  57. .set .Lpic_idx, 0
  58. .set .Lpic_gp, 0
  59. .macro endfunc
  60. .if .Lpic_idx
  61. .align 2
  62. .altmacro
  63. put_pic %(.Lpic_idx - 1)
  64. .noaltmacro
  65. .endif
  66. ELF .size \name, . - \name
  67. .endfunc
  68. .purgem endfunc
  69. .endm
  70. .text
  71. .align 2
  72. .if \export
  73. .global EXTERN_ASM\name
  74. EXTERN_ASM\name:
  75. .endif
  76. ELF .type \name, %function
  77. .func \name
  78. \name:
  79. .endm
  80. .macro const name, align=2
  81. .macro endconst
  82. ELF .size \name, . - \name
  83. .purgem endconst
  84. .endm
  85. .section .rodata
  86. .align \align
  87. \name:
  88. .endm
  89. #if !HAVE_ARMV6T2_EXTERNAL
  90. .macro movw rd, val
  91. mov \rd, \val & 255
  92. orr \rd, \val & ~255
  93. .endm
  94. #endif
  95. .macro mov32 rd, val
  96. #if HAVE_ARMV6T2_EXTERNAL
  97. movw \rd, #(\val) & 0xffff
  98. .if (\val) >> 16
  99. movt \rd, #(\val) >> 16
  100. .endif
  101. #else
  102. ldr \rd, =\val
  103. #endif
  104. .endm
  105. .macro put_pic num
  106. put_pic_\num
  107. .endm
  108. .macro do_def_pic num, val, label
  109. .macro put_pic_\num
  110. .if \num
  111. .altmacro
  112. put_pic %(\num - 1)
  113. .noaltmacro
  114. .endif
  115. \label: .word \val
  116. .purgem put_pic_\num
  117. .endm
  118. .endm
  119. .macro def_pic val, label
  120. .altmacro
  121. do_def_pic %.Lpic_idx, \val, \label
  122. .noaltmacro
  123. .set .Lpic_idx, .Lpic_idx + 1
  124. .endm
  125. .macro ldpic rd, val, indir=0
  126. ldr \rd, .Lpicoff\@
  127. .Lpic\@:
  128. .if \indir
  129. A ldr \rd, [pc, \rd]
  130. T add \rd, pc
  131. T ldr \rd, [\rd]
  132. .else
  133. add \rd, pc
  134. .endif
  135. def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
  136. .endm
  137. .macro movrel rd, val
  138. #if CONFIG_PIC
  139. ldpic \rd, \val
  140. #elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
  141. movw \rd, #:lower16:\val
  142. movt \rd, #:upper16:\val
  143. #else
  144. ldr \rd, =\val
  145. #endif
  146. .endm
  147. .macro movrelx rd, val, gp
  148. #if CONFIG_PIC && defined(__ELF__)
  149. .ifnb \gp
  150. .if .Lpic_gp
  151. .unreq gp
  152. .endif
  153. gp .req \gp
  154. ldpic gp, _GLOBAL_OFFSET_TABLE_
  155. .elseif !.Lpic_gp
  156. gp .req r12
  157. ldpic gp, _GLOBAL_OFFSET_TABLE_
  158. .endif
  159. .set .Lpic_gp, 1
  160. ldr \rd, .Lpicoff\@
  161. ldr \rd, [gp, \rd]
  162. def_pic \val(GOT), .Lpicoff\@
  163. #elif CONFIG_PIC && defined(__APPLE__)
  164. ldpic \rd, .Lpic\@, indir=1
  165. .non_lazy_symbol_pointer
  166. .Lpic\@:
  167. .indirect_symbol \val
  168. .word 0
  169. .text
  170. #else
  171. movrel \rd, \val
  172. #endif
  173. .endm
  174. .macro add_sh rd, rn, rm, sh:vararg
  175. A add \rd, \rn, \rm, \sh
  176. T mov \rm, \rm, \sh
  177. T add \rd, \rn, \rm
  178. .endm
  179. .macro ldr_pre rt, rn, rm:vararg
  180. A ldr \rt, [\rn, \rm]!
  181. T add \rn, \rn, \rm
  182. T ldr \rt, [\rn]
  183. .endm
  184. .macro ldr_dpre rt, rn, rm:vararg
  185. A ldr \rt, [\rn, -\rm]!
  186. T sub \rn, \rn, \rm
  187. T ldr \rt, [\rn]
  188. .endm
  189. .macro ldr_nreg rt, rn, rm:vararg
  190. A ldr \rt, [\rn, -\rm]
  191. T sub \rt, \rn, \rm
  192. T ldr \rt, [\rt]
  193. .endm
  194. .macro ldr_post rt, rn, rm:vararg
  195. A ldr \rt, [\rn], \rm
  196. T ldr \rt, [\rn]
  197. T add \rn, \rn, \rm
  198. .endm
  199. .macro ldrc_pre cc, rt, rn, rm:vararg
  200. A ldr\cc \rt, [\rn, \rm]!
  201. T itt \cc
  202. T add\cc \rn, \rn, \rm
  203. T ldr\cc \rt, [\rn]
  204. .endm
  205. .macro ldrd_reg rt, rt2, rn, rm
  206. A ldrd \rt, \rt2, [\rn, \rm]
  207. T add \rt, \rn, \rm
  208. T ldrd \rt, \rt2, [\rt]
  209. .endm
  210. .macro ldrd_post rt, rt2, rn, rm
  211. A ldrd \rt, \rt2, [\rn], \rm
  212. T ldrd \rt, \rt2, [\rn]
  213. T add \rn, \rn, \rm
  214. .endm
  215. .macro ldrh_pre rt, rn, rm
  216. A ldrh \rt, [\rn, \rm]!
  217. T add \rn, \rn, \rm
  218. T ldrh \rt, [\rn]
  219. .endm
  220. .macro ldrh_dpre rt, rn, rm
  221. A ldrh \rt, [\rn, -\rm]!
  222. T sub \rn, \rn, \rm
  223. T ldrh \rt, [\rn]
  224. .endm
  225. .macro ldrh_post rt, rn, rm
  226. A ldrh \rt, [\rn], \rm
  227. T ldrh \rt, [\rn]
  228. T add \rn, \rn, \rm
  229. .endm
  230. .macro ldrb_post rt, rn, rm
  231. A ldrb \rt, [\rn], \rm
  232. T ldrb \rt, [\rn]
  233. T add \rn, \rn, \rm
  234. .endm
  235. .macro str_post rt, rn, rm:vararg
  236. A str \rt, [\rn], \rm
  237. T str \rt, [\rn]
  238. T add \rn, \rn, \rm
  239. .endm
  240. .macro strb_post rt, rn, rm:vararg
  241. A strb \rt, [\rn], \rm
  242. T strb \rt, [\rn]
  243. T add \rn, \rn, \rm
  244. .endm
  245. .macro strd_post rt, rt2, rn, rm
  246. A strd \rt, \rt2, [\rn], \rm
  247. T strd \rt, \rt2, [\rn]
  248. T add \rn, \rn, \rm
  249. .endm
  250. .macro strh_pre rt, rn, rm
  251. A strh \rt, [\rn, \rm]!
  252. T add \rn, \rn, \rm
  253. T strh \rt, [\rn]
  254. .endm
  255. .macro strh_dpre rt, rn, rm
  256. A strh \rt, [\rn, -\rm]!
  257. T sub \rn, \rn, \rm
  258. T strh \rt, [\rn]
  259. .endm
  260. .macro strh_post rt, rn, rm
  261. A strh \rt, [\rn], \rm
  262. T strh \rt, [\rn]
  263. T add \rn, \rn, \rm
  264. .endm
  265. .macro strh_dpost rt, rn, rm
  266. A strh \rt, [\rn], -\rm
  267. T strh \rt, [\rn]
  268. T sub \rn, \rn, \rm
  269. .endm
  270. #if HAVE_VFP_ARGS
  271. .eabi_attribute 28, 1
  272. # define VFP
  273. # define NOVFP @
  274. #else
  275. # define VFP @
  276. # define NOVFP
  277. #endif
  278. #define GLUE(a, b) a ## b
  279. #define JOIN(a, b) GLUE(a, b)
  280. #define X(s) JOIN(EXTERN_ASM, s)