float.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  3. *
  4. * Floating-point emulation code
  5. * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*
  22. * BEGIN_DESC
  23. *
  24. * File:
  25. * @(#) pa/spmath/float.h $Revision: 1.1 $
  26. *
  27. * Purpose:
  28. * <<please update with a synopis of the functionality provided by this file>>
  29. *
  30. * BE header: no
  31. *
  32. * Shipped: yes
  33. * /usr/conf/pa/spmath/float.h
  34. *
  35. * END_DESC
  36. */
  37. #ifdef __NO_PA_HDRS
  38. PA header file -- do not include this header file for non-PA builds.
  39. #endif
  40. #include "fpbits.h"
  41. #include "hppa.h"
  42. /*
  43. * Want to pick up the FPU capability flags, not the PDC structures.
  44. * 'LOCORE' isn't really true in this case, but we don't want the C structures
  45. * so it suits our purposes
  46. */
  47. #define LOCORE
  48. #include "fpu.h"
  49. /*
  50. * Declare the basic structures for the 3 different
  51. * floating-point precisions.
  52. *
  53. * Single number
  54. * +-------+-------+-------+-------+-------+-------+-------+-------+
  55. * |s| exp | mantissa |
  56. * +-------+-------+-------+-------+-------+-------+-------+-------+
  57. */
  58. #define Sall(object) (object)
  59. #define Ssign(object) Bitfield_extract( 0, 1,object)
  60. #define Ssignedsign(object) Bitfield_signed_extract( 0, 1,object)
  61. #define Sexponent(object) Bitfield_extract( 1, 8,object)
  62. #define Smantissa(object) Bitfield_mask( 9, 23,object)
  63. #define Ssignaling(object) Bitfield_extract( 9, 1,object)
  64. #define Ssignalingnan(object) Bitfield_extract( 1, 9,object)
  65. #define Shigh2mantissa(object) Bitfield_extract( 9, 2,object)
  66. #define Sexponentmantissa(object) Bitfield_mask( 1, 31,object)
  67. #define Ssignexponent(object) Bitfield_extract( 0, 9,object)
  68. #define Shidden(object) Bitfield_extract( 8, 1,object)
  69. #define Shiddenoverflow(object) Bitfield_extract( 7, 1,object)
  70. #define Shiddenhigh7mantissa(object) Bitfield_extract( 8, 8,object)
  71. #define Shiddenhigh3mantissa(object) Bitfield_extract( 8, 4,object)
  72. #define Slow(object) Bitfield_mask( 31, 1,object)
  73. #define Slow4(object) Bitfield_mask( 28, 4,object)
  74. #define Slow31(object) Bitfield_mask( 1, 31,object)
  75. #define Shigh31(object) Bitfield_extract( 0, 31,object)
  76. #define Ssignedhigh31(object) Bitfield_signed_extract( 0, 31,object)
  77. #define Shigh4(object) Bitfield_extract( 0, 4,object)
  78. #define Sbit24(object) Bitfield_extract( 24, 1,object)
  79. #define Sbit28(object) Bitfield_extract( 28, 1,object)
  80. #define Sbit29(object) Bitfield_extract( 29, 1,object)
  81. #define Sbit30(object) Bitfield_extract( 30, 1,object)
  82. #define Sbit31(object) Bitfield_mask( 31, 1,object)
  83. #define Deposit_ssign(object,value) Bitfield_deposit(value,0,1,object)
  84. #define Deposit_sexponent(object,value) Bitfield_deposit(value,1,8,object)
  85. #define Deposit_smantissa(object,value) Bitfield_deposit(value,9,23,object)
  86. #define Deposit_shigh2mantissa(object,value) Bitfield_deposit(value,9,2,object)
  87. #define Deposit_sexponentmantissa(object,value) \
  88. Bitfield_deposit(value,1,31,object)
  89. #define Deposit_ssignexponent(object,value) Bitfield_deposit(value,0,9,object)
  90. #define Deposit_slow(object,value) Bitfield_deposit(value,31,1,object)
  91. #define Deposit_shigh4(object,value) Bitfield_deposit(value,0,4,object)
  92. #define Is_ssign(object) Bitfield_mask( 0, 1,object)
  93. #define Is_ssignaling(object) Bitfield_mask( 9, 1,object)
  94. #define Is_shidden(object) Bitfield_mask( 8, 1,object)
  95. #define Is_shiddenoverflow(object) Bitfield_mask( 7, 1,object)
  96. #define Is_slow(object) Bitfield_mask( 31, 1,object)
  97. #define Is_sbit24(object) Bitfield_mask( 24, 1,object)
  98. #define Is_sbit28(object) Bitfield_mask( 28, 1,object)
  99. #define Is_sbit29(object) Bitfield_mask( 29, 1,object)
  100. #define Is_sbit30(object) Bitfield_mask( 30, 1,object)
  101. #define Is_sbit31(object) Bitfield_mask( 31, 1,object)
  102. /*
  103. * Double number.
  104. * +-------+-------+-------+-------+-------+-------+-------+-------+
  105. * |s| exponent | mantissa part 1 |
  106. * +-------+-------+-------+-------+-------+-------+-------+-------+
  107. *
  108. * +-------+-------+-------+-------+-------+-------+-------+-------+
  109. * | mantissa part 2 |
  110. * +-------+-------+-------+-------+-------+-------+-------+-------+
  111. */
  112. #define Dallp1(object) (object)
  113. #define Dsign(object) Bitfield_extract( 0, 1,object)
  114. #define Dsignedsign(object) Bitfield_signed_extract( 0, 1,object)
  115. #define Dexponent(object) Bitfield_extract( 1, 11,object)
  116. #define Dmantissap1(object) Bitfield_mask( 12, 20,object)
  117. #define Dsignaling(object) Bitfield_extract( 12, 1,object)
  118. #define Dsignalingnan(object) Bitfield_extract( 1, 12,object)
  119. #define Dhigh2mantissa(object) Bitfield_extract( 12, 2,object)
  120. #define Dexponentmantissap1(object) Bitfield_mask( 1, 31,object)
  121. #define Dsignexponent(object) Bitfield_extract( 0, 12,object)
  122. #define Dhidden(object) Bitfield_extract( 11, 1,object)
  123. #define Dhiddenoverflow(object) Bitfield_extract( 10, 1,object)
  124. #define Dhiddenhigh7mantissa(object) Bitfield_extract( 11, 8,object)
  125. #define Dhiddenhigh3mantissa(object) Bitfield_extract( 11, 4,object)
  126. #define Dlowp1(object) Bitfield_mask( 31, 1,object)
  127. #define Dlow31p1(object) Bitfield_mask( 1, 31,object)
  128. #define Dhighp1(object) Bitfield_extract( 0, 1,object)
  129. #define Dhigh4p1(object) Bitfield_extract( 0, 4,object)
  130. #define Dhigh31p1(object) Bitfield_extract( 0, 31,object)
  131. #define Dsignedhigh31p1(object) Bitfield_signed_extract( 0, 31,object)
  132. #define Dbit3p1(object) Bitfield_extract( 3, 1,object)
  133. #define Deposit_dsign(object,value) Bitfield_deposit(value,0,1,object)
  134. #define Deposit_dexponent(object,value) Bitfield_deposit(value,1,11,object)
  135. #define Deposit_dmantissap1(object,value) Bitfield_deposit(value,12,20,object)
  136. #define Deposit_dhigh2mantissa(object,value) Bitfield_deposit(value,12,2,object)
  137. #define Deposit_dexponentmantissap1(object,value) \
  138. Bitfield_deposit(value,1,31,object)
  139. #define Deposit_dsignexponent(object,value) Bitfield_deposit(value,0,12,object)
  140. #define Deposit_dlowp1(object,value) Bitfield_deposit(value,31,1,object)
  141. #define Deposit_dhigh4p1(object,value) Bitfield_deposit(value,0,4,object)
  142. #define Is_dsign(object) Bitfield_mask( 0, 1,object)
  143. #define Is_dsignaling(object) Bitfield_mask( 12, 1,object)
  144. #define Is_dhidden(object) Bitfield_mask( 11, 1,object)
  145. #define Is_dhiddenoverflow(object) Bitfield_mask( 10, 1,object)
  146. #define Is_dlowp1(object) Bitfield_mask( 31, 1,object)
  147. #define Is_dhighp1(object) Bitfield_mask( 0, 1,object)
  148. #define Is_dbit3p1(object) Bitfield_mask( 3, 1,object)
  149. #define Dallp2(object) (object)
  150. #define Dmantissap2(object) (object)
  151. #define Dlowp2(object) Bitfield_mask( 31, 1,object)
  152. #define Dlow4p2(object) Bitfield_mask( 28, 4,object)
  153. #define Dlow31p2(object) Bitfield_mask( 1, 31,object)
  154. #define Dhighp2(object) Bitfield_extract( 0, 1,object)
  155. #define Dhigh31p2(object) Bitfield_extract( 0, 31,object)
  156. #define Dbit2p2(object) Bitfield_extract( 2, 1,object)
  157. #define Dbit3p2(object) Bitfield_extract( 3, 1,object)
  158. #define Dbit21p2(object) Bitfield_extract( 21, 1,object)
  159. #define Dbit28p2(object) Bitfield_extract( 28, 1,object)
  160. #define Dbit29p2(object) Bitfield_extract( 29, 1,object)
  161. #define Dbit30p2(object) Bitfield_extract( 30, 1,object)
  162. #define Dbit31p2(object) Bitfield_mask( 31, 1,object)
  163. #define Deposit_dlowp2(object,value) Bitfield_deposit(value,31,1,object)
  164. #define Is_dlowp2(object) Bitfield_mask( 31, 1,object)
  165. #define Is_dhighp2(object) Bitfield_mask( 0, 1,object)
  166. #define Is_dbit2p2(object) Bitfield_mask( 2, 1,object)
  167. #define Is_dbit3p2(object) Bitfield_mask( 3, 1,object)
  168. #define Is_dbit21p2(object) Bitfield_mask( 21, 1,object)
  169. #define Is_dbit28p2(object) Bitfield_mask( 28, 1,object)
  170. #define Is_dbit29p2(object) Bitfield_mask( 29, 1,object)
  171. #define Is_dbit30p2(object) Bitfield_mask( 30, 1,object)
  172. #define Is_dbit31p2(object) Bitfield_mask( 31, 1,object)
  173. /*
  174. * Quad number.
  175. * +-------+-------+-------+-------+-------+-------+-------+-------+
  176. * |s| exponent | mantissa part 1 |
  177. * +-------+-------+-------+-------+-------+-------+-------+-------+
  178. *
  179. * +-------+-------+-------+-------+-------+-------+-------+-------+
  180. * | mantissa part 2 |
  181. * +-------+-------+-------+-------+-------+-------+-------+-------+
  182. *
  183. * +-------+-------+-------+-------+-------+-------+-------+-------+
  184. * | mantissa part 3 |
  185. * +-------+-------+-------+-------+-------+-------+-------+-------+
  186. *
  187. * +-------+-------+-------+-------+-------+-------+-------+-------+
  188. * | mantissa part 4 |
  189. * +-------+-------+-------+-------+-------+-------+-------+-------+
  190. */
  191. typedef struct
  192. {
  193. union
  194. {
  195. struct { unsigned qallp1; } u_qallp1;
  196. /* Not needed for now...
  197. Bitfield_extract( 0, 1,u_qsign,qsign)
  198. Bitfield_signed_extract( 0, 1,u_qsignedsign,qsignedsign)
  199. Bitfield_extract( 1, 15,u_qexponent,qexponent)
  200. Bitfield_extract(16, 16,u_qmantissap1,qmantissap1)
  201. Bitfield_extract(16, 1,u_qsignaling,qsignaling)
  202. Bitfield_extract(1, 16,u_qsignalingnan,qsignalingnan)
  203. Bitfield_extract(16, 2,u_qhigh2mantissa,qhigh2mantissa)
  204. Bitfield_extract( 1, 31,u_qexponentmantissap1,qexponentmantissap1)
  205. Bitfield_extract( 0, 16,u_qsignexponent,qsignexponent)
  206. Bitfield_extract(15, 1,u_qhidden,qhidden)
  207. Bitfield_extract(14, 1,u_qhiddenoverflow,qhiddenoverflow)
  208. Bitfield_extract(15, 8,u_qhiddenhigh7mantissa,qhiddenhigh7mantissa)
  209. Bitfield_extract(15, 4,u_qhiddenhigh3mantissa,qhiddenhigh3mantissa)
  210. Bitfield_extract(31, 1,u_qlowp1,qlowp1)
  211. Bitfield_extract( 1, 31,u_qlow31p1,qlow31p1)
  212. Bitfield_extract( 0, 1,u_qhighp1,qhighp1)
  213. Bitfield_extract( 0, 4,u_qhigh4p1,qhigh4p1)
  214. Bitfield_extract( 0, 31,u_qhigh31p1,qhigh31p1)
  215. */
  216. } quad_u1;
  217. union
  218. {
  219. struct { unsigned qallp2; } u_qallp2;
  220. /* Not needed for now...
  221. Bitfield_extract(31, 1,u_qlowp2,qlowp2)
  222. Bitfield_extract( 1, 31,u_qlow31p2,qlow31p2)
  223. Bitfield_extract( 0, 1,u_qhighp2,qhighp2)
  224. Bitfield_extract( 0, 31,u_qhigh31p2,qhigh31p2)
  225. */
  226. } quad_u2;
  227. union
  228. {
  229. struct { unsigned qallp3; } u_qallp3;
  230. /* Not needed for now...
  231. Bitfield_extract(31, 1,u_qlowp3,qlowp3)
  232. Bitfield_extract( 1, 31,u_qlow31p3,qlow31p3)
  233. Bitfield_extract( 0, 1,u_qhighp3,qhighp3)
  234. Bitfield_extract( 0, 31,u_qhigh31p3,qhigh31p3)
  235. */
  236. } quad_u3;
  237. union
  238. {
  239. struct { unsigned qallp4; } u_qallp4;
  240. /* Not need for now...
  241. Bitfield_extract(31, 1,u_qlowp4,qlowp4)
  242. Bitfield_extract( 1, 31,u_qlow31p4,qlow31p4)
  243. Bitfield_extract( 0, 1,u_qhighp4,qhighp4)
  244. Bitfield_extract( 0, 31,u_qhigh31p4,qhigh31p4)
  245. */
  246. } quad_u4;
  247. } quad_floating_point;
  248. /* Extension - An additional structure to hold the guard, round and
  249. * sticky bits during computations.
  250. */
  251. #define Extall(object) (object)
  252. #define Extsign(object) Bitfield_extract( 0, 1,object)
  253. #define Exthigh31(object) Bitfield_extract( 0, 31,object)
  254. #define Extlow31(object) Bitfield_extract( 1, 31,object)
  255. #define Extlow(object) Bitfield_extract( 31, 1,object)
  256. /*
  257. * Single extended - The upper word is just like single precision,
  258. * but one additional word of mantissa is needed.
  259. */
  260. #define Sextallp1(object) (object)
  261. #define Sextallp2(object) (object)
  262. #define Sextlowp1(object) Bitfield_extract( 31, 1,object)
  263. #define Sexthighp2(object) Bitfield_extract( 0, 1,object)
  264. #define Sextlow31p2(object) Bitfield_extract( 1, 31,object)
  265. #define Sexthiddenoverflow(object) Bitfield_extract( 4, 1,object)
  266. #define Is_sexthiddenoverflow(object) Bitfield_mask( 4, 1,object)
  267. /*
  268. * Double extended - The upper two words are just like double precision,
  269. * but two additional words of mantissa are needed.
  270. */
  271. #define Dextallp1(object) (object)
  272. #define Dextallp2(object) (object)
  273. #define Dextallp3(object) (object)
  274. #define Dextallp4(object) (object)
  275. #define Dextlowp2(object) Bitfield_extract( 31, 1,object)
  276. #define Dexthighp3(object) Bitfield_extract( 0, 1,object)
  277. #define Dextlow31p3(object) Bitfield_extract( 1, 31,object)
  278. #define Dexthiddenoverflow(object) Bitfield_extract( 10, 1,object)
  279. #define Is_dexthiddenoverflow(object) Bitfield_mask( 10, 1,object)
  280. #define Deposit_dextlowp4(object,value) Bitfield_deposit(value,31,1,object)
  281. /*
  282. * Declare the basic structures for the 3 different
  283. * fixed-point precisions.
  284. *
  285. * Single number
  286. * +-------+-------+-------+-------+-------+-------+-------+-------+
  287. * |s| integer |
  288. * +-------+-------+-------+-------+-------+-------+-------+-------+
  289. */
  290. typedef int sgl_integer;
  291. /*
  292. * Double number.
  293. * +-------+-------+-------+-------+-------+-------+-------+-------+
  294. * |s| high integer |
  295. * +-------+-------+-------+-------+-------+-------+-------+-------+
  296. *
  297. * +-------+-------+-------+-------+-------+-------+-------+-------+
  298. * | low integer |
  299. * +-------+-------+-------+-------+-------+-------+-------+-------+
  300. */
  301. struct dint {
  302. int wd0;
  303. unsigned int wd1;
  304. };
  305. struct dblwd {
  306. unsigned int wd0;
  307. unsigned int wd1;
  308. };
  309. /*
  310. * Quad number.
  311. * +-------+-------+-------+-------+-------+-------+-------+-------+
  312. * |s| integer part1 |
  313. * +-------+-------+-------+-------+-------+-------+-------+-------+
  314. *
  315. * +-------+-------+-------+-------+-------+-------+-------+-------+
  316. * | integer part 2 |
  317. * +-------+-------+-------+-------+-------+-------+-------+-------+
  318. *
  319. * +-------+-------+-------+-------+-------+-------+-------+-------+
  320. * | integer part 3 |
  321. * +-------+-------+-------+-------+-------+-------+-------+-------+
  322. *
  323. * +-------+-------+-------+-------+-------+-------+-------+-------+
  324. * | integer part 4 |
  325. * +-------+-------+-------+-------+-------+-------+-------+-------+
  326. */
  327. struct quadwd {
  328. int wd0;
  329. unsigned int wd1;
  330. unsigned int wd2;
  331. unsigned int wd3;
  332. };
  333. typedef struct quadwd quad_integer;
  334. /* useful typedefs */
  335. typedef unsigned int sgl_floating_point;
  336. typedef struct dblwd dbl_floating_point;
  337. typedef struct dint dbl_integer;
  338. typedef struct dblwd dbl_unsigned;
  339. /*
  340. * Define the different precisions' parameters.
  341. */
  342. #define SGL_BITLENGTH 32
  343. #define SGL_EMAX 127
  344. #define SGL_EMIN (-126)
  345. #define SGL_BIAS 127
  346. #define SGL_WRAP 192
  347. #define SGL_INFINITY_EXPONENT (SGL_EMAX+SGL_BIAS+1)
  348. #define SGL_THRESHOLD 32
  349. #define SGL_EXP_LENGTH 8
  350. #define SGL_P 24
  351. #define DBL_BITLENGTH 64
  352. #define DBL_EMAX 1023
  353. #define DBL_EMIN (-1022)
  354. #define DBL_BIAS 1023
  355. #define DBL_WRAP 1536
  356. #define DBL_INFINITY_EXPONENT (DBL_EMAX+DBL_BIAS+1)
  357. #define DBL_THRESHOLD 64
  358. #define DBL_EXP_LENGTH 11
  359. #define DBL_P 53
  360. #define QUAD_BITLENGTH 128
  361. #define QUAD_EMAX 16383
  362. #define QUAD_EMIN (-16382)
  363. #define QUAD_BIAS 16383
  364. #define QUAD_WRAP 24576
  365. #define QUAD_INFINITY_EXPONENT (QUAD_EMAX+QUAD_BIAS+1)
  366. #define QUAD_P 113
  367. /* Boolean Values etc. */
  368. #define FALSE 0
  369. #define TRUE (!FALSE)
  370. #define NOT !
  371. #define XOR ^
  372. /* other constants */
  373. #undef NULL
  374. #define NULL 0
  375. #define NIL 0
  376. #define SGL 0
  377. #define DBL 1
  378. #define BADFMT 2
  379. #define QUAD 3
  380. /* Types */
  381. typedef int boolean;
  382. typedef int FORMAT;
  383. typedef int VOID;
  384. /* Declare status register equivalent to FPUs architecture.
  385. *
  386. * 0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
  387. * +-------+-------+-------+-------+-------+-------+-------+-------+
  388. * |V|Z|O|U|I|C| rsv | model | version |RM |rsv|T|r|V|Z|O|U|I|
  389. * +-------+-------+-------+-------+-------+-------+-------+-------+
  390. */
  391. #define Cbit(object) Bitfield_extract( 5, 1,object)
  392. #define Tbit(object) Bitfield_extract( 25, 1,object)
  393. #define Roundingmode(object) Bitfield_extract( 21, 2,object)
  394. #define Invalidtrap(object) Bitfield_extract( 27, 1,object)
  395. #define Divisionbyzerotrap(object) Bitfield_extract( 28, 1,object)
  396. #define Overflowtrap(object) Bitfield_extract( 29, 1,object)
  397. #define Underflowtrap(object) Bitfield_extract( 30, 1,object)
  398. #define Inexacttrap(object) Bitfield_extract( 31, 1,object)
  399. #define Invalidflag(object) Bitfield_extract( 0, 1,object)
  400. #define Divisionbyzeroflag(object) Bitfield_extract( 1, 1,object)
  401. #define Overflowflag(object) Bitfield_extract( 2, 1,object)
  402. #define Underflowflag(object) Bitfield_extract( 3, 1,object)
  403. #define Inexactflag(object) Bitfield_extract( 4, 1,object)
  404. #define Allflags(object) Bitfield_extract( 0, 5,object)
  405. /* Definitions relevant to the status register */
  406. /* Rounding Modes */
  407. #define ROUNDNEAREST 0
  408. #define ROUNDZERO 1
  409. #define ROUNDPLUS 2
  410. #define ROUNDMINUS 3
  411. /* Exceptions */
  412. #define NOEXCEPTION 0x0
  413. #define INVALIDEXCEPTION 0x20
  414. #define DIVISIONBYZEROEXCEPTION 0x10
  415. #define OVERFLOWEXCEPTION 0x08
  416. #define UNDERFLOWEXCEPTION 0x04
  417. #define INEXACTEXCEPTION 0x02
  418. #define UNIMPLEMENTEDEXCEPTION 0x01
  419. /* New exceptions for the 2E Opcode */
  420. #define OPC_2E_INVALIDEXCEPTION 0x30
  421. #define OPC_2E_OVERFLOWEXCEPTION 0x18
  422. #define OPC_2E_UNDERFLOWEXCEPTION 0x0c
  423. #define OPC_2E_INEXACTEXCEPTION 0x12
  424. /* Declare exception registers equivalent to FPUs architecture
  425. *
  426. * 0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
  427. * +-------+-------+-------+-------+-------+-------+-------+-------+
  428. * |excepttype | r1 | r2/ext | operation |parm |n| t/cond |
  429. * +-------+-------+-------+-------+-------+-------+-------+-------+
  430. */
  431. #define Allexception(object) (object)
  432. #define Exceptiontype(object) Bitfield_extract( 0, 6,object)
  433. #define Instructionfield(object) Bitfield_mask( 6,26,object)
  434. #define Parmfield(object) Bitfield_extract( 23, 3,object)
  435. #define Rabit(object) Bitfield_extract( 24, 1,object)
  436. #define Ibit(object) Bitfield_extract( 25, 1,object)
  437. #define Set_exceptiontype(object,value) Bitfield_deposit(value, 0, 6,object)
  438. #define Set_parmfield(object,value) Bitfield_deposit(value, 23, 3,object)
  439. #define Set_exceptiontype_and_instr_field(exception,instruction,object) \
  440. object = exception << 26 | instruction
  441. /* Declare the condition field
  442. *
  443. * 0 1 2 3 4 5 6 7 8 910 1 2 3 4 5 6 7 8 920 1 2 3 4 5 6 7 8 930 1
  444. * +-------+-------+-------+-------+-------+-------+-------+-------+
  445. * | |G|L|E|U|X|
  446. * +-------+-------+-------+-------+-------+-------+-------+-------+
  447. */
  448. #define Greaterthanbit(object) Bitfield_extract( 27, 1,object)
  449. #define Lessthanbit(object) Bitfield_extract( 28, 1,object)
  450. #define Equalbit(object) Bitfield_extract( 29, 1,object)
  451. #define Unorderedbit(object) Bitfield_extract( 30, 1,object)
  452. #define Exceptionbit(object) Bitfield_extract( 31, 1,object)
  453. /* An alias name for the status register */
  454. #define Fpustatus_register (*status)
  455. /**************************************************
  456. * Status register referencing and manipulation. *
  457. **************************************************/
  458. /* Rounding mode */
  459. #define Rounding_mode() Roundingmode(Fpustatus_register)
  460. #define Is_rounding_mode(rmode) \
  461. (Roundingmode(Fpustatus_register) == rmode)
  462. #define Set_rounding_mode(value) \
  463. Bitfield_deposit(value,21,2,Fpustatus_register)
  464. /* Boolean testing of the trap enable bits */
  465. #define Is_invalidtrap_enabled() Invalidtrap(Fpustatus_register)
  466. #define Is_divisionbyzerotrap_enabled() Divisionbyzerotrap(Fpustatus_register)
  467. #define Is_overflowtrap_enabled() Overflowtrap(Fpustatus_register)
  468. #define Is_underflowtrap_enabled() Underflowtrap(Fpustatus_register)
  469. #define Is_inexacttrap_enabled() Inexacttrap(Fpustatus_register)
  470. /* Set the indicated flags in the status register */
  471. #define Set_invalidflag() Bitfield_deposit(1,0,1,Fpustatus_register)
  472. #define Set_divisionbyzeroflag() Bitfield_deposit(1,1,1,Fpustatus_register)
  473. #define Set_overflowflag() Bitfield_deposit(1,2,1,Fpustatus_register)
  474. #define Set_underflowflag() Bitfield_deposit(1,3,1,Fpustatus_register)
  475. #define Set_inexactflag() Bitfield_deposit(1,4,1,Fpustatus_register)
  476. #define Clear_all_flags() Bitfield_deposit(0,0,5,Fpustatus_register)
  477. /* Manipulate the trap and condition code bits (tbit and cbit) */
  478. #define Set_tbit() Bitfield_deposit(1,25,1,Fpustatus_register)
  479. #define Clear_tbit() Bitfield_deposit(0,25,1,Fpustatus_register)
  480. #define Is_tbit_set() Tbit(Fpustatus_register)
  481. #define Is_cbit_set() Cbit(Fpustatus_register)
  482. #define Set_status_cbit(value) \
  483. Bitfield_deposit(value,5,1,Fpustatus_register)
  484. /*******************************
  485. * Condition field referencing *
  486. *******************************/
  487. #define Unordered(cond) Unorderedbit(cond)
  488. #define Equal(cond) Equalbit(cond)
  489. #define Lessthan(cond) Lessthanbit(cond)
  490. #define Greaterthan(cond) Greaterthanbit(cond)
  491. #define Exception(cond) Exceptionbit(cond)
  492. /* Defines for the extension */
  493. #define Ext_isone_sign(extent) (Extsign(extent))
  494. #define Ext_isnotzero(extent) \
  495. (Extall(extent))
  496. #define Ext_isnotzero_lower(extent) \
  497. (Extlow31(extent))
  498. #define Ext_leftshiftby1(extent) \
  499. Extall(extent) <<= 1
  500. #define Ext_negate(extent) \
  501. (int )Extall(extent) = 0 - (int )Extall(extent)
  502. #define Ext_setone_low(extent) Bitfield_deposit(1,31,1,extent)
  503. #define Ext_setzero(extent) Extall(extent) = 0
  504. typedef int operation;
  505. /* error messages */
  506. #define NONE 0
  507. #define UNDEFFPINST 1
  508. /* Function definitions: opcode, opclass */
  509. #define FTEST (1<<2) | 0
  510. #define FCPY (2<<2) | 0
  511. #define FABS (3<<2) | 0
  512. #define FSQRT (4<<2) | 0
  513. #define FRND (5<<2) | 0
  514. #define FCNVFF (0<<2) | 1
  515. #define FCNVXF (1<<2) | 1
  516. #define FCNVFX (2<<2) | 1
  517. #define FCNVFXT (3<<2) | 1
  518. #define FCMP (0<<2) | 2
  519. #define FADD (0<<2) | 3
  520. #define FSUB (1<<2) | 3
  521. #define FMPY (2<<2) | 3
  522. #define FDIV (3<<2) | 3
  523. #define FREM (4<<2) | 3