mep-fmax.cpu 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. ; Toshiba MeP FMAX Coprocessor description. -*- Scheme -*-
  2. ; Copyright 2011 Free Software Foundation, Inc.
  3. ;
  4. ; Contributed by Red Hat Inc;
  5. ;
  6. ; This file is part of the GNU Binutils.
  7. ;
  8. ; This program is free software; you can redistribute it and/or modify
  9. ; it under the terms of the GNU General Public License as published by
  10. ; the Free Software Foundation; either version 3 of the License, or
  11. ; (at your option) any later version.
  12. ;
  13. ; This program is distributed in the hope that it will be useful,
  14. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ; GNU General Public License for more details.
  17. ;
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  21. ; MA 02110-1301, USA.
  22. ;------------------------------------------------------------------------------
  23. ; MeP-Integrator will redefine the isa pmacros below to allow the bit widths
  24. ; specified below for each ME_MODULE using this coprocessor.
  25. ; This coprocessor requires only the 32 bit insns in the core.
  26. ;------------------------------------------------------------------------------
  27. ; begin-isas
  28. (define-pmacro fmax-core-isa () (ISA ext_core2))
  29. (define-pmacro all-fmax-isas () (ISA ext_core2))
  30. ; end-isas
  31. ;******************************************************************************
  32. ; ifields
  33. ;------------------------------------------------------------------------------
  34. ; opcodes
  35. (dnf f-fmax-0-4 "opcode" (all-fmax-isas) 0 4)
  36. (dnf f-fmax-4-4 "opcode" (all-fmax-isas) 4 4)
  37. (dnf f-fmax-8-4 "opcode" (all-fmax-isas) 8 4)
  38. (dnf f-fmax-12-4 "opcode" (all-fmax-isas) 12 4)
  39. (dnf f-fmax-16-4 "opcode" (all-fmax-isas) 16 4)
  40. (dnf f-fmax-20-4 "opcode" (all-fmax-isas) 20 4)
  41. (dnf f-fmax-24-4 "opcode" (all-fmax-isas) 24 4)
  42. (dnf f-fmax-28-1 "opcode" (all-fmax-isas) 28 1)
  43. (dnf f-fmax-29-1 "opcode" (all-fmax-isas) 29 1)
  44. (dnf f-fmax-30-1 "opcode" (all-fmax-isas) 30 1)
  45. (dnf f-fmax-31-1 "opcode" (all-fmax-isas) 31 1)
  46. ;------------------------------------------------------------------------------
  47. ; FR registers
  48. (define-multi-ifield
  49. (name f-fmax-frd)
  50. (comment "FRd register")
  51. (attrs all-fmax-isas)
  52. (mode UINT)
  53. (subfields f-fmax-28-1 f-fmax-4-4)
  54. (insert (sequence ()
  55. (set (ifield f-fmax-4-4) (and (ifield f-fmax-frd) #xf))
  56. (set (ifield f-fmax-28-1) (srl (ifield f-fmax-frd) 4))))
  57. (extract (set (ifield f-fmax-frd)
  58. (or (sll (ifield f-fmax-28-1) 4) (ifield f-fmax-4-4))))
  59. )
  60. (define-multi-ifield
  61. (name f-fmax-frn)
  62. (comment "FRn register")
  63. (attrs all-fmax-isas)
  64. (mode UINT)
  65. (subfields f-fmax-29-1 f-fmax-20-4)
  66. (insert (sequence ()
  67. (set (ifield f-fmax-20-4) (and (ifield f-fmax-frn) #xf))
  68. (set (ifield f-fmax-29-1) (srl (ifield f-fmax-frn) 4))))
  69. (extract (set (ifield f-fmax-frn)
  70. (or (sll (ifield f-fmax-29-1) 4) (ifield f-fmax-20-4))))
  71. )
  72. (define-multi-ifield
  73. (name f-fmax-frm)
  74. (comment "FRm register")
  75. (attrs all-fmax-isas)
  76. (mode UINT)
  77. (subfields f-fmax-30-1 f-fmax-24-4)
  78. (insert (sequence ()
  79. (set (ifield f-fmax-24-4) (and (ifield f-fmax-frm) #xf))
  80. (set (ifield f-fmax-30-1) (srl (ifield f-fmax-frm) 4))))
  81. (extract (set (ifield f-fmax-frm)
  82. (or (sll (ifield f-fmax-30-1) 4) (ifield f-fmax-24-4))))
  83. )
  84. ;------------------------------------------------------------------------------
  85. ; Core General registers
  86. (dnf f-fmax-rm "opcode" (all-fmax-isas) 8 4)
  87. ;------------------------------------------------------------------------------
  88. ; Condition opcodes enum
  89. (define-normal-insn-enum fmax-cond "condition opcode enum" (all-fmax-isas) FMAX_ f-fmax-8-4
  90. ("f" "u" "e" "ue" "l" "ul" "le" "ule"
  91. "fi" "ui" "ei" "uei" "li" "uli" "lei" "ulei")
  92. )
  93. ;******************************************************************************
  94. ; Hardware
  95. ;------------------------------------------------------------------------------
  96. ; FR registers
  97. ; Given a coprocessor register number N, expand to a
  98. ; name/index pair: ($frN N)
  99. (define-pmacro (-fmax-fr-reg-pair n) ((.sym "fr" n) n))
  100. (define-pmacro (-fmax-cr-reg-pair n) ((.sym "c" n) n))
  101. ; NOTE: This exists solely for the purpose of providing the proper register names for this coprocessor.
  102. ; GDB will use the hardware table generated from this declaration. The operands use h-cr
  103. ; from mep-core.cpu so that SID's semantic trace will be consistent between
  104. ; the core and the coprocessor but use parse/print handlers which reference the hardware table
  105. ; generated from this declarations
  106. (define-hardware
  107. (name h-cr-fmax)
  108. (comment "Floating point registers")
  109. (attrs all-fmax-isas VIRTUAL IS_FLOAT)
  110. (type register SF (32))
  111. (indices keyword "$"
  112. (.splice (.unsplice (.map -fmax-fr-reg-pair (.iota 32)))
  113. (.unsplice (.map -fmax-cr-reg-pair (.iota 32))))
  114. )
  115. (get (index) (c-call SF "fmax_fr_get_handler" index))
  116. (set (index newval) (c-call VOID "fmax_fr_set_handler" index newval))
  117. )
  118. ;------------------------------------------------------------------------------
  119. ; Control registers
  120. ; NOTE: This exists solely for the purpose of providing the proper register names for this coprocessor.
  121. ; GDB will use the hardware table generated from this declaration. The operands use h-ccr
  122. ; from mep-core.cpu so that SID's semantic trace will be consistent between
  123. ; the core and the coprocessor but use parse/print handlers which reference the hardware table
  124. ; generated from this declarations
  125. (define-hardware
  126. (name h-ccr-fmax)
  127. (comment "Coprocessor Identifier and Revision Register")
  128. (attrs all-fmax-isas VIRTUAL)
  129. (type register USI (16))
  130. (indices keyword "$" (
  131. ("cirr" 0) ("fcr0" 0) ("ccr0" 0)
  132. ("cbcr" 1) ("fcr1" 1) ("ccr1" 1)
  133. ("cerr" 15) ("fcr15" 15) ("ccr15" 15)
  134. )
  135. )
  136. (set (index newval) (c-call VOID "h_ccr_set" index newval))
  137. (get (index) (c-call SI "h_ccr_get" index))
  138. )
  139. ;------------------------------------------------------------------------------
  140. ; Misc
  141. (define-hardware
  142. (name h-fmax-compare-i-p)
  143. (comment "flag")
  144. (attrs all-fmax-isas)
  145. (type register USI)
  146. )
  147. ;******************************************************************************
  148. ; Operands
  149. ;------------------------------------------------------------------------------
  150. ; FR Registers
  151. (define-full-operand fmax-FRd "FRd" (all-fmax-isas (CDATA FMAX_FLOAT)) h-cr SF f-fmax-frd ((parse "fmax_cr") (print "fmax_cr")) () ())
  152. (define-full-operand fmax-FRn "FRn" (all-fmax-isas (CDATA FMAX_FLOAT)) h-cr SF f-fmax-frn ((parse "fmax_cr") (print "fmax_cr")) () ())
  153. (define-full-operand fmax-FRm "FRm" (all-fmax-isas (CDATA FMAX_FLOAT)) h-cr SF f-fmax-frm ((parse "fmax_cr") (print "fmax_cr")) () ())
  154. (define-full-operand fmax-FRd-int "FRd as an integer" (all-fmax-isas (CDATA FMAX_INT)) h-cr SI f-fmax-frd ((parse "fmax_cr") (print "fmax_cr")) () ())
  155. (define-full-operand fmax-FRn-int "FRn as an integer" (all-fmax-isas (CDATA FMAX_INT)) h-cr SI f-fmax-frn ((parse "fmax_cr") (print "fmax_cr")) () ())
  156. ;------------------------------------------------------------------------------
  157. ; Control registers
  158. (define-full-operand fmax-CCRn "CCRn" (all-fmax-isas (CDATA REGNUM)) h-ccr DFLT f-fmax-4-4 ((parse "fmax_ccr") (print "fmax_ccr")) () ())
  159. (dnop fmax-CIRR "CIRR" (all-fmax-isas SEM-ONLY) h-ccr 0)
  160. (dnop fmax-CBCR "CBCR" (all-fmax-isas SEM-ONLY) h-ccr 1)
  161. (dnop fmax-CERR "CERR" (all-fmax-isas SEM-ONLY) h-ccr 15)
  162. ;------------------------------------------------------------------------------
  163. ; Core General Registers
  164. (dnop fmax-Rm "Rm" (all-fmax-isas) h-gpr f-fmax-rm)
  165. ;------------------------------------------------------------------------------
  166. ; misc
  167. (dnop fmax-Compare-i-p "flag" (all-fmax-isas SEM-ONLY) h-fmax-compare-i-p f-nil)
  168. ;******************************************************************************
  169. ; Instructions
  170. ;------------------------------------------------------------------------------
  171. ; Binary Arithmetic
  172. (define-pmacro (fmax-binary-arith op opc sem)
  173. (dni op
  174. (.str op " FRd,FRn,FRm")
  175. (all-fmax-isas MAY_TRAP)
  176. (.str op " ${fmax-FRd},${fmax-FRn},${fmax-FRm}")
  177. (+ (f-fmax-0-4 #xF) fmax-FRd (f-fmax-8-4 opc) (f-fmax-12-4 #x7) (f-fmax-16-4 0)
  178. fmax-FRn fmax-FRm (f-fmax-31-1 0))
  179. sem
  180. ()
  181. )
  182. )
  183. (fmax-binary-arith fadds #x0 (set fmax-FRd (add fmax-FRn fmax-FRm)))
  184. (fmax-binary-arith fsubs #x1 (set fmax-FRd (sub fmax-FRn fmax-FRm)))
  185. (fmax-binary-arith fmuls #x2 (set fmax-FRd (mul fmax-FRn fmax-FRm)))
  186. (fmax-binary-arith fdivs #x3 (set fmax-FRd (div fmax-FRn fmax-FRm)))
  187. ;------------------------------------------------------------------------------
  188. ; Unary Arithmetic
  189. (define-pmacro (fmax-unary-arith op opc sem)
  190. (dni op
  191. (.str op " FRd,FRn")
  192. (all-fmax-isas MAY_TRAP)
  193. (.str op " ${fmax-FRd},${fmax-FRn}")
  194. (+ (f-fmax-0-4 #xF) fmax-FRd (f-fmax-8-4 opc) (f-fmax-12-4 #x7)
  195. (f-fmax-16-4 0) fmax-FRn (f-fmax-24-4 0) (f-fmax-30-1 0) (f-fmax-31-1 0))
  196. sem
  197. ()
  198. )
  199. )
  200. (fmax-unary-arith fsqrts #x4 (set fmax-FRd (sqrt fmax-FRn)))
  201. (fmax-unary-arith fabss #x5 (set fmax-FRd (abs fmax-FRn)))
  202. (fmax-unary-arith fnegs #x7 (set fmax-FRd (neg fmax-FRn)))
  203. (fmax-unary-arith fmovs #x6 (set fmax-FRd fmax-FRn))
  204. ;------------------------------------------------------------------------------
  205. ; Conversions
  206. (define-pmacro (fmax-conv op opc1 opc2 opnd1 opnd2 sem)
  207. (dni op
  208. (.str op " FRd,FRn")
  209. (all-fmax-isas MAY_TRAP)
  210. (.str op " ${" opnd1 "},${" opnd2 "}")
  211. (+ (f-fmax-0-4 #xF) opnd1 (f-fmax-8-4 opc1) (f-fmax-12-4 #x7)
  212. (f-fmax-16-4 opc2) opnd2 (f-fmax-24-4 0) (f-fmax-30-1 0) (f-fmax-31-1 0))
  213. sem
  214. ()
  215. )
  216. )
  217. (fmax-conv froundws #xC #x0 fmax-FRd-int fmax-FRn (set fmax-FRd-int (c-call SI "fmax_froundws" fmax-FRn)))
  218. (fmax-conv ftruncws #xD #x0 fmax-FRd-int fmax-FRn (set fmax-FRd-int (c-call SI "fmax_ftruncws" fmax-FRn)))
  219. (fmax-conv fceilws #xE #x0 fmax-FRd-int fmax-FRn (set fmax-FRd-int (c-call SI "fmax_fceilws" fmax-FRn)))
  220. (fmax-conv ffloorws #xF #x0 fmax-FRd-int fmax-FRn (set fmax-FRd-int (c-call SI "fmax_ffloorws" fmax-FRn)))
  221. (fmax-conv fcvtws #x4 #x1 fmax-FRd-int fmax-FRn (set fmax-FRd-int (c-call SI "fmax_fcvtws" fmax-FRn)))
  222. (fmax-conv fcvtsw #x0 #x9 fmax-FRd fmax-FRn-int (set fmax-FRd (float SF FPCONV-DEFAULT fmax-FRn-int)))
  223. ;------------------------------------------------------------------------------
  224. ; Comparisons
  225. ;
  226. ; Comparison with no exceptions
  227. (define-pmacro (fmax-f-sem x y) (andif (gt x y) (lt x y))) ; do this to get exception detection
  228. (define-pmacro (fmax-u-sem x y) (not (orif (lt x y) (orif (eq x y) (gt x y)))))
  229. (define-pmacro (fmax-e-sem x y) (eq x y))
  230. (define-pmacro (fmax-ue-sem x y) (not (orif (lt x y) (gt x y))))
  231. (define-pmacro (fmax-l-sem x y) (lt x y))
  232. (define-pmacro (fmax-ul-sem x y) (not (orif (gt x y) (eq x y))))
  233. (define-pmacro (fmax-le-sem x y) (orif (lt x y) (eq x y)))
  234. (define-pmacro (fmax-ule-sem x y) (not (gt x y)))
  235. (define-pmacro (fmax-comp cond suffix exceptions)
  236. (dni (.sym fcmp cond suffix s)
  237. (.str "fcmp" cond suffix "s FRn,FRm")
  238. ;; Even though the instruction doesn't really trap if EXCEPTIONS
  239. ;; is zero, we don't want gcc to put it in a repeat or erepeat
  240. ;; block because of the hazards between fcmp instructions and
  241. ;; anything that reads CBCR.
  242. (all-fmax-isas MAY_TRAP)
  243. (.str "fcmp" cond suffix "s ${fmax-FRn},${fmax-FRm}")
  244. (+ (f-fmax-0-4 #xF) (f-fmax-4-4 0) (.sym FMAX_ cond suffix) (f-fmax-12-4 #x7)
  245. (f-fmax-16-4 #x2) (f-fmax-28-1 0) fmax-FRn fmax-FRm (f-fmax-31-1 0))
  246. (sequence ()
  247. (set fmax-Compare-i-p exceptions)
  248. (set fmax-CBCR ((.sym fmax- cond -sem) fmax-FRn fmax-FRm))
  249. (set fmax-Compare-i-p 0)
  250. )
  251. ()
  252. )
  253. )
  254. ; Comparison with no exceptions
  255. (fmax-comp f "" 0)
  256. (fmax-comp u "" 0)
  257. (fmax-comp e "" 0)
  258. (fmax-comp ue "" 0)
  259. (fmax-comp l "" 0)
  260. (fmax-comp ul "" 0)
  261. (fmax-comp le "" 0)
  262. (fmax-comp ule "" 0)
  263. ; Comparison with exceptions
  264. (fmax-comp f i 1)
  265. (fmax-comp u i 1)
  266. (fmax-comp e i 1)
  267. (fmax-comp ue i 1)
  268. (fmax-comp l i 1)
  269. (fmax-comp ul i 1)
  270. (fmax-comp le i 1)
  271. (fmax-comp ule i 1)
  272. ;------------------------------------------------------------------------------
  273. ; Move to/from core registers
  274. (dni cmov-frn-rm
  275. "cmov FRn,Rm"
  276. (all-fmax-isas (INTRINSIC "cmov1"))
  277. "cmov ${fmax-FRd-int},${fmax-Rm}"
  278. (+ (f-fmax-0-4 #xF) fmax-FRd-int fmax-Rm (f-fmax-12-4 #x7)
  279. (f-fmax-16-4 #xF) (f-fmax-20-4 0) (f-fmax-24-4 0)
  280. (f-fmax-29-1 0) (f-fmax-30-1 0) (f-fmax-31-1 0))
  281. (set fmax-FRd-int fmax-Rm)
  282. ()
  283. )
  284. (dni cmov-rm-frn
  285. "cmov Rm,FRn"
  286. (all-fmax-isas (INTRINSIC "cmov2"))
  287. "cmov ${fmax-Rm},${fmax-FRd-int}"
  288. (+ (f-fmax-0-4 #xF) fmax-FRd-int fmax-Rm (f-fmax-12-4 #x7)
  289. (f-fmax-16-4 #xF) (f-fmax-20-4 0) (f-fmax-24-4 0)
  290. (f-fmax-29-1 0) (f-fmax-30-1 0) (f-fmax-31-1 1))
  291. (set fmax-Rm fmax-FRd-int)
  292. ()
  293. )
  294. (dni cmovc-ccrn-rm
  295. "cmovc CCRn,Rm"
  296. (all-fmax-isas (INTRINSIC "cmovc1"))
  297. "cmovc ${fmax-CCRn},${fmax-Rm}"
  298. (+ (f-fmax-0-4 #xF) fmax-CCRn fmax-Rm (f-fmax-12-4 #x7)
  299. (f-fmax-16-4 #xF) (f-fmax-20-4 0) (f-fmax-24-4 0)
  300. (f-fmax-28-1 0) (f-fmax-29-1 0) (f-fmax-30-1 1) (f-fmax-31-1 0))
  301. (set fmax-CCRn fmax-Rm)
  302. ()
  303. )
  304. (dni cmovc-rm-ccrn
  305. "cmovc Rm,CCRn"
  306. (all-fmax-isas (INTRINSIC "cmovc2"))
  307. "cmovc ${fmax-Rm},${fmax-CCRn}"
  308. (+ (f-fmax-0-4 #xF) fmax-CCRn fmax-Rm (f-fmax-12-4 #x7)
  309. (f-fmax-16-4 #xF) (f-fmax-20-4 0) (f-fmax-24-4 0)
  310. (f-fmax-28-1 0) (f-fmax-29-1 0) (f-fmax-30-1 1) (f-fmax-31-1 1))
  311. (set fmax-Rm fmax-CCRn)
  312. ()
  313. )