fpopcode.h 15 KB

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