fpopcode.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. NetWinder Floating Point Emulator
  3. (c) Rebel.COM, 1998,1999
  4. Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  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 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #ifndef __FPOPCODE_H__
  18. #define __FPOPCODE_H__
  19. /*
  20. ARM Floating Point Instruction Classes
  21. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  22. |c o n d|1 1 0 P|U|u|W|L| Rn |v| Fd |0|0|0|1| o f f s e t | CPDT
  23. |c o n d|1 1 0 P|U|w|W|L| Rn |x| Fd |0|0|0|1| o f f s e t | CPDT
  24. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  25. |c o n d|1 1 1 0|a|b|c|d|e| Fn |j| Fd |0|0|0|1|f|g|h|0|i| Fm | CPDO
  26. |c o n d|1 1 1 0|a|b|c|L|e| Fn | Rd |0|0|0|1|f|g|h|1|i| Fm | CPRT
  27. |c o n d|1 1 1 0|a|b|c|1|e| Fn |1|1|1|1|0|0|0|1|f|g|h|1|i| Fm | comparisons
  28. | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
  29. CPDT data transfer instructions
  30. LDF, STF, LFM, SFM
  31. CPDO dyadic arithmetic instructions
  32. ADF, MUF, SUF, RSF, DVF, RDF,
  33. POW, RPW, RMF, FML, FDV, FRD, POL
  34. CPDO monadic arithmetic instructions
  35. MVF, MNF, ABS, RND, SQT, LOG, LGN, EXP,
  36. SIN, COS, TAN, ASN, ACS, ATN, URD, NRM
  37. CPRT joint arithmetic/data transfer instructions
  38. FIX (arithmetic followed by load/store)
  39. FLT (load/store followed by arithmetic)
  40. CMF, CNF CMFE, CNFE (comparisons)
  41. WFS, RFS (write/read floating point status register)
  42. WFC, RFC (write/read floating point control register)
  43. cond condition codes
  44. P pre/post index bit: 0 = postindex, 1 = preindex
  45. U up/down bit: 0 = stack grows down, 1 = stack grows up
  46. W write back bit: 1 = update base register (Rn)
  47. L load/store bit: 0 = store, 1 = load
  48. Rn base register
  49. Rd destination/source register
  50. Fd floating point destination register
  51. Fn floating point source register
  52. Fm floating point source register or floating point constant
  53. uv transfer length (TABLE 1)
  54. wx register count (TABLE 2)
  55. abcd arithmetic opcode (TABLES 3 & 4)
  56. ef destination size (rounding precision) (TABLE 5)
  57. gh rounding mode (TABLE 6)
  58. j dyadic/monadic bit: 0 = dyadic, 1 = monadic
  59. i constant bit: 1 = constant (TABLE 6)
  60. */
  61. /*
  62. TABLE 1
  63. +-------------------------+---+---+---------+---------+
  64. | Precision | u | v | FPSR.EP | length |
  65. +-------------------------+---+---+---------+---------+
  66. | Single | 0 ü 0 | x | 1 words |
  67. | Double | 1 ü 1 | x | 2 words |
  68. | Extended | 1 ü 1 | x | 3 words |
  69. | Packed decimal | 1 ü 1 | 0 | 3 words |
  70. | Expanded packed decimal | 1 ü 1 | 1 | 4 words |
  71. +-------------------------+---+---+---------+---------+
  72. Note: x = don't care
  73. */
  74. /*
  75. TABLE 2
  76. +---+---+---------------------------------+
  77. | w | x | Number of registers to transfer |
  78. +---+---+---------------------------------+
  79. | 0 ü 1 | 1 |
  80. | 1 ü 0 | 2 |
  81. | 1 ü 1 | 3 |
  82. | 0 ü 0 | 4 |
  83. +---+---+---------------------------------+
  84. */
  85. /*
  86. TABLE 3: Dyadic Floating Point Opcodes
  87. +---+---+---+---+----------+-----------------------+-----------------------+
  88. | a | b | c | d | Mnemonic | Description | Operation |
  89. +---+---+---+---+----------+-----------------------+-----------------------+
  90. | 0 | 0 | 0 | 0 | ADF | Add | Fd := Fn + Fm |
  91. | 0 | 0 | 0 | 1 | MUF | Multiply | Fd := Fn * Fm |
  92. | 0 | 0 | 1 | 0 | SUF | Subtract | Fd := Fn - Fm |
  93. | 0 | 0 | 1 | 1 | RSF | Reverse subtract | Fd := Fm - Fn |
  94. | 0 | 1 | 0 | 0 | DVF | Divide | Fd := Fn / Fm |
  95. | 0 | 1 | 0 | 1 | RDF | Reverse divide | Fd := Fm / Fn |
  96. | 0 | 1 | 1 | 0 | POW | Power | Fd := Fn ^ Fm |
  97. | 0 | 1 | 1 | 1 | RPW | Reverse power | Fd := Fm ^ Fn |
  98. | 1 | 0 | 0 | 0 | RMF | Remainder | Fd := IEEE rem(Fn/Fm) |
  99. | 1 | 0 | 0 | 1 | FML | Fast Multiply | Fd := Fn * Fm |
  100. | 1 | 0 | 1 | 0 | FDV | Fast Divide | Fd := Fn / Fm |
  101. | 1 | 0 | 1 | 1 | FRD | Fast reverse divide | Fd := Fm / Fn |
  102. | 1 | 1 | 0 | 0 | POL | Polar angle (ArcTan2) | Fd := arctan2(Fn,Fm) |
  103. | 1 | 1 | 0 | 1 | | undefined instruction | trap |
  104. | 1 | 1 | 1 | 0 | | undefined instruction | trap |
  105. | 1 | 1 | 1 | 1 | | undefined instruction | trap |
  106. +---+---+---+---+----------+-----------------------+-----------------------+
  107. Note: POW, RPW, POL are deprecated, and are available for backwards
  108. compatibility only.
  109. */
  110. /*
  111. TABLE 4: Monadic Floating Point Opcodes
  112. +---+---+---+---+----------+-----------------------+-----------------------+
  113. | a | b | c | d | Mnemonic | Description | Operation |
  114. +---+---+---+---+----------+-----------------------+-----------------------+
  115. | 0 | 0 | 0 | 0 | MVF | Move | Fd := Fm |
  116. | 0 | 0 | 0 | 1 | MNF | Move negated | Fd := - Fm |
  117. | 0 | 0 | 1 | 0 | ABS | Absolute value | Fd := abs(Fm) |
  118. | 0 | 0 | 1 | 1 | RND | Round to integer | Fd := int(Fm) |
  119. | 0 | 1 | 0 | 0 | SQT | Square root | Fd := sqrt(Fm) |
  120. | 0 | 1 | 0 | 1 | LOG | Log base 10 | Fd := log10(Fm) |
  121. | 0 | 1 | 1 | 0 | LGN | Log base e | Fd := ln(Fm) |
  122. | 0 | 1 | 1 | 1 | EXP | Exponent | Fd := e ^ Fm |
  123. | 1 | 0 | 0 | 0 | SIN | Sine | Fd := sin(Fm) |
  124. | 1 | 0 | 0 | 1 | COS | Cosine | Fd := cos(Fm) |
  125. | 1 | 0 | 1 | 0 | TAN | Tangent | Fd := tan(Fm) |
  126. | 1 | 0 | 1 | 1 | ASN | Arc Sine | Fd := arcsin(Fm) |
  127. | 1 | 1 | 0 | 0 | ACS | Arc Cosine | Fd := arccos(Fm) |
  128. | 1 | 1 | 0 | 1 | ATN | Arc Tangent | Fd := arctan(Fm) |
  129. | 1 | 1 | 1 | 0 | URD | Unnormalized round | Fd := int(Fm) |
  130. | 1 | 1 | 1 | 1 | NRM | Normalize | Fd := norm(Fm) |
  131. +---+---+---+---+----------+-----------------------+-----------------------+
  132. Note: LOG, LGN, EXP, SIN, COS, TAN, ASN, ACS, ATN are deprecated, and are
  133. available for backwards compatibility only.
  134. */
  135. /*
  136. TABLE 5
  137. +-------------------------+---+---+
  138. | Rounding Precision | e | f |
  139. +-------------------------+---+---+
  140. | IEEE Single precision | 0 ü 0 |
  141. | IEEE Double precision | 0 ü 1 |
  142. | IEEE Extended precision | 1 ü 0 |
  143. | undefined (trap) | 1 ü 1 |
  144. +-------------------------+---+---+
  145. */
  146. /*
  147. TABLE 5
  148. +---------------------------------+---+---+
  149. | Rounding Mode | g | h |
  150. +---------------------------------+---+---+
  151. | Round to nearest (default) | 0 ü 0 |
  152. | Round toward plus infinity | 0 ü 1 |
  153. | Round toward negative infinity | 1 ü 0 |
  154. | Round toward zero | 1 ü 1 |
  155. +---------------------------------+---+---+
  156. */
  157. /*
  158. ===
  159. === Definitions for load and store instructions
  160. ===
  161. */
  162. /* bit masks */
  163. #define BIT_PREINDEX 0x01000000
  164. #define BIT_UP 0x00800000
  165. #define BIT_WRITE_BACK 0x00200000
  166. #define BIT_LOAD 0x00100000
  167. /* masks for load/store */
  168. #define MASK_CPDT 0x0c000000 /* data processing opcode */
  169. #define MASK_OFFSET 0x000000ff
  170. #define MASK_TRANSFER_LENGTH 0x00408000
  171. #define MASK_REGISTER_COUNT MASK_TRANSFER_LENGTH
  172. #define MASK_COPROCESSOR 0x00000f00
  173. /* Tests for transfer length */
  174. #define TRANSFER_SINGLE 0x00000000
  175. #define TRANSFER_DOUBLE 0x00008000
  176. #define TRANSFER_EXTENDED 0x00400000
  177. #define TRANSFER_PACKED MASK_TRANSFER_LENGTH
  178. /* Get the coprocessor number from the opcode. */
  179. #define getCoprocessorNumber(opcode) ((opcode & MASK_COPROCESSOR) >> 8)
  180. /* Get the offset from the opcode. */
  181. #define getOffset(opcode) (opcode & MASK_OFFSET)
  182. /* Tests for specific data transfer load/store opcodes. */
  183. #define TEST_OPCODE(opcode,mask) (((opcode) & (mask)) == (mask))
  184. #define LOAD_OP(opcode) TEST_OPCODE((opcode),MASK_CPDT | BIT_LOAD)
  185. #define STORE_OP(opcode) ((opcode & (MASK_CPDT | BIT_LOAD)) == MASK_CPDT)
  186. #define LDF_OP(opcode) (LOAD_OP(opcode) && (getCoprocessorNumber(opcode) == 1))
  187. #define LFM_OP(opcode) (LOAD_OP(opcode) && (getCoprocessorNumber(opcode) == 2))
  188. #define STF_OP(opcode) (STORE_OP(opcode) && (getCoprocessorNumber(opcode) == 1))
  189. #define SFM_OP(opcode) (STORE_OP(opcode) && (getCoprocessorNumber(opcode) == 2))
  190. #define PREINDEXED(opcode) ((opcode & BIT_PREINDEX) != 0)
  191. #define POSTINDEXED(opcode) ((opcode & BIT_PREINDEX) == 0)
  192. #define BIT_UP_SET(opcode) ((opcode & BIT_UP) != 0)
  193. #define BIT_UP_CLEAR(opcode) ((opcode & BIT_DOWN) == 0)
  194. #define WRITE_BACK(opcode) ((opcode & BIT_WRITE_BACK) != 0)
  195. #define LOAD(opcode) ((opcode & BIT_LOAD) != 0)
  196. #define STORE(opcode) ((opcode & BIT_LOAD) == 0)
  197. /*
  198. ===
  199. === Definitions for arithmetic instructions
  200. ===
  201. */
  202. /* bit masks */
  203. #define BIT_MONADIC 0x00008000
  204. #define BIT_CONSTANT 0x00000008
  205. #define CONSTANT_FM(opcode) ((opcode & BIT_CONSTANT) != 0)
  206. #define MONADIC_INSTRUCTION(opcode) ((opcode & BIT_MONADIC) != 0)
  207. /* instruction identification masks */
  208. #define MASK_CPDO 0x0e000000 /* arithmetic opcode */
  209. #define MASK_ARITHMETIC_OPCODE 0x00f08000
  210. #define MASK_DESTINATION_SIZE 0x00080080
  211. /* dyadic arithmetic opcodes. */
  212. #define ADF_CODE 0x00000000
  213. #define MUF_CODE 0x00100000
  214. #define SUF_CODE 0x00200000
  215. #define RSF_CODE 0x00300000
  216. #define DVF_CODE 0x00400000
  217. #define RDF_CODE 0x00500000
  218. #define POW_CODE 0x00600000
  219. #define RPW_CODE 0x00700000
  220. #define RMF_CODE 0x00800000
  221. #define FML_CODE 0x00900000
  222. #define FDV_CODE 0x00a00000
  223. #define FRD_CODE 0x00b00000
  224. #define POL_CODE 0x00c00000
  225. /* 0x00d00000 is an invalid dyadic arithmetic opcode */
  226. /* 0x00e00000 is an invalid dyadic arithmetic opcode */
  227. /* 0x00f00000 is an invalid dyadic arithmetic opcode */
  228. /* monadic arithmetic opcodes. */
  229. #define MVF_CODE 0x00008000
  230. #define MNF_CODE 0x00108000
  231. #define ABS_CODE 0x00208000
  232. #define RND_CODE 0x00308000
  233. #define SQT_CODE 0x00408000
  234. #define LOG_CODE 0x00508000
  235. #define LGN_CODE 0x00608000
  236. #define EXP_CODE 0x00708000
  237. #define SIN_CODE 0x00808000
  238. #define COS_CODE 0x00908000
  239. #define TAN_CODE 0x00a08000
  240. #define ASN_CODE 0x00b08000
  241. #define ACS_CODE 0x00c08000
  242. #define ATN_CODE 0x00d08000
  243. #define URD_CODE 0x00e08000
  244. #define NRM_CODE 0x00f08000
  245. /*
  246. ===
  247. === Definitions for register transfer and comparison instructions
  248. ===
  249. */
  250. #define MASK_CPRT 0x0e000010 /* register transfer opcode */
  251. #define MASK_CPRT_CODE 0x00f00000
  252. #define FLT_CODE 0x00000000
  253. #define FIX_CODE 0x00100000
  254. #define WFS_CODE 0x00200000
  255. #define RFS_CODE 0x00300000
  256. #define WFC_CODE 0x00400000
  257. #define RFC_CODE 0x00500000
  258. #define CMF_CODE 0x00900000
  259. #define CNF_CODE 0x00b00000
  260. #define CMFE_CODE 0x00d00000
  261. #define CNFE_CODE 0x00f00000
  262. /*
  263. ===
  264. === Common definitions
  265. ===
  266. */
  267. /* register masks */
  268. #define MASK_Rd 0x0000f000
  269. #define MASK_Rn 0x000f0000
  270. #define MASK_Fd 0x00007000
  271. #define MASK_Fm 0x00000007
  272. #define MASK_Fn 0x00070000
  273. /* condition code masks */
  274. #define CC_MASK 0xf0000000
  275. #define CC_NEGATIVE 0x80000000
  276. #define CC_ZERO 0x40000000
  277. #define CC_CARRY 0x20000000
  278. #define CC_OVERFLOW 0x10000000
  279. #define CC_EQ 0x00000000
  280. #define CC_NE 0x10000000
  281. #define CC_CS 0x20000000
  282. #define CC_HS CC_CS
  283. #define CC_CC 0x30000000
  284. #define CC_LO CC_CC
  285. #define CC_MI 0x40000000
  286. #define CC_PL 0x50000000
  287. #define CC_VS 0x60000000
  288. #define CC_VC 0x70000000
  289. #define CC_HI 0x80000000
  290. #define CC_LS 0x90000000
  291. #define CC_GE 0xa0000000
  292. #define CC_LT 0xb0000000
  293. #define CC_GT 0xc0000000
  294. #define CC_LE 0xd0000000
  295. #define CC_AL 0xe0000000
  296. #define CC_NV 0xf0000000
  297. /* rounding masks/values */
  298. #define MASK_ROUNDING_MODE 0x00000060
  299. #define ROUND_TO_NEAREST 0x00000000
  300. #define ROUND_TO_PLUS_INFINITY 0x00000020
  301. #define ROUND_TO_MINUS_INFINITY 0x00000040
  302. #define ROUND_TO_ZERO 0x00000060
  303. #define MASK_ROUNDING_PRECISION 0x00080080
  304. #define ROUND_SINGLE 0x00000000
  305. #define ROUND_DOUBLE 0x00000080
  306. #define ROUND_EXTENDED 0x00080000
  307. /* Get the condition code from the opcode. */
  308. #define getCondition(opcode) (opcode >> 28)
  309. /* Get the source register from the opcode. */
  310. #define getRn(opcode) ((opcode & MASK_Rn) >> 16)
  311. /* Get the destination floating point register from the opcode. */
  312. #define getFd(opcode) ((opcode & MASK_Fd) >> 12)
  313. /* Get the first source floating point register from the opcode. */
  314. #define getFn(opcode) ((opcode & MASK_Fn) >> 16)
  315. /* Get the second source floating point register from the opcode. */
  316. #define getFm(opcode) (opcode & MASK_Fm)
  317. /* Get the destination register from the opcode. */
  318. #define getRd(opcode) ((opcode & MASK_Rd) >> 12)
  319. /* Get the rounding mode from the opcode. */
  320. #define getRoundingMode(opcode) ((opcode & MASK_ROUNDING_MODE) >> 5)
  321. static inline const floatx80 getExtendedConstant(const unsigned int nIndex)
  322. {
  323. extern const floatx80 floatx80Constant[];
  324. return floatx80Constant[nIndex];
  325. }
  326. static inline const float64 getDoubleConstant(const unsigned int nIndex)
  327. {
  328. extern const float64 float64Constant[];
  329. return float64Constant[nIndex];
  330. }
  331. static inline const float32 getSingleConstant(const unsigned int nIndex)
  332. {
  333. extern const float32 float32Constant[];
  334. return float32Constant[nIndex];
  335. }
  336. extern unsigned int getRegisterCount(const unsigned int opcode);
  337. extern unsigned int getDestinationSize(const unsigned int opcode);
  338. #endif