mulsi3.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. ; Copyright (C) 2011-2022 Free Software Foundation, Inc.
  2. ; Contributed by Red Hat.
  3. ;
  4. ; This file is free software; you can redistribute it and/or modify it
  5. ; under the terms of the GNU General Public License as published by the
  6. ; Free Software Foundation; either version 3, or (at your option) any
  7. ; later version.
  8. ;
  9. ; This file is distributed in the hope that it will be useful, but
  10. ; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ; General Public License for more details.
  13. ;
  14. ; Under Section 7 of GPL version 3, you are granted additional
  15. ; permissions described in the GCC Runtime Library Exception, version
  16. ; 3.1, as published by the Free Software Foundation.
  17. ;
  18. ; You should have received a copy of the GNU General Public License and
  19. ; a copy of the GCC Runtime Library Exception along with this program;
  20. ; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  21. ; <http://www.gnu.org/licenses/>.
  22. ;; 32x32=32 multiply
  23. #include "vregs.h"
  24. ;----------------------------------------------------------------------
  25. ; Register use:
  26. ; RB0 RB1 RB2
  27. ; AX op2L res32L res32H
  28. ; BC op2H (resH) op1
  29. ; DE count (resL-tmp)
  30. ; HL [sp+4]
  31. ; Register use (G10):
  32. ;
  33. ; AX op2L
  34. ; BC op2H
  35. ; DE count
  36. ; HL [sp+4]
  37. ; r8/r9 res32L
  38. ; r10/r11 (resH)
  39. ; r12/r13 (resL-tmp)
  40. ; r16/r17 res32H
  41. ; r18/r19 op1
  42. START_FUNC ___mulsi3
  43. ;; A is at [sp+4]
  44. ;; B is at [sp+8]
  45. ;; result is in R8..R11
  46. #ifdef __RL78_G10__
  47. movw ax, r16
  48. push ax
  49. movw ax, r18
  50. push ax
  51. #else
  52. sel rb2
  53. push ax
  54. push bc
  55. sel rb0
  56. #endif
  57. clrw ax
  58. movw r8, ax
  59. movw r16, ax
  60. movw ax, [sp+14]
  61. cmpw ax, #0
  62. bz $1f
  63. cmpw ax, #0xffff
  64. bnz $2f
  65. movw ax, [sp+8]
  66. #ifdef __RL78_G10__
  67. push bc
  68. movw bc, r8
  69. xchw ax, bc
  70. subw ax, bc
  71. movw r8, ax
  72. movw ax, bc
  73. pop bc
  74. #else
  75. sel rb1
  76. subw ax, r_0
  77. sel rb0
  78. #endif
  79. br $1f
  80. 2:
  81. movw bc, ax
  82. movw ax, [sp+8]
  83. cmpw ax, #0
  84. skz
  85. call !.Lmul_hi
  86. 1:
  87. movw ax, [sp+10]
  88. cmpw ax, #0
  89. bz $1f
  90. cmpw ax, #0xffff
  91. bnz $2f
  92. movw ax, [sp+12]
  93. #ifdef __RL78_G10__
  94. push bc
  95. movw bc, r8
  96. xchw ax, bc
  97. subw ax, bc
  98. movw r8, ax
  99. movw ax, bc
  100. pop bc
  101. #else
  102. sel rb1
  103. subw ax, r_0
  104. sel rb0
  105. #endif
  106. br $1f
  107. 2:
  108. movw bc, ax
  109. movw ax, [sp+12]
  110. cmpw ax, #0
  111. skz
  112. call !.Lmul_hi
  113. 1:
  114. movw ax, r8
  115. movw r16, ax
  116. clrw ax
  117. movw r8, ax
  118. ;; now do R16:R8 += op1L * op2L
  119. ;; op1 is in AX.0 (needs to shrw)
  120. ;; op2 is in BC.2 and BC.1 (bc can shlw/rolcw)
  121. ;; res is in AX.2 and AX.1 (needs to addw)
  122. movw ax, [sp+8]
  123. movw r10, ax ; BC.1
  124. movw ax, [sp+12]
  125. cmpw ax, r10
  126. bc $.Lmul_hisi_top
  127. movw bc, r10
  128. movw r10, ax
  129. movw ax, bc
  130. .Lmul_hisi_top:
  131. movw bc, #0
  132. .Lmul_hisi_loop:
  133. shrw ax, 1
  134. #ifdef __RL78_G10__
  135. push ax
  136. bnc $.Lmul_hisi_no_add_g10
  137. movw ax, r8
  138. addw ax, r10
  139. movw r8, ax
  140. sknc
  141. incw r16
  142. movw ax, r16
  143. addw ax, r_2
  144. movw r16, ax
  145. .Lmul_hisi_no_add_g10:
  146. movw ax, r10
  147. shlw ax, 1
  148. movw r10, ax
  149. pop ax
  150. #else
  151. bnc $.Lmul_hisi_no_add
  152. sel rb1
  153. addw ax, bc
  154. sel rb2
  155. sknc
  156. incw ax
  157. addw ax, r_2
  158. .Lmul_hisi_no_add:
  159. sel rb1
  160. shlw bc, 1
  161. sel rb0
  162. #endif
  163. rolwc bc, 1
  164. cmpw ax, #0
  165. bz $.Lmul_hisi_done
  166. shrw ax, 1
  167. #ifdef __RL78_G10__
  168. push ax
  169. bnc $.Lmul_hisi_no_add2_g10
  170. movw ax, r8
  171. addw ax, r10
  172. movw r8, ax
  173. movw ax, r16
  174. sknc
  175. incw ax
  176. addw ax, r_2
  177. movw r16, ax
  178. .Lmul_hisi_no_add2_g10:
  179. movw ax, r10
  180. shlw ax, 1
  181. movw r10, ax
  182. pop ax
  183. #else
  184. bnc $.Lmul_hisi_no_add2
  185. sel rb1
  186. addw ax, bc
  187. sel rb2
  188. sknc
  189. incw ax
  190. addw ax, r_2
  191. .Lmul_hisi_no_add2:
  192. sel rb1
  193. shlw bc, 1
  194. sel rb0
  195. #endif
  196. rolwc bc, 1
  197. cmpw ax, #0
  198. bnz $.Lmul_hisi_loop
  199. .Lmul_hisi_done:
  200. movw ax, r16
  201. movw r10, ax
  202. #ifdef __RL78_G10__
  203. pop ax
  204. movw r18, ax
  205. pop ax
  206. movw r16, ax
  207. #else
  208. sel rb2
  209. pop bc
  210. pop ax
  211. sel rb0
  212. #endif
  213. ret
  214. END_FUNC ___mulsi3
  215. ;----------------------------------------------------------------------
  216. START_FUNC ___mulhi3
  217. movw r8, #0
  218. movw ax, [sp+6]
  219. movw bc, ax
  220. movw ax, [sp+4]
  221. ;; R8 += AX * BC
  222. .Lmul_hi:
  223. cmpw ax, bc
  224. skc
  225. xchw ax, bc
  226. br $.Lmul_hi_loop
  227. .Lmul_hi_top:
  228. #ifdef __RL78_G10__
  229. push ax
  230. movw ax, r8
  231. addw ax, r_2
  232. movw r8, ax
  233. pop ax
  234. #else
  235. sel rb1
  236. addw ax, r_2
  237. sel rb0
  238. #endif
  239. .Lmul_hi_no_add:
  240. shlw bc, 1
  241. .Lmul_hi_loop:
  242. shrw ax, 1
  243. bc $.Lmul_hi_top
  244. cmpw ax, #0
  245. bz $.Lmul_hi_done
  246. shlw bc, 1
  247. shrw ax, 1
  248. bc $.Lmul_hi_top
  249. cmpw ax, #0
  250. bnz $.Lmul_hi_no_add
  251. .Lmul_hi_done:
  252. ret
  253. END_FUNC ___mulhi3
  254. ;;; --------------------------------------
  255. #ifdef __RL78_G10__
  256. START_FUNC ___mulqi3
  257. mov a, [sp+4]
  258. mov r9, a
  259. mov a, [sp+6]
  260. mov r10, a
  261. mov a, #9
  262. mov r11, a
  263. clrb a
  264. mov r8, a
  265. .L2:
  266. cmp0 r10
  267. skz
  268. dec r11
  269. sknz
  270. ret
  271. mov a, r10
  272. and a, #1
  273. mov r12, a
  274. cmp0 r12
  275. sknz
  276. br !!.L3
  277. mov a, r9
  278. mov l, a
  279. mov a, r8
  280. add a, l
  281. mov r8, a
  282. .L3:
  283. mov a, r9
  284. add a, a
  285. mov r9, a
  286. mov a, r10
  287. shr a, 1
  288. mov r10, a
  289. br !!.L2
  290. END_FUNC ___mulqi3
  291. #endif