div.S 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /* Tests the divide instructions.
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. # mach: or1k
  14. # output: report(0x0000000c);\n
  15. # output: report(0x00000003);\n
  16. # output: report(0x00000004);\n
  17. # output: report(0x00000000);\n
  18. # output: report(0x00000000);\n
  19. # output: report(0x00000000);\n
  20. # output: \n
  21. # output: report(0x0000000b);\n
  22. # output: report(0x00000003);\n
  23. # output: report(0x00000003);\n
  24. # output: report(0x00000000);\n
  25. # output: report(0x00000000);\n
  26. # output: report(0x00000000);\n
  27. # output: \n
  28. # output: report(0xfffffff4);\n
  29. # output: report(0xfffffffd);\n
  30. # output: report(0x00000004);\n
  31. # output: report(0x00000000);\n
  32. # output: report(0x00000000);\n
  33. # output: report(0x00000000);\n
  34. # output: \n
  35. # output: report(0xfffffff5);\n
  36. # output: report(0xfffffffd);\n
  37. # output: report(0x00000003);\n
  38. # output: report(0x00000000);\n
  39. # output: report(0x00000000);\n
  40. # output: report(0x00000000);\n
  41. # output: \n
  42. # output: report(0xfffffff4);\n
  43. # output: report(0x00000003);\n
  44. # output: report(0xfffffffc);\n
  45. # output: report(0x00000000);\n
  46. # output: report(0x00000000);\n
  47. # output: report(0x00000000);\n
  48. # output: \n
  49. # output: report(0xfffffff5);\n
  50. # output: report(0x00000003);\n
  51. # output: report(0xfffffffd);\n
  52. # output: report(0x00000000);\n
  53. # output: report(0x00000000);\n
  54. # output: report(0x00000000);\n
  55. # output: \n
  56. # output: report(0x0000000c);\n
  57. # output: report(0xfffffffd);\n
  58. # output: report(0xfffffffc);\n
  59. # output: report(0x00000000);\n
  60. # output: report(0x00000000);\n
  61. # output: report(0x00000000);\n
  62. # output: \n
  63. # output: report(0x0000000b);\n
  64. # output: report(0xfffffffd);\n
  65. # output: report(0xfffffffd);\n
  66. # output: report(0x00000000);\n
  67. # output: report(0x00000000);\n
  68. # output: report(0x00000000);\n
  69. # output: \n
  70. # output: report(0x0000000c);\n
  71. # output: report(0x00000000);\n
  72. # output: report(0xfffffffd);\n
  73. # output: report(0x00000000);\n
  74. # output: report(0x00000001);\n
  75. # output: report(0x00000000);\n
  76. # output: \n
  77. # output: report(0xfffffff4);\n
  78. # output: report(0x00000000);\n
  79. # output: report(0xfffffffd);\n
  80. # output: report(0x00000000);\n
  81. # output: report(0x00000001);\n
  82. # output: report(0x00000000);\n
  83. # output: \n
  84. # output: report(0x0000000c);\n
  85. # output: report(0x00000000);\n
  86. # output: report(0xfffffffd);\n
  87. # output: report(0x00000000);\n
  88. # output: report(0x00000001);\n
  89. # output: report(0x00000001);\n
  90. # output: \n
  91. # output: report(0xfffffff4);\n
  92. # output: report(0x00000000);\n
  93. # output: report(0xfffffffd);\n
  94. # output: report(0x00000000);\n
  95. # output: report(0x00000001);\n
  96. # output: report(0x00000001);\n
  97. # output: \n
  98. # output: report(0x0000000c);\n
  99. # output: report(0x00000003);\n
  100. # output: report(0x00000004);\n
  101. # output: report(0x00000000);\n
  102. # output: report(0x00000000);\n
  103. # output: report(0x00000000);\n
  104. # output: \n
  105. # output: report(0x0000000b);\n
  106. # output: report(0x00000003);\n
  107. # output: report(0x00000003);\n
  108. # output: report(0x00000000);\n
  109. # output: report(0x00000000);\n
  110. # output: report(0x00000000);\n
  111. # output: \n
  112. # output: report(0xfffffff4);\n
  113. # output: report(0xfffffffd);\n
  114. # output: report(0x00000000);\n
  115. # output: report(0x00000000);\n
  116. # output: report(0x00000000);\n
  117. # output: report(0x00000000);\n
  118. # output: \n
  119. # output: report(0xfffffff5);\n
  120. # output: report(0xfffffffd);\n
  121. # output: report(0x00000000);\n
  122. # output: report(0x00000000);\n
  123. # output: report(0x00000000);\n
  124. # output: report(0x00000000);\n
  125. # output: \n
  126. # output: report(0xfffffff4);\n
  127. # output: report(0x00000003);\n
  128. # output: report(0x55555551);\n
  129. # output: report(0x00000000);\n
  130. # output: report(0x00000000);\n
  131. # output: report(0x00000000);\n
  132. # output: \n
  133. # output: report(0xfffffff5);\n
  134. # output: report(0x00000003);\n
  135. # output: report(0x55555551);\n
  136. # output: report(0x00000000);\n
  137. # output: report(0x00000000);\n
  138. # output: report(0x00000000);\n
  139. # output: \n
  140. # output: report(0x0000000c);\n
  141. # output: report(0xfffffffd);\n
  142. # output: report(0x00000000);\n
  143. # output: report(0x00000000);\n
  144. # output: report(0x00000000);\n
  145. # output: report(0x00000000);\n
  146. # output: \n
  147. # output: report(0x0000000b);\n
  148. # output: report(0xfffffffd);\n
  149. # output: report(0x00000000);\n
  150. # output: report(0x00000000);\n
  151. # output: report(0x00000000);\n
  152. # output: report(0x00000000);\n
  153. # output: \n
  154. # output: report(0x0000000c);\n
  155. # output: report(0x00000000);\n
  156. # output: report(0x00000000);\n
  157. # output: report(0x00000001);\n
  158. # output: report(0x00000000);\n
  159. # output: report(0x00000000);\n
  160. # output: \n
  161. # output: report(0xfffffff4);\n
  162. # output: report(0x00000000);\n
  163. # output: report(0x00000000);\n
  164. # output: report(0x00000001);\n
  165. # output: report(0x00000000);\n
  166. # output: report(0x00000000);\n
  167. # output: \n
  168. # output: report(0x0000000c);\n
  169. # output: report(0x00000000);\n
  170. # output: report(0x00000000);\n
  171. # output: report(0x00000001);\n
  172. # output: report(0x00000000);\n
  173. # output: report(0x00000001);\n
  174. # output: \n
  175. # output: report(0xfffffff4);\n
  176. # output: report(0x00000000);\n
  177. # output: report(0x00000000);\n
  178. # output: report(0x00000001);\n
  179. # output: report(0x00000000);\n
  180. # output: report(0x00000001);\n
  181. # output: \n
  182. # output: exit(0)\n
  183. #include "or1k-asm-test-helpers.h"
  184. STANDARD_TEST_ENVIRONMENT
  185. .section .exception_vectors
  186. /* Range exception. */
  187. .org 0xb00
  188. l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
  189. PUSH r2
  190. PUSH r3
  191. /* Save the address of the instruction that caused the problem. */
  192. MOVE_FROM_SPR r2, SPR_EPCR_BASE
  193. LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop */
  194. l.sw 0(r2), r3
  195. POP r3
  196. POP r2
  197. l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
  198. l.rfe
  199. .section .text
  200. start_tests:
  201. PUSH LINK_REGISTER_R9
  202. /* Test l.div */
  203. /* Divide two positive numbers and check rounding. Should set no
  204. flags. */
  205. TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000003 /* 12 / 3 = 4 */
  206. TEST_INST_I32_I32 l.div, 0x0000000b, 0x00000003 /* 11 / 3 = 3 */
  207. /* Divide two negative numbers and check rounding. Should set no
  208. flags. */
  209. TEST_INST_I32_I32 l.div, 0xfffffff4, 0xfffffffd
  210. TEST_INST_I32_I32 l.div, 0xfffffff5, 0xfffffffd
  211. /* Divide a negative number by a positive number and check
  212. rounding. Should set no flags. */
  213. TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000003
  214. TEST_INST_I32_I32 l.div, 0xfffffff5, 0x00000003
  215. /* Divide a positive number by a negative number and check
  216. rounding. Should set no flags. */
  217. TEST_INST_I32_I32 l.div, 0x0000000c, 0xfffffffd
  218. TEST_INST_I32_I32 l.div, 0x0000000b, 0xfffffffd
  219. /* Divide by zero. This will set the overflow flag. */
  220. TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
  221. TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
  222. /* Check that range exceptions are triggered. */
  223. SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
  224. /* Divide by zero. This will set the overflow flag and trigger an
  225. exception. */
  226. TEST_INST_I32_I32 l.div, 0x0000000c, 0x00000000
  227. TEST_INST_I32_I32 l.div, 0xfffffff4, 0x00000000
  228. CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
  229. /* Test l.divu */
  230. /* Divide two positive numbers and check rounding. Should set no
  231. flags. */
  232. TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000003
  233. TEST_INST_I32_I32 l.divu, 0x0000000b, 0x00000003
  234. /* Divide two numbers that would be negative under 2's complement
  235. and check rounding. Should set no flags. */
  236. TEST_INST_I32_I32 l.divu, 0xfffffff4, 0xfffffffd
  237. TEST_INST_I32_I32 l.divu, 0xfffffff5, 0xfffffffd
  238. /* Divide a number that would be negative under 2's complement by a
  239. number that would be positive under 2's complement and check
  240. rounding. This should set no flags. */
  241. TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000003
  242. TEST_INST_I32_I32 l.divu, 0xfffffff5, 0x00000003
  243. /* Divide a number that would be positive under 2's complement by a
  244. number that would be negative under 2's complement and check
  245. rounding. This should set no flags. */
  246. TEST_INST_I32_I32 l.divu, 0x0000000c, 0xfffffffd
  247. TEST_INST_I32_I32 l.divu, 0x0000000b, 0xfffffffd
  248. /* Divide by zero. This will set the carry flag. */
  249. TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
  250. TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
  251. /* Check that range exceptions are triggered. */
  252. SET_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
  253. /* Divide by zero. This will set the carry flag and trigger an
  254. exception. */
  255. TEST_INST_I32_I32 l.divu, 0x0000000c, 0x00000000
  256. TEST_INST_I32_I32 l.divu, 0xfffffff4, 0x00000000
  257. CLEAR_SPR_SR_FLAGS SPR_SR_OVE, r2, r3
  258. POP LINK_REGISTER_R9
  259. RETURN_TO_LINK_REGISTER_R9