asm.S 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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_AS_FUNC
  34. # define FUNC
  35. #else
  36. # define FUNC @
  37. #endif
  38. #if HAVE_AS_FPU_DIRECTIVE
  39. # define FPU
  40. #else
  41. # define FPU @
  42. #endif
  43. #if CONFIG_THUMB && defined(__APPLE__)
  44. # define TFUNC
  45. #else
  46. # define TFUNC @
  47. #endif
  48. #if HAVE_AS_ARCH_DIRECTIVE
  49. #if HAVE_NEON
  50. .arch armv7-a
  51. #elif HAVE_ARMV6T2
  52. .arch armv6t2
  53. #elif HAVE_ARMV6
  54. .arch armv6
  55. #elif HAVE_ARMV5TE
  56. .arch armv5te
  57. #endif
  58. #endif
  59. #if HAVE_AS_OBJECT_ARCH
  60. ELF .object_arch armv4
  61. #endif
  62. #if HAVE_NEON
  63. FPU .fpu neon
  64. ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
  65. ELF .eabi_attribute 12, 0 @ suppress Tag_Advanced_SIMD_arch
  66. #elif HAVE_VFP
  67. FPU .fpu vfp
  68. ELF .eabi_attribute 10, 0 @ suppress Tag_FP_arch
  69. #endif
  70. .syntax unified
  71. T .thumb
  72. ELF .eabi_attribute 25, 1 @ Tag_ABI_align_preserved
  73. ELF .section .note.GNU-stack,"",%progbits @ Mark stack as non-executable
  74. .macro function name, export=0, align=2
  75. .set .Lpic_idx, 0
  76. .set .Lpic_gp, 0
  77. .macro endfunc
  78. .if .Lpic_idx
  79. .align 2
  80. .altmacro
  81. put_pic %(.Lpic_idx - 1)
  82. .noaltmacro
  83. .endif
  84. .if .Lpic_gp
  85. .unreq gp
  86. .endif
  87. ELF .size \name, . - \name
  88. FUNC .endfunc
  89. .purgem endfunc
  90. .endm
  91. .text
  92. .align \align
  93. .if \export
  94. .global EXTERN_ASM\name
  95. ELF .type EXTERN_ASM\name, %function
  96. FUNC .func EXTERN_ASM\name
  97. TFUNC .thumb_func EXTERN_ASM\name
  98. EXTERN_ASM\name:
  99. .else
  100. ELF .type \name, %function
  101. FUNC .func \name
  102. TFUNC .thumb_func \name
  103. \name:
  104. .endif
  105. .endm
  106. .macro const name, align=2, relocate=0
  107. .macro endconst
  108. ELF .size \name, . - \name
  109. .purgem endconst
  110. .endm
  111. #if HAVE_SECTION_DATA_REL_RO
  112. .if \relocate
  113. .section .data.rel.ro
  114. .else
  115. .section .rodata
  116. .endif
  117. #elif defined(_WIN32)
  118. .section .rdata
  119. #elif !defined(__MACH__)
  120. .section .rodata
  121. #else
  122. .const_data
  123. #endif
  124. .align \align
  125. \name:
  126. .endm
  127. #if !HAVE_ARMV6T2_EXTERNAL
  128. .macro movw rd, val
  129. mov \rd, \val & 255
  130. orr \rd, \val & ~255
  131. .endm
  132. #endif
  133. .macro mov32 rd, val
  134. #if HAVE_ARMV6T2_EXTERNAL
  135. movw \rd, #(\val) & 0xffff
  136. .if (\val) >> 16
  137. movt \rd, #(\val) >> 16
  138. .endif
  139. #else
  140. ldr \rd, =\val
  141. #endif
  142. .endm
  143. .macro put_pic num
  144. put_pic_\num
  145. .endm
  146. .macro do_def_pic num, val, label
  147. .macro put_pic_\num
  148. .if \num
  149. .altmacro
  150. put_pic %(\num - 1)
  151. .noaltmacro
  152. .endif
  153. \label: .word \val
  154. .purgem put_pic_\num
  155. .endm
  156. .endm
  157. .macro def_pic val, label
  158. .altmacro
  159. do_def_pic %.Lpic_idx, \val, \label
  160. .noaltmacro
  161. .set .Lpic_idx, .Lpic_idx + 1
  162. .endm
  163. .macro ldpic rd, val, indir=0
  164. ldr \rd, .Lpicoff\@
  165. .Lpic\@:
  166. .if \indir
  167. A ldr \rd, [pc, \rd]
  168. T add \rd, pc
  169. T ldr \rd, [\rd]
  170. .else
  171. add \rd, pc
  172. .endif
  173. def_pic \val - (.Lpic\@ + (8 >> CONFIG_THUMB)), .Lpicoff\@
  174. .endm
  175. .macro movrel rd, val
  176. #if CONFIG_PIC
  177. ldpic \rd, \val
  178. #elif HAVE_ARMV6T2_EXTERNAL && !defined(__APPLE__)
  179. movw \rd, #:lower16:\val
  180. movt \rd, #:upper16:\val
  181. #else
  182. ldr \rd, =\val
  183. #endif
  184. .endm
  185. .macro movrelx rd, val, gp
  186. .ifc \rd,\gp
  187. .error "movrelx needs two distinct registers"
  188. .endif
  189. .ifc \rd\()_\gp,r12_
  190. .warning "movrelx rd=\rd without explicit set gp"
  191. .endif
  192. .ifc \rd\()_\gp,ip_
  193. .warning "movrelx rd=\rd without explicit set gp"
  194. .endif
  195. #if CONFIG_PIC && defined(__ELF__)
  196. .ifnb \gp
  197. .if .Lpic_gp
  198. .unreq gp
  199. .endif
  200. gp .req \gp
  201. ldpic gp, _GLOBAL_OFFSET_TABLE_
  202. .elseif !.Lpic_gp
  203. gp .req r12
  204. ldpic gp, _GLOBAL_OFFSET_TABLE_
  205. .endif
  206. .set .Lpic_gp, 1
  207. ldr \rd, .Lpicoff\@
  208. ldr \rd, [gp, \rd]
  209. def_pic \val(GOT), .Lpicoff\@
  210. #elif CONFIG_PIC && defined(__APPLE__)
  211. ldpic \rd, .Lpic\@, indir=1
  212. .non_lazy_symbol_pointer
  213. .Lpic\@:
  214. .indirect_symbol \val
  215. .word 0
  216. .text
  217. #else
  218. movrel \rd, \val
  219. #endif
  220. .endm
  221. .macro add_sh rd, rn, rm, sh:vararg
  222. A add \rd, \rn, \rm, \sh
  223. T mov \rm, \rm, \sh
  224. T add \rd, \rn, \rm
  225. .endm
  226. .macro ldr_pre rt, rn, rm:vararg
  227. A ldr \rt, [\rn, \rm]!
  228. T add \rn, \rn, \rm
  229. T ldr \rt, [\rn]
  230. .endm
  231. .macro ldr_dpre rt, rn, rm:vararg
  232. A ldr \rt, [\rn, -\rm]!
  233. T sub \rn, \rn, \rm
  234. T ldr \rt, [\rn]
  235. .endm
  236. .macro ldr_nreg rt, rn, rm:vararg
  237. A ldr \rt, [\rn, -\rm]
  238. T sub \rt, \rn, \rm
  239. T ldr \rt, [\rt]
  240. .endm
  241. .macro ldr_post rt, rn, rm:vararg
  242. A ldr \rt, [\rn], \rm
  243. T ldr \rt, [\rn]
  244. T add \rn, \rn, \rm
  245. .endm
  246. .macro ldrc_pre cc, rt, rn, rm:vararg
  247. A ldr\cc \rt, [\rn, \rm]!
  248. T itt \cc
  249. T add\cc \rn, \rn, \rm
  250. T ldr\cc \rt, [\rn]
  251. .endm
  252. .macro ldrd_reg rt, rt2, rn, rm
  253. A ldrd \rt, \rt2, [\rn, \rm]
  254. T add \rt, \rn, \rm
  255. T ldrd \rt, \rt2, [\rt]
  256. .endm
  257. .macro ldrd_post rt, rt2, rn, rm
  258. A ldrd \rt, \rt2, [\rn], \rm
  259. T ldrd \rt, \rt2, [\rn]
  260. T add \rn, \rn, \rm
  261. .endm
  262. .macro ldrh_pre rt, rn, rm
  263. A ldrh \rt, [\rn, \rm]!
  264. T add \rn, \rn, \rm
  265. T ldrh \rt, [\rn]
  266. .endm
  267. .macro ldrh_dpre rt, rn, rm
  268. A ldrh \rt, [\rn, -\rm]!
  269. T sub \rn, \rn, \rm
  270. T ldrh \rt, [\rn]
  271. .endm
  272. .macro ldrh_post rt, rn, rm
  273. A ldrh \rt, [\rn], \rm
  274. T ldrh \rt, [\rn]
  275. T add \rn, \rn, \rm
  276. .endm
  277. .macro ldrb_post rt, rn, rm
  278. A ldrb \rt, [\rn], \rm
  279. T ldrb \rt, [\rn]
  280. T add \rn, \rn, \rm
  281. .endm
  282. .macro str_post rt, rn, rm:vararg
  283. A str \rt, [\rn], \rm
  284. T str \rt, [\rn]
  285. T add \rn, \rn, \rm
  286. .endm
  287. .macro strb_post rt, rn, rm:vararg
  288. A strb \rt, [\rn], \rm
  289. T strb \rt, [\rn]
  290. T add \rn, \rn, \rm
  291. .endm
  292. .macro strd_post rt, rt2, rn, rm
  293. A strd \rt, \rt2, [\rn], \rm
  294. T strd \rt, \rt2, [\rn]
  295. T add \rn, \rn, \rm
  296. .endm
  297. .macro strh_pre rt, rn, rm
  298. A strh \rt, [\rn, \rm]!
  299. T add \rn, \rn, \rm
  300. T strh \rt, [\rn]
  301. .endm
  302. .macro strh_dpre rt, rn, rm
  303. A strh \rt, [\rn, -\rm]!
  304. T sub \rn, \rn, \rm
  305. T strh \rt, [\rn]
  306. .endm
  307. .macro strh_post rt, rn, rm
  308. A strh \rt, [\rn], \rm
  309. T strh \rt, [\rn]
  310. T add \rn, \rn, \rm
  311. .endm
  312. .macro strh_dpost rt, rn, rm
  313. A strh \rt, [\rn], -\rm
  314. T strh \rt, [\rn]
  315. T sub \rn, \rn, \rm
  316. .endm
  317. #if HAVE_VFP_ARGS
  318. ELF .eabi_attribute 28, 1
  319. # define VFP
  320. # define NOVFP @
  321. #else
  322. # define VFP @
  323. # define NOVFP
  324. #endif
  325. #define GLUE(a, b) a ## b
  326. #define JOIN(a, b) GLUE(a, b)
  327. #define X(s) JOIN(EXTERN_ASM, s)