jsimd_mips_dspr2_asm.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * MIPS DSPr2 optimizations for libjpeg-turbo
  3. *
  4. * Copyright (C) 2013, MIPS Technologies, Inc., California.
  5. * All Rights Reserved.
  6. * Authors: Teodora Novkovic (teodora.novkovic@imgtec.com)
  7. * Darko Laus (darko.laus@imgtec.com)
  8. * This software is provided 'as-is', without any express or implied
  9. * warranty. In no event will the authors be held liable for any damages
  10. * arising from the use of this software.
  11. *
  12. * Permission is granted to anyone to use this software for any purpose,
  13. * including commercial applications, and to alter it and redistribute it
  14. * freely, subject to the following restrictions:
  15. *
  16. * 1. The origin of this software must not be misrepresented; you must not
  17. * claim that you wrote the original software. If you use this software
  18. * in a product, an acknowledgment in the product documentation would be
  19. * appreciated but is not required.
  20. * 2. Altered source versions must be plainly marked as such, and must not be
  21. * misrepresented as being the original software.
  22. * 3. This notice may not be removed or altered from any source distribution.
  23. */
  24. #define zero $0
  25. #define AT $1
  26. #define v0 $2
  27. #define v1 $3
  28. #define a0 $4
  29. #define a1 $5
  30. #define a2 $6
  31. #define a3 $7
  32. #define t0 $8
  33. #define t1 $9
  34. #define t2 $10
  35. #define t3 $11
  36. #define t4 $12
  37. #define t5 $13
  38. #define t6 $14
  39. #define t7 $15
  40. #define s0 $16
  41. #define s1 $17
  42. #define s2 $18
  43. #define s3 $19
  44. #define s4 $20
  45. #define s5 $21
  46. #define s6 $22
  47. #define s7 $23
  48. #define t8 $24
  49. #define t9 $25
  50. #define k0 $26
  51. #define k1 $27
  52. #define gp $28
  53. #define sp $29
  54. #define fp $30
  55. #define s8 $30
  56. #define ra $31
  57. #define f0 $f0
  58. #define f1 $f1
  59. #define f2 $f2
  60. #define f3 $f3
  61. #define f4 $f4
  62. #define f5 $f5
  63. #define f6 $f6
  64. #define f7 $f7
  65. #define f8 $f8
  66. #define f9 $f9
  67. #define f10 $f10
  68. #define f11 $f11
  69. #define f12 $f12
  70. #define f13 $f13
  71. #define f14 $f14
  72. #define f15 $f15
  73. #define f16 $f16
  74. #define f17 $f17
  75. #define f18 $f18
  76. #define f19 $f19
  77. #define f20 $f20
  78. #define f21 $f21
  79. #define f22 $f22
  80. #define f23 $f23
  81. #define f24 $f24
  82. #define f25 $f25
  83. #define f26 $f26
  84. #define f27 $f27
  85. #define f28 $f28
  86. #define f29 $f29
  87. #define f30 $f30
  88. #define f31 $f31
  89. /*
  90. * LEAF_MIPS32R2 - declare leaf routine for MIPS32r2
  91. */
  92. #define LEAF_MIPS32R2(symbol) \
  93. .globl symbol; \
  94. .align 2; \
  95. .type symbol, @function; \
  96. .ent symbol, 0; \
  97. symbol: .frame sp, 0, ra; \
  98. .set push; \
  99. .set arch=mips32r2; \
  100. .set noreorder; \
  101. .set noat;
  102. /*
  103. * LEAF_MIPS_DSPR2 - declare leaf routine for MIPS DSPr2
  104. */
  105. #define LEAF_MIPS_DSPR2(symbol) \
  106. LEAF_MIPS32R2(symbol) \
  107. .set dspr2;
  108. /*
  109. * END - mark end of function
  110. */
  111. #define END(function) \
  112. .set pop; \
  113. .end function; \
  114. .size function,.-function
  115. /*
  116. * Checks if stack offset is big enough for storing/restoring regs_num
  117. * number of register to/from stack. Stack offset must be greater than
  118. * or equal to the number of bytes needed for storing registers (regs_num*4).
  119. * Since MIPS ABI allows usage of first 16 bytes of stack frame (this is
  120. * preserved for input arguments of the functions, already stored in a0-a3),
  121. * stack size can be further optimized by utilizing this space.
  122. */
  123. .macro CHECK_STACK_OFFSET regs_num, stack_offset
  124. .if \stack_offset < \regs_num * 4 - 16
  125. .error "Stack offset too small."
  126. .endif
  127. .endm
  128. /*
  129. * Saves set of registers on stack. Maximum number of registers that
  130. * can be saved on stack is limitted to 14 (a0-a3, v0-v1 and s0-s7).
  131. * Stack offset is number of bytes that are added to stack pointer (sp)
  132. * before registers are pushed in order to provide enough space on stack
  133. * (offset must be multiple of 4, and must be big enough, as described by
  134. * CHECK_STACK_OFFSET macro). This macro is intended to be used in
  135. * combination with RESTORE_REGS_FROM_STACK macro. Example:
  136. * SAVE_REGS_ON_STACK 4, v0, v1, s0, s1
  137. * RESTORE_REGS_FROM_STACK 4, v0, v1, s0, s1
  138. */
  139. .macro SAVE_REGS_ON_STACK stack_offset = 0, r1, \
  140. r2 = 0, r3 = 0, r4 = 0, \
  141. r5 = 0, r6 = 0, r7 = 0, \
  142. r8 = 0, r9 = 0, r10 = 0, \
  143. r11 = 0, r12 = 0, r13 = 0, \
  144. r14 = 0
  145. .if (\stack_offset < 0) || (\stack_offset - (\stack_offset / 4) * 4)
  146. .error "Stack offset must be pozitive and multiple of 4."
  147. .endif
  148. .if \stack_offset != 0
  149. addiu sp, sp, -\stack_offset
  150. .endif
  151. sw \r1, 0(sp)
  152. .if \r2 != 0
  153. sw \r2, 4(sp)
  154. .endif
  155. .if \r3 != 0
  156. sw \r3, 8(sp)
  157. .endif
  158. .if \r4 != 0
  159. sw \r4, 12(sp)
  160. .endif
  161. .if \r5 != 0
  162. CHECK_STACK_OFFSET 5, \stack_offset
  163. sw \r5, 16(sp)
  164. .endif
  165. .if \r6 != 0
  166. CHECK_STACK_OFFSET 6, \stack_offset
  167. sw \r6, 20(sp)
  168. .endif
  169. .if \r7 != 0
  170. CHECK_STACK_OFFSET 7, \stack_offset
  171. sw \r7, 24(sp)
  172. .endif
  173. .if \r8 != 0
  174. CHECK_STACK_OFFSET 8, \stack_offset
  175. sw \r8, 28(sp)
  176. .endif
  177. .if \r9 != 0
  178. CHECK_STACK_OFFSET 9, \stack_offset
  179. sw \r9, 32(sp)
  180. .endif
  181. .if \r10 != 0
  182. CHECK_STACK_OFFSET 10, \stack_offset
  183. sw \r10, 36(sp)
  184. .endif
  185. .if \r11 != 0
  186. CHECK_STACK_OFFSET 11, \stack_offset
  187. sw \r11, 40(sp)
  188. .endif
  189. .if \r12 != 0
  190. CHECK_STACK_OFFSET 12, \stack_offset
  191. sw \r12, 44(sp)
  192. .endif
  193. .if \r13 != 0
  194. CHECK_STACK_OFFSET 13, \stack_offset
  195. sw \r13, 48(sp)
  196. .endif
  197. .if \r14 != 0
  198. CHECK_STACK_OFFSET 14, \stack_offset
  199. sw \r14, 52(sp)
  200. .endif
  201. .endm
  202. /*
  203. * Restores set of registers from stack. Maximum number of registers that
  204. * can be restored from stack is limitted to 14 (a0-a3, v0-v1 and s0-s7).
  205. * Stack offset is number of bytes that are added to stack pointer (sp)
  206. * after registers are restored (offset must be multiple of 4, and must
  207. * be big enough, as described by CHECK_STACK_OFFSET macro). This macro is
  208. * intended to be used in combination with RESTORE_REGS_FROM_STACK macro.
  209. * Example:
  210. * SAVE_REGS_ON_STACK 4, v0, v1, s0, s1
  211. * RESTORE_REGS_FROM_STACK 4, v0, v1, s0, s1
  212. */
  213. .macro RESTORE_REGS_FROM_STACK stack_offset = 0, r1, \
  214. r2 = 0, r3 = 0, r4 = 0, \
  215. r5 = 0, r6 = 0, r7 = 0, \
  216. r8 = 0, r9 = 0, r10 = 0, \
  217. r11 = 0, r12 = 0, r13 = 0, \
  218. r14 = 0
  219. .if (\stack_offset < 0) || (\stack_offset - (\stack_offset/4)*4)
  220. .error "Stack offset must be pozitive and multiple of 4."
  221. .endif
  222. lw \r1, 0(sp)
  223. .if \r2 != 0
  224. lw \r2, 4(sp)
  225. .endif
  226. .if \r3 != 0
  227. lw \r3, 8(sp)
  228. .endif
  229. .if \r4 != 0
  230. lw \r4, 12(sp)
  231. .endif
  232. .if \r5 != 0
  233. CHECK_STACK_OFFSET 5, \stack_offset
  234. lw \r5, 16(sp)
  235. .endif
  236. .if \r6 != 0
  237. CHECK_STACK_OFFSET 6, \stack_offset
  238. lw \r6, 20(sp)
  239. .endif
  240. .if \r7 != 0
  241. CHECK_STACK_OFFSET 7, \stack_offset
  242. lw \r7, 24(sp)
  243. .endif
  244. .if \r8 != 0
  245. CHECK_STACK_OFFSET 8, \stack_offset
  246. lw \r8, 28(sp)
  247. .endif
  248. .if \r9 != 0
  249. CHECK_STACK_OFFSET 9, \stack_offset
  250. lw \r9, 32(sp)
  251. .endif
  252. .if \r10 != 0
  253. CHECK_STACK_OFFSET 10, \stack_offset
  254. lw \r10, 36(sp)
  255. .endif
  256. .if \r11 != 0
  257. CHECK_STACK_OFFSET 11, \stack_offset
  258. lw \r11, 40(sp)
  259. .endif
  260. .if \r12 != 0
  261. CHECK_STACK_OFFSET 12, \stack_offset
  262. lw \r12, 44(sp)
  263. .endif
  264. .if \r13 != 0
  265. CHECK_STACK_OFFSET 13, \stack_offset
  266. lw \r13, 48(sp)
  267. .endif
  268. .if \r14 != 0
  269. CHECK_STACK_OFFSET 14, \stack_offset
  270. lw \r14, 52(sp)
  271. .endif
  272. .if \stack_offset != 0
  273. addiu sp, sp, \stack_offset
  274. .endif
  275. .endm