fpu.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Tests some basic fpu 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(0x00007ab7);\n
  15. # output: report(0xffffd8f0);\n
  16. # output: report(0x46f56e00);\n
  17. # output: report(0xc61c4000);\n
  18. # output: report(0x00007ab7);\n
  19. # output: report(0xffffd8f0);\n
  20. # output: \n
  21. # output: report(0xc0490e56);\n
  22. # output: report(0xfffffffd);\n
  23. # output: \n
  24. # output: report(0x4e6b4bbb);\n
  25. # output: \n
  26. # output: report(0xbdc0be40);\n
  27. # output: \n
  28. # output: report(0x00000001);\n
  29. # output: \n
  30. # output: WARNING: ignoring fpu error caught in fast mode.\n
  31. # output: report(0x00000000);\n
  32. # output: \n
  33. # output: exit(0)\n
  34. #include "or1k-asm-test-helpers.h"
  35. STANDARD_TEST_ENVIRONMENT
  36. .section .exception_vectors
  37. /* Floating point exception. */
  38. .org 0xd00
  39. /* The handling is a bit dubious at present. We just patch the
  40. instruction with l.nop and restart. This will go wrong in branch
  41. delay slots. But we don't have those in this test. */
  42. l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
  43. PUSH r2
  44. PUSH r3
  45. /* Save the address of the instruction that caused the problem. */
  46. MOVE_FROM_SPR r2, SPR_EPCR_BASE
  47. LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop */
  48. l.sw -4(r2), r3
  49. POP r3
  50. POP r2
  51. l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
  52. l.rfe
  53. .section .text
  54. start_tests:
  55. PUSH LINK_REGISTER_R9
  56. /* Test lf.itof.s int to float conversion. Setting up:
  57. * r10 31415.0f
  58. * r12 -10000.0f
  59. */
  60. l.ori r11, r0, 31415
  61. l.ori r13, r0, -10000
  62. l.movhi r15, 0xffff
  63. l.or r13, r13, r15
  64. REPORT_REG_TO_CONSOLE r11
  65. REPORT_REG_TO_CONSOLE r13
  66. lf.itof.s r10, r11
  67. lf.itof.s r12, r13
  68. REPORT_REG_TO_CONSOLE r10
  69. REPORT_REG_TO_CONSOLE r12
  70. /* Test lf.ftoi.s float to int conversion. */
  71. lf.ftoi.s r11, r10
  72. lf.ftoi.s r13, r12
  73. REPORT_REG_TO_CONSOLE r11
  74. REPORT_REG_TO_CONSOLE r13
  75. PRINT_NEWLINE_TO_CONSOLE
  76. /* Test lf.div.s divide 31415 by -1000 to get -pi. Setting up:
  77. * r8 -3.1415f
  78. */
  79. lf.div.s r8, r10, r12
  80. REPORT_REG_TO_CONSOLE r8
  81. lf.ftoi.s r11, r8
  82. REPORT_REG_TO_CONSOLE r11
  83. PRINT_NEWLINE_TO_CONSOLE
  84. /* Test lf.mul.s multiply -pi x -10000 x 31415. Setting up:
  85. * r6 986902225
  86. */
  87. lf.mul.s r6, r8, r12
  88. lf.mul.s r6, r6, r10
  89. REPORT_REG_TO_CONSOLE r6
  90. PRINT_NEWLINE_TO_CONSOLE
  91. /* Test lf.rem.s remainder of 986902225 / -pi. */
  92. lf.rem.s r2, r6, r8
  93. REPORT_REG_TO_CONSOLE r2
  94. PRINT_NEWLINE_TO_CONSOLE
  95. /* Test lf.sfge.s set flag if r6 >= r10. */
  96. lf.sfge.s r6, r10
  97. MOVE_FROM_SPR r2, SPR_SR
  98. REPORT_BIT_TO_CONSOLE r2, SPR_SR_F
  99. PRINT_NEWLINE_TO_CONSOLE
  100. /* Test raising an exception by dividing by 0. */
  101. MOVE_FROM_SPR r2, SPR_FPCSR
  102. l.ori r2, r2, 0x1
  103. MOVE_TO_SPR SPR_FPCSR, r2
  104. div0: lf.div.s r2, r8, r0
  105. REPORT_EXCEPTION div0
  106. PRINT_NEWLINE_TO_CONSOLE
  107. POP LINK_REGISTER_R9
  108. RETURN_TO_LINK_REGISTER_R9