or1korfpx.cpu 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ; OpenRISC 1000 architecture. -*- Scheme -*-
  2. ; Copyright 2000-2014 Free Software Foundation, Inc.
  3. ; Contributed by Peter Gavin, pgavin@gmail.com
  4. ;
  5. ; This program is free software; you can redistribute it and/or modify
  6. ; it under the terms of the GNU General Public License as published by
  7. ; the Free Software Foundation; either version 3 of the License, or
  8. ; (at your option) any later version.
  9. ;
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ; GNU General Public License for more details.
  14. ;
  15. ; You should have received a copy of the GNU General Public License
  16. ; along with this program; if not, see <http://www.gnu.org/licenses/>
  17. ; Initial ORFPX32 instruction set
  18. ; I'm not sure how CGEN handles rounding in FP operations, except for
  19. ; in conversions to/from integers. So lf.add, lf.sub, lf.mul, and
  20. ; lf.div do not round according to the FPCSR RM field.
  21. ; NaN, overflow, and underflow are not yet handled either.
  22. (define-normal-insn-enum insn-opcode-float-regreg
  23. "floating point reg/reg insn opcode enums" ()
  24. OPC_FLOAT_REGREG_ f-op-7-8
  25. (("ADD_S" #x00)
  26. ("SUB_S" #x01)
  27. ("MUL_S" #x02)
  28. ("DIV_S" #x03)
  29. ("ITOF_S" #x04)
  30. ("FTOI_S" #x05)
  31. ("REM_S" #x06)
  32. ("MADD_S" #x07)
  33. ("SFEQ_S" #x08)
  34. ("SFNE_S" #x09)
  35. ("SFGT_S" #x0a)
  36. ("SFGE_S" #x0b)
  37. ("SFLT_S" #x0c)
  38. ("SFLE_S" #x0d)
  39. ("ADD_D" #x10)
  40. ("SUB_D" #x11)
  41. ("MUL_D" #x12)
  42. ("DIV_D" #x13)
  43. ("ITOF_D" #x14)
  44. ("FTOI_D" #x15)
  45. ("REM_D" #x16)
  46. ("MADD_D" #x17)
  47. ("SFEQ_D" #x18)
  48. ("SFNE_D" #x19)
  49. ("SFGT_D" #x1a)
  50. ("SFGE_D" #x1b)
  51. ("SFLT_D" #x1c)
  52. ("SFLE_D" #x1d)
  53. ("CUST1_S" #xd0)
  54. ("CUST1_D" #xe0)
  55. )
  56. )
  57. (dnop rDSF "destination register (single floating point mode)" () h-fsr f-r1)
  58. (dnop rASF "source register A (single floating point mode)" () h-fsr f-r2)
  59. (dnop rBSF "source register B (single floating point mode)" () h-fsr f-r3)
  60. (dnop rDDF "destination register (double floating point mode)" ((MACH ORFPX64-MACHS)) h-fdr f-r1)
  61. (dnop rADF "source register A (double floating point mode)" ((MACH ORFPX64-MACHS)) h-fdr f-r1)
  62. (dnop rBDF "source register B (double floating point mode)" ((MACH ORFPX64-MACHS)) h-fdr f-r1)
  63. (define-pmacro (float-regreg-insn mnemonic)
  64. (begin
  65. (dni (.sym lf- mnemonic -s)
  66. (.str "lf." mnemonic ".s reg/reg/reg")
  67. ((MACH ORFPX-MACHS))
  68. (.str "lf." mnemonic ".s $rDSF,$rASF,$rBSF")
  69. (+ OPC_FLOAT rDSF rASF rBSF (f-resv-10-3 0) (.sym OPC_FLOAT_REGREG_ (.upcase mnemonic) _S))
  70. (set SF rDSF (mnemonic SF rASF rBSF))
  71. ()
  72. )
  73. (dni (.sym lf- mnemonic -d)
  74. (.str "lf." mnemonic ".d reg/reg/reg")
  75. ((MACH ORFPX64-MACHS))
  76. (.str "lf." mnemonic ".d $rDDF,$rADF,$rBDF")
  77. (+ OPC_FLOAT rDDF rADF rBDF (f-resv-10-3 0) (.sym OPC_FLOAT_REGREG_ (.upcase mnemonic) _D))
  78. (set DF rDDF (mnemonic DF rADF rBDF))
  79. ()
  80. )
  81. )
  82. )
  83. (float-regreg-insn add)
  84. (float-regreg-insn sub)
  85. (float-regreg-insn mul)
  86. (float-regreg-insn div)
  87. (dni lf-rem-s
  88. "lf.rem.s reg/reg/reg"
  89. ((MACH ORFPX-MACHS))
  90. "lf.rem.s $rDSF,$rASF,$rBSF"
  91. (+ OPC_FLOAT rDSF rASF rBSF (f-resv-10-3 0) OPC_FLOAT_REGREG_REM_S)
  92. (set SF rDSF (rem SF rASF rBSF))
  93. ()
  94. )
  95. (dni lf-rem-d
  96. "lf.rem.d reg/reg/reg"
  97. ((MACH ORFPX64-MACHS))
  98. "lf.rem.d $rDDF,$rADF,$rBDF"
  99. (+ OPC_FLOAT rDDF rADF rBDF (f-resv-10-3 0) OPC_FLOAT_REGREG_REM_D)
  100. (set DF rDDF (mod DF rADF rBDF))
  101. ()
  102. )
  103. (define-pmacro (get-rounding-mode)
  104. (case INT sys-fpcsr-rm
  105. ((0) 1) ; TIES-TO-EVEN -- I'm assuming this is what is meant by "round to nearest"
  106. ((1) 3) ; TOWARD-ZERO
  107. ((2) 4) ; TOWARD-POSITIVE
  108. (else 5) ; TOWARD-NEGATIVE
  109. )
  110. )
  111. (dni lf-itof-s
  112. "lf.itof.s reg/reg"
  113. ((MACH ORFPX-MACHS))
  114. "lf.itof.s $rDSF,$rA"
  115. (+ OPC_FLOAT rDSF rA (f-r3 0) (f-resv-10-3 0) OPC_FLOAT_REGREG_ITOF_S)
  116. (set SF rDSF (float SF (get-rounding-mode) (trunc SI rA)))
  117. ()
  118. )
  119. (dni lf-itof-d
  120. "lf.itof.d reg/reg"
  121. ((MACH ORFPX64-MACHS))
  122. "lf.itof.d $rDSF,$rA"
  123. (+ OPC_FLOAT rDSF rA (f-r3 0) (f-resv-10-3 0) OPC_FLOAT_REGREG_ITOF_D)
  124. (set DF rDDF (float DF (get-rounding-mode) rA))
  125. ()
  126. )
  127. (dni lf-ftoi-s
  128. "lf.ftoi.s reg/reg"
  129. ((MACH ORFPX-MACHS))
  130. "lf.ftoi.s $rD,$rASF"
  131. (+ OPC_FLOAT rD rASF (f-r3 0) (f-resv-10-3 0) OPC_FLOAT_REGREG_FTOI_S)
  132. (set WI rD (ext WI (fix SI (get-rounding-mode) rASF)))
  133. ()
  134. )
  135. (dni lf-ftoi-d
  136. "lf.ftoi.d reg/reg"
  137. ((MACH ORFPX64-MACHS))
  138. "lf.ftoi.d $rD,$rADF"
  139. (+ OPC_FLOAT rD rADF (f-r3 0) (f-resv-10-3 0) OPC_FLOAT_REGREG_FTOI_D)
  140. (set DI rD (fix DI (get-rounding-mode) rADF))
  141. ()
  142. )
  143. (define-pmacro (float-setflag-insn mnemonic)
  144. (begin
  145. (dni (.sym lf- mnemonic -s)
  146. (.str "lf.sf" mnemonic ".s reg/reg")
  147. ((MACH ORFPX-MACHS))
  148. (.str "lf.sf" mnemonic ".s $rASF,$rBSF")
  149. (+ OPC_FLOAT (f-r1 0) rASF rBSF (f-resv-10-3 0) (.sym OPC_FLOAT_REGREG_SF (.upcase mnemonic) _S))
  150. (set BI sys-sr-f (mnemonic SF rASF rBSF))
  151. ()
  152. )
  153. (dni (.sym lf- mnemonic -d)
  154. (.str "lf.sf" mnemonic ".d reg/reg")
  155. ((MACH ORFPX64-MACHS))
  156. (.str "lf.sf" mnemonic ".d $rASF,$rBSF")
  157. (+ OPC_FLOAT (f-r1 0) rASF rBSF (f-resv-10-3 0) (.sym OPC_FLOAT_REGREG_SF (.upcase mnemonic) _D))
  158. (set BI sys-sr-f (mnemonic DF rADF rBDF))
  159. ()
  160. )
  161. )
  162. )
  163. (float-setflag-insn eq)
  164. (float-setflag-insn ne)
  165. (float-setflag-insn ge)
  166. (float-setflag-insn gt)
  167. (float-setflag-insn lt)
  168. (float-setflag-insn le)
  169. (dni lf-madd-s
  170. "lf.madd.s reg/reg/reg"
  171. ((MACH ORFPX-MACHS))
  172. "lf.madd.s $rDSF,$rASF,$rBSF"
  173. (+ OPC_FLOAT rDSF rASF rBSF (f-resv-10-3 0) OPC_FLOAT_REGREG_MADD_S)
  174. (set SF rDSF (add SF (mul SF rASF rBSF) rDSF))
  175. ()
  176. )
  177. (dni lf-madd-d
  178. "lf.madd.d reg/reg/reg"
  179. ((MACH ORFPX64-MACHS))
  180. "lf.madd.d $rDDF,$rADF,$rBDF"
  181. (+ OPC_FLOAT rDDF rADF rBDF (f-resv-10-3 0) OPC_FLOAT_REGREG_MADD_D)
  182. (set DF rDDF (add DF (mul DF rADF rBDF) rDDF))
  183. ()
  184. )
  185. (define-pmacro (float-cust-insn cust-num)
  186. (begin
  187. (dni (.sym "lf-cust" cust-num "-s")
  188. (.str "lf.cust" cust-num ".s")
  189. ((MACH ORFPX-MACHS))
  190. (.str "lf.cust" cust-num ".s $rASF,$rBSF")
  191. (+ OPC_FLOAT (f-resv-25-5 0) rASF rBSF (f-resv-10-3 0) (.sym "OPC_FLOAT_REGREG_CUST" cust-num "_S"))
  192. (nop)
  193. ()
  194. )
  195. (dni (.sym "lf-cust" cust-num "-d")
  196. (.str "lf.cust" cust-num ".d")
  197. ((MACH ORFPX64-MACHS))
  198. (.str "lf.cust" cust-num ".d")
  199. (+ OPC_FLOAT (f-resv-25-5 0) rADF rBDF (f-resv-10-3 0) (.sym "OPC_FLOAT_REGREG_CUST" cust-num "_D"))
  200. (nop)
  201. ()
  202. )
  203. )
  204. )
  205. (float-cust-insn "1")