asmxtensa.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2016 Damien P. George
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef MICROPY_INCLUDED_PY_ASMXTENSA_H
  27. #define MICROPY_INCLUDED_PY_ASMXTENSA_H
  28. #include "py/misc.h"
  29. #include "py/asmbase.h"
  30. // calling conventions:
  31. // up to 6 args in a2-a7
  32. // return value in a2
  33. // PC stored in a0
  34. // stack pointer is a1, stack full descending, is aligned to 16 bytes
  35. // callee save: a1, a12, a13, a14, a15
  36. // caller save: a3
  37. // With windowed registers, size 8:
  38. // - a0: return PC
  39. // - a1: stack pointer, full descending, aligned to 16 bytes
  40. // - a2-a7: incoming args, and essentially callee save
  41. // - a2: return value
  42. // - a8-a15: caller save temporaries
  43. // - a10-a15: input args to called function
  44. // - a10: return value of called function
  45. // note: a0-a7 are saved automatically via window shift of called function
  46. #define ASM_XTENSA_REG_A0 (0)
  47. #define ASM_XTENSA_REG_A1 (1)
  48. #define ASM_XTENSA_REG_A2 (2)
  49. #define ASM_XTENSA_REG_A3 (3)
  50. #define ASM_XTENSA_REG_A4 (4)
  51. #define ASM_XTENSA_REG_A5 (5)
  52. #define ASM_XTENSA_REG_A6 (6)
  53. #define ASM_XTENSA_REG_A7 (7)
  54. #define ASM_XTENSA_REG_A8 (8)
  55. #define ASM_XTENSA_REG_A9 (9)
  56. #define ASM_XTENSA_REG_A10 (10)
  57. #define ASM_XTENSA_REG_A11 (11)
  58. #define ASM_XTENSA_REG_A12 (12)
  59. #define ASM_XTENSA_REG_A13 (13)
  60. #define ASM_XTENSA_REG_A14 (14)
  61. #define ASM_XTENSA_REG_A15 (15)
  62. // for bccz
  63. #define ASM_XTENSA_CCZ_EQ (0)
  64. #define ASM_XTENSA_CCZ_NE (1)
  65. // for bcc and setcc
  66. #define ASM_XTENSA_CC_NONE (0)
  67. #define ASM_XTENSA_CC_EQ (1)
  68. #define ASM_XTENSA_CC_LT (2)
  69. #define ASM_XTENSA_CC_LTU (3)
  70. #define ASM_XTENSA_CC_ALL (4)
  71. #define ASM_XTENSA_CC_BC (5)
  72. #define ASM_XTENSA_CC_ANY (8)
  73. #define ASM_XTENSA_CC_NE (9)
  74. #define ASM_XTENSA_CC_GE (10)
  75. #define ASM_XTENSA_CC_GEU (11)
  76. #define ASM_XTENSA_CC_NALL (12)
  77. #define ASM_XTENSA_CC_BS (13)
  78. // macros for encoding instructions (little endian versions)
  79. #define ASM_XTENSA_ENCODE_RRR(op0, op1, op2, r, s, t) \
  80. ((((uint32_t)op2) << 20) | (((uint32_t)op1) << 16) | ((r) << 12) | ((s) << 8) | ((t) << 4) | (op0))
  81. #define ASM_XTENSA_ENCODE_RRI4(op0, op1, r, s, t, imm4) \
  82. (((imm4) << 20) | ((op1) << 16) | ((r) << 12) | ((s) << 8) | ((t) << 4) | (op0))
  83. #define ASM_XTENSA_ENCODE_RRI8(op0, r, s, t, imm8) \
  84. ((((uint32_t)imm8) << 16) | ((r) << 12) | ((s) << 8) | ((t) << 4) | (op0))
  85. #define ASM_XTENSA_ENCODE_RI16(op0, t, imm16) \
  86. (((imm16) << 8) | ((t) << 4) | (op0))
  87. #define ASM_XTENSA_ENCODE_RSR(op0, op1, op2, rs, t) \
  88. (((op2) << 20) | ((op1) << 16) | ((rs) << 8) | ((t) << 4) | (op0))
  89. #define ASM_XTENSA_ENCODE_CALL(op0, n, offset) \
  90. (((offset) << 6) | ((n) << 4) | (op0))
  91. #define ASM_XTENSA_ENCODE_CALLX(op0, op1, op2, r, s, m, n) \
  92. ((((uint32_t)op2) << 20) | (((uint32_t)op1) << 16) | ((r) << 12) | ((s) << 8) | ((m) << 6) | ((n) << 4) | (op0))
  93. #define ASM_XTENSA_ENCODE_BRI8(op0, r, s, m, n, imm8) \
  94. (((imm8) << 16) | ((r) << 12) | ((s) << 8) | ((m) << 6) | ((n) << 4) | (op0))
  95. #define ASM_XTENSA_ENCODE_BRI12(op0, s, m, n, imm12) \
  96. (((imm12) << 12) | ((s) << 8) | ((m) << 6) | ((n) << 4) | (op0))
  97. #define ASM_XTENSA_ENCODE_RRRN(op0, r, s, t) \
  98. (((r) << 12) | ((s) << 8) | ((t) << 4) | (op0))
  99. #define ASM_XTENSA_ENCODE_RI7(op0, s, imm7) \
  100. ((((imm7) & 0xf) << 12) | ((s) << 8) | ((imm7) & 0x70) | (op0))
  101. // Number of registers saved on the stack upon entry to function
  102. #define ASM_XTENSA_NUM_REGS_SAVED (5)
  103. #define ASM_XTENSA_NUM_REGS_SAVED_WIN (1)
  104. typedef struct _asm_xtensa_t {
  105. mp_asm_base_t base;
  106. uint32_t cur_const;
  107. uint32_t num_const;
  108. uint32_t *const_table;
  109. uint32_t stack_adjust;
  110. } asm_xtensa_t;
  111. void asm_xtensa_end_pass(asm_xtensa_t *as);
  112. void asm_xtensa_entry(asm_xtensa_t *as, int num_locals);
  113. void asm_xtensa_exit(asm_xtensa_t *as);
  114. void asm_xtensa_entry_win(asm_xtensa_t *as, int num_locals);
  115. void asm_xtensa_exit_win(asm_xtensa_t *as);
  116. void asm_xtensa_op16(asm_xtensa_t *as, uint16_t op);
  117. void asm_xtensa_op24(asm_xtensa_t *as, uint32_t op);
  118. // raw instructions
  119. static inline void asm_xtensa_op_entry(asm_xtensa_t *as, uint reg_src, int32_t num_bytes) {
  120. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_BRI12(6, reg_src, 0, 3, (num_bytes / 8) & 0xfff));
  121. }
  122. static inline void asm_xtensa_op_add_n(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {
  123. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RRRN(10, reg_dest, reg_src_a, reg_src_b));
  124. }
  125. static inline void asm_xtensa_op_addi(asm_xtensa_t *as, uint reg_dest, uint reg_src, int imm8) {
  126. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 12, reg_src, reg_dest, imm8 & 0xff));
  127. }
  128. static inline void asm_xtensa_op_and(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {
  129. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 1, reg_dest, reg_src_a, reg_src_b));
  130. }
  131. static inline void asm_xtensa_op_bcc(asm_xtensa_t *as, uint cond, uint reg_src1, uint reg_src2, int32_t rel8) {
  132. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(7, cond, reg_src1, reg_src2, rel8 & 0xff));
  133. }
  134. static inline void asm_xtensa_op_bccz(asm_xtensa_t *as, uint cond, uint reg_src, int32_t rel12) {
  135. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_BRI12(6, reg_src, cond, 1, rel12 & 0xfff));
  136. }
  137. static inline void asm_xtensa_op_call0(asm_xtensa_t *as, int32_t rel18) {
  138. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_CALL(5, 0, rel18 & 0x3ffff));
  139. }
  140. static inline void asm_xtensa_op_callx0(asm_xtensa_t *as, uint reg) {
  141. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_CALLX(0, 0, 0, 0, reg, 3, 0));
  142. }
  143. static inline void asm_xtensa_op_callx8(asm_xtensa_t *as, uint reg) {
  144. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_CALLX(0, 0, 0, 0, reg, 3, 2));
  145. }
  146. static inline void asm_xtensa_op_j(asm_xtensa_t *as, int32_t rel18) {
  147. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_CALL(6, 0, rel18 & 0x3ffff));
  148. }
  149. static inline void asm_xtensa_op_jx(asm_xtensa_t *as, uint reg) {
  150. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_CALLX(0, 0, 0, 0, reg, 2, 2));
  151. }
  152. static inline void asm_xtensa_op_l8ui(asm_xtensa_t *as, uint reg_dest, uint reg_base, uint byte_offset) {
  153. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 0, reg_base, reg_dest, byte_offset & 0xff));
  154. }
  155. static inline void asm_xtensa_op_l16ui(asm_xtensa_t *as, uint reg_dest, uint reg_base, uint half_word_offset) {
  156. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 1, reg_base, reg_dest, half_word_offset & 0xff));
  157. }
  158. static inline void asm_xtensa_op_l32i(asm_xtensa_t *as, uint reg_dest, uint reg_base, uint word_offset) {
  159. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 2, reg_base, reg_dest, word_offset & 0xff));
  160. }
  161. static inline void asm_xtensa_op_l32i_n(asm_xtensa_t *as, uint reg_dest, uint reg_base, uint word_offset) {
  162. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RRRN(8, word_offset & 0xf, reg_base, reg_dest));
  163. }
  164. static inline void asm_xtensa_op_l32r(asm_xtensa_t *as, uint reg_dest, uint32_t op_off, uint32_t dest_off) {
  165. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RI16(1, reg_dest, ((dest_off - ((op_off + 3) & ~3)) >> 2) & 0xffff));
  166. }
  167. static inline void asm_xtensa_op_mov_n(asm_xtensa_t *as, uint reg_dest, uint reg_src) {
  168. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RRRN(13, 0, reg_src, reg_dest));
  169. }
  170. static inline void asm_xtensa_op_movi(asm_xtensa_t *as, uint reg_dest, int32_t imm12) {
  171. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 10, (imm12 >> 8) & 0xf, reg_dest, imm12 & 0xff));
  172. }
  173. // Argument must be in the range (-32 .. 95) inclusive.
  174. static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm7) {
  175. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm7));
  176. }
  177. static inline void asm_xtensa_op_mull(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {
  178. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 2, 8, reg_dest, reg_src_a, reg_src_b));
  179. }
  180. static inline void asm_xtensa_op_neg(asm_xtensa_t *as, uint reg_dest, uint reg_src) {
  181. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 6, reg_dest, 0, reg_src));
  182. }
  183. static inline void asm_xtensa_op_or(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {
  184. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 2, reg_dest, reg_src_a, reg_src_b));
  185. }
  186. static inline void asm_xtensa_op_ret_n(asm_xtensa_t *as) {
  187. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RRRN(13, 15, 0, 0));
  188. }
  189. static inline void asm_xtensa_op_retw_n(asm_xtensa_t *as) {
  190. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RRRN(13, 15, 0, 1));
  191. }
  192. static inline void asm_xtensa_op_s8i(asm_xtensa_t *as, uint reg_src, uint reg_base, uint byte_offset) {
  193. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 4, reg_base, reg_src, byte_offset & 0xff));
  194. }
  195. static inline void asm_xtensa_op_s16i(asm_xtensa_t *as, uint reg_src, uint reg_base, uint half_word_offset) {
  196. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 5, reg_base, reg_src, half_word_offset & 0xff));
  197. }
  198. static inline void asm_xtensa_op_s32i(asm_xtensa_t *as, uint reg_src, uint reg_base, uint word_offset) {
  199. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 6, reg_base, reg_src, word_offset & 0xff));
  200. }
  201. static inline void asm_xtensa_op_s32i_n(asm_xtensa_t *as, uint reg_src, uint reg_base, uint word_offset) {
  202. asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RRRN(9, word_offset & 0xf, reg_base, reg_src));
  203. }
  204. static inline void asm_xtensa_op_sll(asm_xtensa_t *as, uint reg_dest, uint reg_src) {
  205. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 1, 10, reg_dest, reg_src, 0));
  206. }
  207. static inline void asm_xtensa_op_srl(asm_xtensa_t *as, uint reg_dest, uint reg_src) {
  208. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 1, 9, reg_dest, 0, reg_src));
  209. }
  210. static inline void asm_xtensa_op_sra(asm_xtensa_t *as, uint reg_dest, uint reg_src) {
  211. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 1, 11, reg_dest, 0, reg_src));
  212. }
  213. static inline void asm_xtensa_op_ssl(asm_xtensa_t *as, uint reg_src) {
  214. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 4, 1, reg_src, 0));
  215. }
  216. static inline void asm_xtensa_op_ssr(asm_xtensa_t *as, uint reg_src) {
  217. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 4, 0, reg_src, 0));
  218. }
  219. static inline void asm_xtensa_op_sub(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {
  220. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 12, reg_dest, reg_src_a, reg_src_b));
  221. }
  222. static inline void asm_xtensa_op_xor(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) {
  223. asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 3, reg_dest, reg_src_a, reg_src_b));
  224. }
  225. // convenience functions
  226. void asm_xtensa_j_label(asm_xtensa_t *as, uint label);
  227. void asm_xtensa_bccz_reg_label(asm_xtensa_t *as, uint cond, uint reg, uint label);
  228. void asm_xtensa_bcc_reg_reg_label(asm_xtensa_t *as, uint cond, uint reg1, uint reg2, uint label);
  229. void asm_xtensa_setcc_reg_reg_reg(asm_xtensa_t *as, uint cond, uint reg_dest, uint reg_src1, uint reg_src2);
  230. size_t asm_xtensa_mov_reg_i32(asm_xtensa_t *as, uint reg_dest, uint32_t i32);
  231. void asm_xtensa_mov_reg_i32_optimised(asm_xtensa_t *as, uint reg_dest, uint32_t i32);
  232. void asm_xtensa_mov_local_reg(asm_xtensa_t *as, int local_num, uint reg_src);
  233. void asm_xtensa_mov_reg_local(asm_xtensa_t *as, uint reg_dest, int local_num);
  234. void asm_xtensa_mov_reg_local_addr(asm_xtensa_t *as, uint reg_dest, int local_num);
  235. void asm_xtensa_mov_reg_pcrel(asm_xtensa_t *as, uint reg_dest, uint label);
  236. void asm_xtensa_l32i_optimised(asm_xtensa_t *as, uint reg_dest, uint reg_base, uint word_offset);
  237. void asm_xtensa_s32i_optimised(asm_xtensa_t *as, uint reg_src, uint reg_base, uint word_offset);
  238. void asm_xtensa_call_ind(asm_xtensa_t *as, uint idx);
  239. void asm_xtensa_call_ind_win(asm_xtensa_t *as, uint idx);
  240. // Holds a pointer to mp_fun_table
  241. #define ASM_XTENSA_REG_FUN_TABLE ASM_XTENSA_REG_A15
  242. #define ASM_XTENSA_REG_FUN_TABLE_WIN ASM_XTENSA_REG_A7
  243. #if GENERIC_ASM_API
  244. // The following macros provide a (mostly) arch-independent API to
  245. // generate native code, and are used by the native emitter.
  246. #define ASM_WORD_SIZE (4)
  247. #if !GENERIC_ASM_API_WIN
  248. // Configuration for non-windowed calls
  249. #define REG_RET ASM_XTENSA_REG_A2
  250. #define REG_ARG_1 ASM_XTENSA_REG_A2
  251. #define REG_ARG_2 ASM_XTENSA_REG_A3
  252. #define REG_ARG_3 ASM_XTENSA_REG_A4
  253. #define REG_ARG_4 ASM_XTENSA_REG_A5
  254. #define REG_ARG_5 ASM_XTENSA_REG_A6
  255. #define REG_TEMP0 ASM_XTENSA_REG_A2
  256. #define REG_TEMP1 ASM_XTENSA_REG_A3
  257. #define REG_TEMP2 ASM_XTENSA_REG_A4
  258. #define REG_LOCAL_1 ASM_XTENSA_REG_A12
  259. #define REG_LOCAL_2 ASM_XTENSA_REG_A13
  260. #define REG_LOCAL_3 ASM_XTENSA_REG_A14
  261. #define REG_LOCAL_NUM (3)
  262. #define ASM_NUM_REGS_SAVED ASM_XTENSA_NUM_REGS_SAVED
  263. #define REG_FUN_TABLE ASM_XTENSA_REG_FUN_TABLE
  264. #define ASM_ENTRY(as, nlocal) asm_xtensa_entry((as), (nlocal))
  265. #define ASM_EXIT(as) asm_xtensa_exit((as))
  266. #define ASM_CALL_IND(as, idx) asm_xtensa_call_ind((as), (idx))
  267. #else
  268. // Configuration for windowed calls with window size 8
  269. #define REG_PARENT_RET ASM_XTENSA_REG_A2
  270. #define REG_PARENT_ARG_1 ASM_XTENSA_REG_A2
  271. #define REG_PARENT_ARG_2 ASM_XTENSA_REG_A3
  272. #define REG_PARENT_ARG_3 ASM_XTENSA_REG_A4
  273. #define REG_PARENT_ARG_4 ASM_XTENSA_REG_A5
  274. #define REG_RET ASM_XTENSA_REG_A10
  275. #define REG_ARG_1 ASM_XTENSA_REG_A10
  276. #define REG_ARG_2 ASM_XTENSA_REG_A11
  277. #define REG_ARG_3 ASM_XTENSA_REG_A12
  278. #define REG_ARG_4 ASM_XTENSA_REG_A13
  279. #define REG_TEMP0 ASM_XTENSA_REG_A10
  280. #define REG_TEMP1 ASM_XTENSA_REG_A11
  281. #define REG_TEMP2 ASM_XTENSA_REG_A12
  282. #define REG_LOCAL_1 ASM_XTENSA_REG_A4
  283. #define REG_LOCAL_2 ASM_XTENSA_REG_A5
  284. #define REG_LOCAL_3 ASM_XTENSA_REG_A6
  285. #define REG_LOCAL_NUM (3)
  286. #define ASM_NUM_REGS_SAVED ASM_XTENSA_NUM_REGS_SAVED_WIN
  287. #define REG_FUN_TABLE ASM_XTENSA_REG_FUN_TABLE_WIN
  288. #define ASM_ENTRY(as, nlocal) asm_xtensa_entry_win((as), (nlocal))
  289. #define ASM_EXIT(as) asm_xtensa_exit_win((as))
  290. #define ASM_CALL_IND(as, idx) asm_xtensa_call_ind_win((as), (idx))
  291. #endif
  292. #define ASM_T asm_xtensa_t
  293. #define ASM_END_PASS asm_xtensa_end_pass
  294. #define ASM_JUMP asm_xtensa_j_label
  295. #define ASM_JUMP_IF_REG_ZERO(as, reg, label, bool_test) \
  296. asm_xtensa_bccz_reg_label(as, ASM_XTENSA_CCZ_EQ, reg, label)
  297. #define ASM_JUMP_IF_REG_NONZERO(as, reg, label, bool_test) \
  298. asm_xtensa_bccz_reg_label(as, ASM_XTENSA_CCZ_NE, reg, label)
  299. #define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \
  300. asm_xtensa_bcc_reg_reg_label(as, ASM_XTENSA_CC_EQ, reg1, reg2, label)
  301. #define ASM_JUMP_REG(as, reg) asm_xtensa_op_jx((as), (reg))
  302. #define ASM_MOV_LOCAL_REG(as, local_num, reg_src) asm_xtensa_mov_local_reg((as), ASM_NUM_REGS_SAVED + (local_num), (reg_src))
  303. #define ASM_MOV_REG_IMM(as, reg_dest, imm) asm_xtensa_mov_reg_i32_optimised((as), (reg_dest), (imm))
  304. #define ASM_MOV_REG_LOCAL(as, reg_dest, local_num) asm_xtensa_mov_reg_local((as), (reg_dest), ASM_NUM_REGS_SAVED + (local_num))
  305. #define ASM_MOV_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_mov_n((as), (reg_dest), (reg_src))
  306. #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_xtensa_mov_reg_local_addr((as), (reg_dest), ASM_NUM_REGS_SAVED + (local_num))
  307. #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_xtensa_mov_reg_pcrel((as), (reg_dest), (label))
  308. #define ASM_NEG_REG(as, reg_dest) asm_xtensa_op_neg((as), (reg_dest), (reg_dest))
  309. #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) \
  310. do { \
  311. asm_xtensa_op_ssl((as), (reg_shift)); \
  312. asm_xtensa_op_sll((as), (reg_dest), (reg_dest)); \
  313. } while (0)
  314. #define ASM_LSR_REG_REG(as, reg_dest, reg_shift) \
  315. do { \
  316. asm_xtensa_op_ssr((as), (reg_shift)); \
  317. asm_xtensa_op_srl((as), (reg_dest), (reg_dest)); \
  318. } while (0)
  319. #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) \
  320. do { \
  321. asm_xtensa_op_ssr((as), (reg_shift)); \
  322. asm_xtensa_op_sra((as), (reg_dest), (reg_dest)); \
  323. } while (0)
  324. #define ASM_OR_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_or((as), (reg_dest), (reg_dest), (reg_src))
  325. #define ASM_XOR_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_xor((as), (reg_dest), (reg_dest), (reg_src))
  326. #define ASM_AND_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_and((as), (reg_dest), (reg_dest), (reg_src))
  327. #define ASM_ADD_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_add_n((as), (reg_dest), (reg_dest), (reg_src))
  328. #define ASM_SUB_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_sub((as), (reg_dest), (reg_dest), (reg_src))
  329. #define ASM_MUL_REG_REG(as, reg_dest, reg_src) asm_xtensa_op_mull((as), (reg_dest), (reg_dest), (reg_src))
  330. #define ASM_LOAD_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_xtensa_l32i_optimised((as), (reg_dest), (reg_base), (word_offset))
  331. #define ASM_LOAD8_REG_REG(as, reg_dest, reg_base) asm_xtensa_op_l8ui((as), (reg_dest), (reg_base), 0)
  332. #define ASM_LOAD16_REG_REG(as, reg_dest, reg_base) asm_xtensa_op_l16ui((as), (reg_dest), (reg_base), 0)
  333. #define ASM_LOAD16_REG_REG_OFFSET(as, reg_dest, reg_base, uint16_offset) asm_xtensa_op_l16ui((as), (reg_dest), (reg_base), (uint16_offset))
  334. #define ASM_LOAD32_REG_REG(as, reg_dest, reg_base) asm_xtensa_op_l32i_n((as), (reg_dest), (reg_base), 0)
  335. #define ASM_STORE_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_xtensa_s32i_optimised((as), (reg_dest), (reg_base), (word_offset))
  336. #define ASM_STORE8_REG_REG(as, reg_src, reg_base) asm_xtensa_op_s8i((as), (reg_src), (reg_base), 0)
  337. #define ASM_STORE16_REG_REG(as, reg_src, reg_base) asm_xtensa_op_s16i((as), (reg_src), (reg_base), 0)
  338. #define ASM_STORE32_REG_REG(as, reg_src, reg_base) asm_xtensa_op_s32i_n((as), (reg_src), (reg_base), 0)
  339. #endif // GENERIC_ASM_API
  340. #endif // MICROPY_INCLUDED_PY_ASMXTENSA_H