fpu64a32.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* Tests some basic fpu instructions.
  2. Copyright (C) 2019-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(0x400921f9);\n
  15. # output: report(0xf01b866e);\n
  16. # output: report(0x4005bf09);\n
  17. # output: report(0x95aaf790);\n
  18. # output: report(0x00000000);\n
  19. # output: report(0x00001234);\n
  20. # output: \n
  21. # output: report(0x40b23400);\n
  22. # output: report(0x00000000);\n
  23. # output: report(0x40b23400);\n
  24. # output: report(0x00000000);\n
  25. # output: \n
  26. # output: report(0x40177081);\n
  27. # output: report(0xc2e33eff);\n
  28. # output: report(0x400921f9);\n
  29. # output: report(0xf01b866e);\n
  30. # output: \n
  31. # output: report(0x40211456);\n
  32. # output: report(0x587dfabf);\n
  33. # output: report(0x400921f9);\n
  34. # output: report(0xf01b866d);\n
  35. # output: \n
  36. # output: report(0x00000001);\n
  37. # output: \n
  38. # output: WARNING: ignoring fpu error caught in fast mode.\n
  39. # output: report(0x00000000);\n
  40. # output: \n
  41. # output: exit(0)\n
  42. #include "or1k-asm-test-helpers.h"
  43. STANDARD_TEST_ENVIRONMENT
  44. .section .exception_vectors
  45. /* Floating point exception. */
  46. .org 0xd00
  47. /* The handling is a bit dubious at present. We just patch the
  48. instruction with l.nop and restart. This will go wrong in branch
  49. delay slots. But we don't have those in this test. */
  50. l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
  51. PUSH r2
  52. PUSH r3
  53. /* Save the address of the instruction that caused the problem. */
  54. MOVE_FROM_SPR r2, SPR_EPCR_BASE
  55. LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop */
  56. l.sw -4(r2), r3
  57. POP r3
  58. POP r2
  59. l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
  60. l.rfe
  61. .section .data
  62. .align 4
  63. .type pi, @object
  64. .size pi, 8
  65. anchor:
  66. pi:
  67. .double 3.14159
  68. .type e, @object
  69. .size e, 8
  70. e:
  71. .double 2.71828
  72. .type large, @object
  73. .size large, 8
  74. large:
  75. .long 0
  76. .long 0x1234
  77. .section .text
  78. start_tests:
  79. PUSH LINK_REGISTER_R9
  80. /* Test lf.itof.d int to double conversion. Setting up:
  81. * r11 pointer to data
  82. * r12,r13 pi as double
  83. * r14,r15 e as double
  84. * r16,r17 a long long
  85. */
  86. l.ori r11, r0, ha(anchor)
  87. l.addi r11, r11, lo(anchor)
  88. l.lwz r12, 0(r11)
  89. l.lwz r13, 4(r11)
  90. l.lwz r14, 8(r11)
  91. l.lwz r15, 12(r11)
  92. l.lwz r16, 16(r11)
  93. l.lwz r18, 20(r11)
  94. /* Output to ensure we loaded it correctly. */
  95. REPORT_REG_TO_CONSOLE r12
  96. REPORT_REG_TO_CONSOLE r13
  97. REPORT_REG_TO_CONSOLE r14
  98. REPORT_REG_TO_CONSOLE r15
  99. REPORT_REG_TO_CONSOLE r16
  100. REPORT_REG_TO_CONSOLE r18
  101. PRINT_NEWLINE_TO_CONSOLE
  102. /* Convert the big long to a double. */
  103. lf.itof.d r16,r18, r16,r18
  104. REPORT_REG_TO_CONSOLE r16
  105. REPORT_REG_TO_CONSOLE r18
  106. /* Convert the double back to a long, it should match before. */
  107. lf.ftoi.d r16,r18, r16,r18
  108. lf.itof.d r16,r18, r16,r18
  109. REPORT_REG_TO_CONSOLE r16
  110. REPORT_REG_TO_CONSOLE r18
  111. PRINT_NEWLINE_TO_CONSOLE
  112. /* Add and subtract some double values. */
  113. lf.add.d r12,r13, r12,r13, r14,r15
  114. REPORT_REG_TO_CONSOLE r12
  115. REPORT_REG_TO_CONSOLE r13
  116. lf.sub.d r12,r13, r12,r13, r14,r15
  117. REPORT_REG_TO_CONSOLE r12
  118. REPORT_REG_TO_CONSOLE r13
  119. PRINT_NEWLINE_TO_CONSOLE
  120. /* Multiply and divide double values. */
  121. lf.mul.d r12,r13, r12,r13, r14,r15
  122. REPORT_REG_TO_CONSOLE r12
  123. REPORT_REG_TO_CONSOLE r13
  124. lf.div.d r12,r13, r12,r13, r14,r15
  125. REPORT_REG_TO_CONSOLE r12
  126. REPORT_REG_TO_CONSOLE r13
  127. PRINT_NEWLINE_TO_CONSOLE
  128. /* Test lf.sfge.s set flag if r6 >= r10. */
  129. lf.sfge.d r12,r13, r14,r15
  130. MOVE_FROM_SPR r2, SPR_SR
  131. REPORT_BIT_TO_CONSOLE r2, SPR_SR_F
  132. PRINT_NEWLINE_TO_CONSOLE
  133. /* Test raising an exception by dividing by 0. */
  134. MOVE_FROM_SPR r2, SPR_FPCSR
  135. l.ori r2, r2, 0x1
  136. MOVE_TO_SPR SPR_FPCSR, r2
  137. div0: lf.div.d r2,r3, r12,r13, r0,r1
  138. REPORT_EXCEPTION div0
  139. PRINT_NEWLINE_TO_CONSOLE
  140. POP LINK_REGISTER_R9
  141. RETURN_TO_LINK_REGISTER_R9