vfpsingle.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. vfp/vfpsingle.c - ARM VFPv3 emulation unit - SoftFloat single instruction
  3. Copyright (C) 2003 Skyeye Develop Group
  4. for help please send mail to <skyeye-developer@lists.gro.clinux.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /*
  18. * This code is derived in part from :
  19. * - Android kernel
  20. * - John R. Housers softfloat library, which
  21. * carries the following notice:
  22. *
  23. * ===========================================================================
  24. * This C source file is part of the SoftFloat IEC/IEEE Floating-point
  25. * Arithmetic Package, Release 2.
  26. *
  27. * Written by John R. Hauser. This work was made possible in part by the
  28. * International Computer Science Institute, located at Suite 600, 1947 Center
  29. * Street, Berkeley, California 94704. Funding was partially provided by the
  30. * National Science Foundation under grant MIP-9311980. The original version
  31. * of this code was written as part of a project to build a fixed-point vector
  32. * processor in collaboration with the University of California at Berkeley,
  33. * overseen by Profs. Nelson Morgan and John Wawrzynek. More information
  34. * is available through the web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
  35. * arithmetic/softfloat.html'.
  36. *
  37. * THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
  38. * has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
  39. * TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
  40. * PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
  41. * AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
  42. *
  43. * Derivative works are acceptable, even for commercial purposes, so long as
  44. * (1) they include prominent notice that the work is derivative, and (2) they
  45. * include prominent notice akin to these three paragraphs for those parts of
  46. * this code that are retained.
  47. * ===========================================================================
  48. */
  49. #include "core/arm/interpreter/vfp/vfp_helper.h"
  50. #include "core/arm/interpreter/vfp/asm_vfp.h"
  51. #include "core/arm/interpreter/vfp/vfp.h"
  52. static struct vfp_single vfp_single_default_qnan = {
  53. //.exponent = 255,
  54. //.sign = 0,
  55. //.significand = VFP_SINGLE_SIGNIFICAND_QNAN,
  56. };
  57. static void vfp_single_dump(const char *str, struct vfp_single *s)
  58. {
  59. pr_debug("VFP: %s: sign=%d exponent=%d significand=%08x\n",
  60. str, s->sign != 0, s->exponent, s->significand);
  61. }
  62. static void vfp_single_normalise_denormal(struct vfp_single *vs)
  63. {
  64. int bits = 31 - fls(vs->significand);
  65. vfp_single_dump("normalise_denormal: in", vs);
  66. if (bits) {
  67. vs->exponent -= bits - 1;
  68. vs->significand <<= bits;
  69. }
  70. vfp_single_dump("normalise_denormal: out", vs);
  71. }
  72. u32 vfp_single_normaliseround(ARMul_State* state, int sd, struct vfp_single *vs, u32 fpscr, u32 exceptions, const char *func)
  73. {
  74. u32 significand, incr, rmode;
  75. int exponent, shift, underflow;
  76. vfp_single_dump("pack: in", vs);
  77. /*
  78. * Infinities and NaNs are a special case.
  79. */
  80. if (vs->exponent == 255 && (vs->significand == 0 || exceptions))
  81. goto pack;
  82. /*
  83. * Special-case zero.
  84. */
  85. if (vs->significand == 0) {
  86. vs->exponent = 0;
  87. goto pack;
  88. }
  89. exponent = vs->exponent;
  90. significand = vs->significand;
  91. /*
  92. * Normalise first. Note that we shift the significand up to
  93. * bit 31, so we have VFP_SINGLE_LOW_BITS + 1 below the least
  94. * significant bit.
  95. */
  96. shift = 32 - fls(significand);
  97. if (shift < 32 && shift) {
  98. exponent -= shift;
  99. significand <<= shift;
  100. }
  101. #if 1
  102. vs->exponent = exponent;
  103. vs->significand = significand;
  104. vfp_single_dump("pack: normalised", vs);
  105. #endif
  106. /*
  107. * Tiny number?
  108. */
  109. underflow = exponent < 0;
  110. if (underflow) {
  111. significand = vfp_shiftright32jamming(significand, -exponent);
  112. exponent = 0;
  113. #if 1
  114. vs->exponent = exponent;
  115. vs->significand = significand;
  116. vfp_single_dump("pack: tiny number", vs);
  117. #endif
  118. if (!(significand & ((1 << (VFP_SINGLE_LOW_BITS + 1)) - 1)))
  119. underflow = 0;
  120. }
  121. /*
  122. * Select rounding increment.
  123. */
  124. incr = 0;
  125. rmode = fpscr & FPSCR_RMODE_MASK;
  126. if (rmode == FPSCR_ROUND_NEAREST) {
  127. incr = 1 << VFP_SINGLE_LOW_BITS;
  128. if ((significand & (1 << (VFP_SINGLE_LOW_BITS + 1))) == 0)
  129. incr -= 1;
  130. } else if (rmode == FPSCR_ROUND_TOZERO) {
  131. incr = 0;
  132. } else if ((rmode == FPSCR_ROUND_PLUSINF) ^ (vs->sign != 0))
  133. incr = (1 << (VFP_SINGLE_LOW_BITS + 1)) - 1;
  134. pr_debug("VFP: rounding increment = 0x%08x\n", incr);
  135. /*
  136. * Is our rounding going to overflow?
  137. */
  138. if ((significand + incr) < significand) {
  139. exponent += 1;
  140. significand = (significand >> 1) | (significand & 1);
  141. incr >>= 1;
  142. #if 1
  143. vs->exponent = exponent;
  144. vs->significand = significand;
  145. vfp_single_dump("pack: overflow", vs);
  146. #endif
  147. }
  148. /*
  149. * If any of the low bits (which will be shifted out of the
  150. * number) are non-zero, the result is inexact.
  151. */
  152. if (significand & ((1 << (VFP_SINGLE_LOW_BITS + 1)) - 1))
  153. exceptions |= FPSCR_IXC;
  154. /*
  155. * Do our rounding.
  156. */
  157. significand += incr;
  158. /*
  159. * Infinity?
  160. */
  161. if (exponent >= 254) {
  162. exceptions |= FPSCR_OFC | FPSCR_IXC;
  163. if (incr == 0) {
  164. vs->exponent = 253;
  165. vs->significand = 0x7fffffff;
  166. } else {
  167. vs->exponent = 255; /* infinity */
  168. vs->significand = 0;
  169. }
  170. } else {
  171. if (significand >> (VFP_SINGLE_LOW_BITS + 1) == 0)
  172. exponent = 0;
  173. if (exponent || significand > 0x80000000)
  174. underflow = 0;
  175. if (underflow)
  176. exceptions |= FPSCR_UFC;
  177. vs->exponent = exponent;
  178. vs->significand = significand >> 1;
  179. }
  180. pack:
  181. vfp_single_dump("pack: final", vs);
  182. {
  183. s32 d = vfp_single_pack(vs);
  184. #if 1
  185. pr_debug("VFP: %s: d(s%d)=%08x exceptions=%08x\n", func,
  186. sd, d, exceptions);
  187. #endif
  188. vfp_put_float(state, d, sd);
  189. }
  190. return exceptions;
  191. }
  192. /*
  193. * Propagate the NaN, setting exceptions if it is signalling.
  194. * 'n' is always a NaN. 'm' may be a number, NaN or infinity.
  195. */
  196. static u32
  197. vfp_propagate_nan(struct vfp_single *vsd, struct vfp_single *vsn,
  198. struct vfp_single *vsm, u32 fpscr)
  199. {
  200. struct vfp_single *nan;
  201. int tn, tm = 0;
  202. tn = vfp_single_type(vsn);
  203. if (vsm)
  204. tm = vfp_single_type(vsm);
  205. if (fpscr & FPSCR_DEFAULT_NAN)
  206. /*
  207. * Default NaN mode - always returns a quiet NaN
  208. */
  209. nan = &vfp_single_default_qnan;
  210. else {
  211. /*
  212. * Contemporary mode - select the first signalling
  213. * NAN, or if neither are signalling, the first
  214. * quiet NAN.
  215. */
  216. if (tn == VFP_SNAN || (tm != VFP_SNAN && tn == VFP_QNAN))
  217. nan = vsn;
  218. else
  219. nan = vsm;
  220. /*
  221. * Make the NaN quiet.
  222. */
  223. nan->significand |= VFP_SINGLE_SIGNIFICAND_QNAN;
  224. }
  225. *vsd = *nan;
  226. /*
  227. * If one was a signalling NAN, raise invalid operation.
  228. */
  229. return tn == VFP_SNAN || tm == VFP_SNAN ? FPSCR_IOC : VFP_NAN_FLAG;
  230. }
  231. /*
  232. * Extended operations
  233. */
  234. static u32 vfp_single_fabs(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  235. {
  236. vfp_put_float(state, vfp_single_packed_abs(m), sd);
  237. return 0;
  238. }
  239. static u32 vfp_single_fcpy(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  240. {
  241. vfp_put_float(state, m, sd);
  242. return 0;
  243. }
  244. static u32 vfp_single_fneg(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  245. {
  246. vfp_put_float(state, vfp_single_packed_negate(m), sd);
  247. return 0;
  248. }
  249. static const u16 sqrt_oddadjust[] = {
  250. 0x0004, 0x0022, 0x005d, 0x00b1, 0x011d, 0x019f, 0x0236, 0x02e0,
  251. 0x039c, 0x0468, 0x0545, 0x0631, 0x072b, 0x0832, 0x0946, 0x0a67
  252. };
  253. static const u16 sqrt_evenadjust[] = {
  254. 0x0a2d, 0x08af, 0x075a, 0x0629, 0x051a, 0x0429, 0x0356, 0x029e,
  255. 0x0200, 0x0179, 0x0109, 0x00af, 0x0068, 0x0034, 0x0012, 0x0002
  256. };
  257. u32 vfp_estimate_sqrt_significand(u32 exponent, u32 significand)
  258. {
  259. int index;
  260. u32 z, a;
  261. if ((significand & 0xc0000000) != 0x40000000) {
  262. pr_debug("VFP: estimate_sqrt: invalid significand\n");
  263. }
  264. a = significand << 1;
  265. index = (a >> 27) & 15;
  266. if (exponent & 1) {
  267. z = 0x4000 + (a >> 17) - sqrt_oddadjust[index];
  268. z = ((a / z) << 14) + (z << 15);
  269. a >>= 1;
  270. } else {
  271. z = 0x8000 + (a >> 17) - sqrt_evenadjust[index];
  272. z = a / z + z;
  273. z = (z >= 0x20000) ? 0xffff8000 : (z << 15);
  274. if (z <= a)
  275. return (s32)a >> 1;
  276. }
  277. {
  278. u64 v = (u64)a << 31;
  279. do_div(v, z);
  280. return v + (z >> 1);
  281. }
  282. }
  283. static u32 vfp_single_fsqrt(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  284. {
  285. struct vfp_single vsm, vsd, *vsp;
  286. int ret, tm;
  287. vfp_single_unpack(&vsm, m);
  288. tm = vfp_single_type(&vsm);
  289. if (tm & (VFP_NAN|VFP_INFINITY)) {
  290. vsp = &vsd;
  291. if (tm & VFP_NAN)
  292. ret = vfp_propagate_nan(vsp, &vsm, NULL, fpscr);
  293. else if (vsm.sign == 0) {
  294. sqrt_copy:
  295. vsp = &vsm;
  296. ret = 0;
  297. } else {
  298. sqrt_invalid:
  299. vsp = &vfp_single_default_qnan;
  300. ret = FPSCR_IOC;
  301. }
  302. vfp_put_float(state, vfp_single_pack(vsp), sd);
  303. return ret;
  304. }
  305. /*
  306. * sqrt(+/- 0) == +/- 0
  307. */
  308. if (tm & VFP_ZERO)
  309. goto sqrt_copy;
  310. /*
  311. * Normalise a denormalised number
  312. */
  313. if (tm & VFP_DENORMAL)
  314. vfp_single_normalise_denormal(&vsm);
  315. /*
  316. * sqrt(<0) = invalid
  317. */
  318. if (vsm.sign)
  319. goto sqrt_invalid;
  320. vfp_single_dump("sqrt", &vsm);
  321. /*
  322. * Estimate the square root.
  323. */
  324. vsd.sign = 0;
  325. vsd.exponent = ((vsm.exponent - 127) >> 1) + 127;
  326. vsd.significand = vfp_estimate_sqrt_significand(vsm.exponent, vsm.significand) + 2;
  327. vfp_single_dump("sqrt estimate", &vsd);
  328. /*
  329. * And now adjust.
  330. */
  331. if ((vsd.significand & VFP_SINGLE_LOW_BITS_MASK) <= 5) {
  332. if (vsd.significand < 2) {
  333. vsd.significand = 0xffffffff;
  334. } else {
  335. u64 term;
  336. s64 rem;
  337. vsm.significand <<= !(vsm.exponent & 1);
  338. term = (u64)vsd.significand * vsd.significand;
  339. rem = ((u64)vsm.significand << 32) - term;
  340. pr_debug("VFP: term=%016llx rem=%016llx\n", term, rem);
  341. while (rem < 0) {
  342. vsd.significand -= 1;
  343. rem += ((u64)vsd.significand << 1) | 1;
  344. }
  345. vsd.significand |= rem != 0;
  346. }
  347. }
  348. vsd.significand = vfp_shiftright32jamming(vsd.significand, 1);
  349. return vfp_single_normaliseround(state, sd, &vsd, fpscr, 0, "fsqrt");
  350. }
  351. /*
  352. * Equal := ZC
  353. * Less than := N
  354. * Greater than := C
  355. * Unordered := CV
  356. */
  357. static u32 vfp_compare(ARMul_State* state, int sd, int signal_on_qnan, s32 m, u32 fpscr)
  358. {
  359. s32 d;
  360. u32 ret = 0;
  361. d = vfp_get_float(state, sd);
  362. if (vfp_single_packed_exponent(m) == 255 && vfp_single_packed_mantissa(m)) {
  363. ret |= FPSCR_C | FPSCR_V;
  364. if (signal_on_qnan || !(vfp_single_packed_mantissa(m) & (1 << (VFP_SINGLE_MANTISSA_BITS - 1))))
  365. /*
  366. * Signalling NaN, or signalling on quiet NaN
  367. */
  368. ret |= FPSCR_IOC;
  369. }
  370. if (vfp_single_packed_exponent(d) == 255 && vfp_single_packed_mantissa(d)) {
  371. ret |= FPSCR_C | FPSCR_V;
  372. if (signal_on_qnan || !(vfp_single_packed_mantissa(d) & (1 << (VFP_SINGLE_MANTISSA_BITS - 1))))
  373. /*
  374. * Signalling NaN, or signalling on quiet NaN
  375. */
  376. ret |= FPSCR_IOC;
  377. }
  378. if (ret == 0) {
  379. if (d == m || vfp_single_packed_abs(d | m) == 0) {
  380. /*
  381. * equal
  382. */
  383. ret |= FPSCR_Z | FPSCR_C;
  384. } else if (vfp_single_packed_sign(d ^ m)) {
  385. /*
  386. * different signs
  387. */
  388. if (vfp_single_packed_sign(d))
  389. /*
  390. * d is negative, so d < m
  391. */
  392. ret |= FPSCR_N;
  393. else
  394. /*
  395. * d is positive, so d > m
  396. */
  397. ret |= FPSCR_C;
  398. } else if ((vfp_single_packed_sign(d) != 0) ^ (d < m)) {
  399. /*
  400. * d < m
  401. */
  402. ret |= FPSCR_N;
  403. } else if ((vfp_single_packed_sign(d) != 0) ^ (d > m)) {
  404. /*
  405. * d > m
  406. */
  407. ret |= FPSCR_C;
  408. }
  409. }
  410. return ret;
  411. }
  412. static u32 vfp_single_fcmp(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  413. {
  414. return vfp_compare(state, sd, 0, m, fpscr);
  415. }
  416. static u32 vfp_single_fcmpe(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  417. {
  418. return vfp_compare(state, sd, 1, m, fpscr);
  419. }
  420. static u32 vfp_single_fcmpz(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  421. {
  422. return vfp_compare(state, sd, 0, 0, fpscr);
  423. }
  424. static u32 vfp_single_fcmpez(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  425. {
  426. return vfp_compare(state, sd, 1, 0, fpscr);
  427. }
  428. static u32 vfp_single_fcvtd(ARMul_State* state, int dd, int unused, s32 m, u32 fpscr)
  429. {
  430. struct vfp_single vsm;
  431. struct vfp_double vdd;
  432. int tm;
  433. u32 exceptions = 0;
  434. vfp_single_unpack(&vsm, m);
  435. tm = vfp_single_type(&vsm);
  436. /*
  437. * If we have a signalling NaN, signal invalid operation.
  438. */
  439. if (tm == VFP_SNAN)
  440. exceptions = FPSCR_IOC;
  441. if (tm & VFP_DENORMAL)
  442. vfp_single_normalise_denormal(&vsm);
  443. vdd.sign = vsm.sign;
  444. vdd.significand = (u64)vsm.significand << 32;
  445. /*
  446. * If we have an infinity or NaN, the exponent must be 2047.
  447. */
  448. if (tm & (VFP_INFINITY|VFP_NAN)) {
  449. vdd.exponent = 2047;
  450. if (tm == VFP_QNAN)
  451. vdd.significand |= VFP_DOUBLE_SIGNIFICAND_QNAN;
  452. goto pack_nan;
  453. } else if (tm & VFP_ZERO)
  454. vdd.exponent = 0;
  455. else
  456. vdd.exponent = vsm.exponent + (1023 - 127);
  457. return vfp_double_normaliseround(state, dd, &vdd, fpscr, exceptions, "fcvtd");
  458. pack_nan:
  459. vfp_put_double(state, vfp_double_pack(&vdd), dd);
  460. return exceptions;
  461. }
  462. static u32 vfp_single_fuito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  463. {
  464. struct vfp_single vs;
  465. vs.sign = 0;
  466. vs.exponent = 127 + 31 - 1;
  467. vs.significand = (u32)m;
  468. return vfp_single_normaliseround(state, sd, &vs, fpscr, 0, "fuito");
  469. }
  470. static u32 vfp_single_fsito(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  471. {
  472. struct vfp_single vs;
  473. vs.sign = (m & 0x80000000) >> 16;
  474. vs.exponent = 127 + 31 - 1;
  475. vs.significand = vs.sign ? -m : m;
  476. return vfp_single_normaliseround(state, sd, &vs, fpscr, 0, "fsito");
  477. }
  478. static u32 vfp_single_ftoui(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  479. {
  480. struct vfp_single vsm;
  481. u32 d, exceptions = 0;
  482. int rmode = fpscr & FPSCR_RMODE_MASK;
  483. int tm;
  484. vfp_single_unpack(&vsm, m);
  485. vfp_single_dump("VSM", &vsm);
  486. /*
  487. * Do we have a denormalised number?
  488. */
  489. tm = vfp_single_type(&vsm);
  490. if (tm & VFP_DENORMAL)
  491. exceptions |= FPSCR_IDC;
  492. if (tm & VFP_NAN)
  493. vsm.sign = 0;
  494. if (vsm.exponent >= 127 + 32) {
  495. d = vsm.sign ? 0 : 0xffffffff;
  496. exceptions = FPSCR_IOC;
  497. } else if (vsm.exponent >= 127 - 1) {
  498. int shift = 127 + 31 - vsm.exponent;
  499. u32 rem, incr = 0;
  500. /*
  501. * 2^0 <= m < 2^32-2^8
  502. */
  503. d = (vsm.significand << 1) >> shift;
  504. rem = vsm.significand << (33 - shift);
  505. if (rmode == FPSCR_ROUND_NEAREST) {
  506. incr = 0x80000000;
  507. if ((d & 1) == 0)
  508. incr -= 1;
  509. } else if (rmode == FPSCR_ROUND_TOZERO) {
  510. incr = 0;
  511. } else if ((rmode == FPSCR_ROUND_PLUSINF) ^ (vsm.sign != 0)) {
  512. incr = ~0;
  513. }
  514. if ((rem + incr) < rem) {
  515. if (d < 0xffffffff)
  516. d += 1;
  517. else
  518. exceptions |= FPSCR_IOC;
  519. }
  520. if (d && vsm.sign) {
  521. d = 0;
  522. exceptions |= FPSCR_IOC;
  523. } else if (rem)
  524. exceptions |= FPSCR_IXC;
  525. } else {
  526. d = 0;
  527. if (vsm.exponent | vsm.significand) {
  528. exceptions |= FPSCR_IXC;
  529. if (rmode == FPSCR_ROUND_PLUSINF && vsm.sign == 0)
  530. d = 1;
  531. else if (rmode == FPSCR_ROUND_MINUSINF && vsm.sign) {
  532. d = 0;
  533. exceptions |= FPSCR_IOC;
  534. }
  535. }
  536. }
  537. pr_debug("VFP: ftoui: d(s%d)=%08x exceptions=%08x\n", sd, d, exceptions);
  538. vfp_put_float(state, d, sd);
  539. return exceptions;
  540. }
  541. static u32 vfp_single_ftouiz(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  542. {
  543. return vfp_single_ftoui(state, sd, unused, m, FPSCR_ROUND_TOZERO);
  544. }
  545. static u32 vfp_single_ftosi(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  546. {
  547. struct vfp_single vsm;
  548. u32 d, exceptions = 0;
  549. int rmode = fpscr & FPSCR_RMODE_MASK;
  550. int tm;
  551. vfp_single_unpack(&vsm, m);
  552. vfp_single_dump("VSM", &vsm);
  553. /*
  554. * Do we have a denormalised number?
  555. */
  556. tm = vfp_single_type(&vsm);
  557. if (vfp_single_type(&vsm) & VFP_DENORMAL)
  558. exceptions |= FPSCR_IDC;
  559. if (tm & VFP_NAN) {
  560. d = 0;
  561. exceptions |= FPSCR_IOC;
  562. } else if (vsm.exponent >= 127 + 32) {
  563. /*
  564. * m >= 2^31-2^7: invalid
  565. */
  566. d = 0x7fffffff;
  567. if (vsm.sign)
  568. d = ~d;
  569. exceptions |= FPSCR_IOC;
  570. } else if (vsm.exponent >= 127 - 1) {
  571. int shift = 127 + 31 - vsm.exponent;
  572. u32 rem, incr = 0;
  573. /* 2^0 <= m <= 2^31-2^7 */
  574. d = (vsm.significand << 1) >> shift;
  575. rem = vsm.significand << (33 - shift);
  576. if (rmode == FPSCR_ROUND_NEAREST) {
  577. incr = 0x80000000;
  578. if ((d & 1) == 0)
  579. incr -= 1;
  580. } else if (rmode == FPSCR_ROUND_TOZERO) {
  581. incr = 0;
  582. } else if ((rmode == FPSCR_ROUND_PLUSINF) ^ (vsm.sign != 0)) {
  583. incr = ~0;
  584. }
  585. if ((rem + incr) < rem && d < 0xffffffff)
  586. d += 1;
  587. if (d > 0x7fffffff + (vsm.sign != 0)) {
  588. d = 0x7fffffff + (vsm.sign != 0);
  589. exceptions |= FPSCR_IOC;
  590. } else if (rem)
  591. exceptions |= FPSCR_IXC;
  592. if (vsm.sign)
  593. d = -d;
  594. } else {
  595. d = 0;
  596. if (vsm.exponent | vsm.significand) {
  597. exceptions |= FPSCR_IXC;
  598. if (rmode == FPSCR_ROUND_PLUSINF && vsm.sign == 0)
  599. d = 1;
  600. else if (rmode == FPSCR_ROUND_MINUSINF && vsm.sign)
  601. d = -1;
  602. }
  603. }
  604. pr_debug("VFP: ftosi: d(s%d)=%08x exceptions=%08x\n", sd, d, exceptions);
  605. vfp_put_float(state, (s32)d, sd);
  606. return exceptions;
  607. }
  608. static u32 vfp_single_ftosiz(ARMul_State* state, int sd, int unused, s32 m, u32 fpscr)
  609. {
  610. return vfp_single_ftosi(state, sd, unused, m, FPSCR_ROUND_TOZERO);
  611. }
  612. static struct op fops_ext[] = {
  613. { vfp_single_fcpy, 0 }, //0x00000000 - FEXT_FCPY
  614. { vfp_single_fabs, 0 }, //0x00000001 - FEXT_FABS
  615. { vfp_single_fneg, 0 }, //0x00000002 - FEXT_FNEG
  616. { vfp_single_fsqrt, 0 }, //0x00000003 - FEXT_FSQRT
  617. { NULL, 0 },
  618. { NULL, 0 },
  619. { NULL, 0 },
  620. { NULL, 0 },
  621. { vfp_single_fcmp, OP_SCALAR }, //0x00000008 - FEXT_FCMP
  622. { vfp_single_fcmpe, OP_SCALAR }, //0x00000009 - FEXT_FCMPE
  623. { vfp_single_fcmpz, OP_SCALAR }, //0x0000000A - FEXT_FCMPZ
  624. { vfp_single_fcmpez, OP_SCALAR }, //0x0000000B - FEXT_FCMPEZ
  625. { NULL, 0 },
  626. { NULL, 0 },
  627. { NULL, 0 },
  628. { vfp_single_fcvtd, OP_SCALAR|OP_DD }, //0x0000000F - FEXT_FCVT
  629. { vfp_single_fuito, OP_SCALAR }, //0x00000010 - FEXT_FUITO
  630. { vfp_single_fsito, OP_SCALAR }, //0x00000011 - FEXT_FSITO
  631. { NULL, 0 },
  632. { NULL, 0 },
  633. { NULL, 0 },
  634. { NULL, 0 },
  635. { NULL, 0 },
  636. { NULL, 0 },
  637. { vfp_single_ftoui, OP_SCALAR }, //0x00000018 - FEXT_FTOUI
  638. { vfp_single_ftouiz, OP_SCALAR }, //0x00000019 - FEXT_FTOUIZ
  639. { vfp_single_ftosi, OP_SCALAR }, //0x0000001A - FEXT_FTOSI
  640. { vfp_single_ftosiz, OP_SCALAR }, //0x0000001B - FEXT_FTOSIZ
  641. };
  642. static u32
  643. vfp_single_fadd_nonnumber(struct vfp_single *vsd, struct vfp_single *vsn,
  644. struct vfp_single *vsm, u32 fpscr)
  645. {
  646. struct vfp_single *vsp;
  647. u32 exceptions = 0;
  648. int tn, tm;
  649. tn = vfp_single_type(vsn);
  650. tm = vfp_single_type(vsm);
  651. if (tn & tm & VFP_INFINITY) {
  652. /*
  653. * Two infinities. Are they different signs?
  654. */
  655. if (vsn->sign ^ vsm->sign) {
  656. /*
  657. * different signs -> invalid
  658. */
  659. exceptions = FPSCR_IOC;
  660. vsp = &vfp_single_default_qnan;
  661. } else {
  662. /*
  663. * same signs -> valid
  664. */
  665. vsp = vsn;
  666. }
  667. } else if (tn & VFP_INFINITY && tm & VFP_NUMBER) {
  668. /*
  669. * One infinity and one number -> infinity
  670. */
  671. vsp = vsn;
  672. } else {
  673. /*
  674. * 'n' is a NaN of some type
  675. */
  676. return vfp_propagate_nan(vsd, vsn, vsm, fpscr);
  677. }
  678. *vsd = *vsp;
  679. return exceptions;
  680. }
  681. static u32
  682. vfp_single_add(struct vfp_single *vsd, struct vfp_single *vsn,
  683. struct vfp_single *vsm, u32 fpscr)
  684. {
  685. u32 exp_diff, m_sig;
  686. if (vsn->significand & 0x80000000 ||
  687. vsm->significand & 0x80000000) {
  688. pr_info("VFP: bad FP values\n");
  689. vfp_single_dump("VSN", vsn);
  690. vfp_single_dump("VSM", vsm);
  691. }
  692. /*
  693. * Ensure that 'n' is the largest magnitude number. Note that
  694. * if 'n' and 'm' have equal exponents, we do not swap them.
  695. * This ensures that NaN propagation works correctly.
  696. */
  697. if (vsn->exponent < vsm->exponent) {
  698. struct vfp_single *t = vsn;
  699. vsn = vsm;
  700. vsm = t;
  701. }
  702. /*
  703. * Is 'n' an infinity or a NaN? Note that 'm' may be a number,
  704. * infinity or a NaN here.
  705. */
  706. if (vsn->exponent == 255)
  707. return vfp_single_fadd_nonnumber(vsd, vsn, vsm, fpscr);
  708. /*
  709. * We have two proper numbers, where 'vsn' is the larger magnitude.
  710. *
  711. * Copy 'n' to 'd' before doing the arithmetic.
  712. */
  713. *vsd = *vsn;
  714. /*
  715. * Align both numbers.
  716. */
  717. exp_diff = vsn->exponent - vsm->exponent;
  718. m_sig = vfp_shiftright32jamming(vsm->significand, exp_diff);
  719. /*
  720. * If the signs are different, we are really subtracting.
  721. */
  722. if (vsn->sign ^ vsm->sign) {
  723. m_sig = vsn->significand - m_sig;
  724. if ((s32)m_sig < 0) {
  725. vsd->sign = vfp_sign_negate(vsd->sign);
  726. m_sig = -m_sig;
  727. } else if (m_sig == 0) {
  728. vsd->sign = (fpscr & FPSCR_RMODE_MASK) ==
  729. FPSCR_ROUND_MINUSINF ? 0x8000 : 0;
  730. }
  731. } else {
  732. m_sig = vsn->significand + m_sig;
  733. }
  734. vsd->significand = m_sig;
  735. return 0;
  736. }
  737. static u32
  738. vfp_single_multiply(struct vfp_single *vsd, struct vfp_single *vsn, struct vfp_single *vsm, u32 fpscr)
  739. {
  740. vfp_single_dump("VSN", vsn);
  741. vfp_single_dump("VSM", vsm);
  742. /*
  743. * Ensure that 'n' is the largest magnitude number. Note that
  744. * if 'n' and 'm' have equal exponents, we do not swap them.
  745. * This ensures that NaN propagation works correctly.
  746. */
  747. if (vsn->exponent < vsm->exponent) {
  748. struct vfp_single *t = vsn;
  749. vsn = vsm;
  750. vsm = t;
  751. pr_debug("VFP: swapping M <-> N\n");
  752. }
  753. vsd->sign = vsn->sign ^ vsm->sign;
  754. /*
  755. * If 'n' is an infinity or NaN, handle it. 'm' may be anything.
  756. */
  757. if (vsn->exponent == 255) {
  758. if (vsn->significand || (vsm->exponent == 255 && vsm->significand))
  759. return vfp_propagate_nan(vsd, vsn, vsm, fpscr);
  760. if ((vsm->exponent | vsm->significand) == 0) {
  761. *vsd = vfp_single_default_qnan;
  762. return FPSCR_IOC;
  763. }
  764. vsd->exponent = vsn->exponent;
  765. vsd->significand = 0;
  766. return 0;
  767. }
  768. /*
  769. * If 'm' is zero, the result is always zero. In this case,
  770. * 'n' may be zero or a number, but it doesn't matter which.
  771. */
  772. if ((vsm->exponent | vsm->significand) == 0) {
  773. vsd->exponent = 0;
  774. vsd->significand = 0;
  775. return 0;
  776. }
  777. /*
  778. * We add 2 to the destination exponent for the same reason as
  779. * the addition case - though this time we have +1 from each
  780. * input operand.
  781. */
  782. vsd->exponent = vsn->exponent + vsm->exponent - 127 + 2;
  783. vsd->significand = vfp_hi64to32jamming((u64)vsn->significand * vsm->significand);
  784. vfp_single_dump("VSD", vsd);
  785. return 0;
  786. }
  787. #define NEG_MULTIPLY (1 << 0)
  788. #define NEG_SUBTRACT (1 << 1)
  789. static u32
  790. vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr, u32 negate, char *func)
  791. {
  792. struct vfp_single vsd, vsp, vsn, vsm;
  793. u32 exceptions;
  794. s32 v;
  795. v = vfp_get_float(state, sn);
  796. pr_debug("VFP: s%u = %08x\n", sn, v);
  797. vfp_single_unpack(&vsn, v);
  798. if (vsn.exponent == 0 && vsn.significand)
  799. vfp_single_normalise_denormal(&vsn);
  800. vfp_single_unpack(&vsm, m);
  801. if (vsm.exponent == 0 && vsm.significand)
  802. vfp_single_normalise_denormal(&vsm);
  803. exceptions = vfp_single_multiply(&vsp, &vsn, &vsm, fpscr);
  804. if (negate & NEG_MULTIPLY)
  805. vsp.sign = vfp_sign_negate(vsp.sign);
  806. v = vfp_get_float(state, sd);
  807. pr_debug("VFP: s%u = %08x\n", sd, v);
  808. vfp_single_unpack(&vsn, v);
  809. if (negate & NEG_SUBTRACT)
  810. vsn.sign = vfp_sign_negate(vsn.sign);
  811. exceptions |= vfp_single_add(&vsd, &vsn, &vsp, fpscr);
  812. return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, func);
  813. }
  814. /*
  815. * Standard operations
  816. */
  817. /*
  818. * sd = sd + (sn * sm)
  819. */
  820. static u32 vfp_single_fmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  821. {
  822. pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd);
  823. return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac");
  824. }
  825. /*
  826. * sd = sd - (sn * sm)
  827. */
  828. static u32 vfp_single_fnmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  829. {
  830. pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sd, sn);
  831. return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_MULTIPLY, "fnmac");
  832. }
  833. /*
  834. * sd = -sd + (sn * sm)
  835. */
  836. static u32 vfp_single_fmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  837. {
  838. pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd);
  839. return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_SUBTRACT, "fmsc");
  840. }
  841. /*
  842. * sd = -sd - (sn * sm)
  843. */
  844. static u32 vfp_single_fnmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  845. {
  846. pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd);
  847. return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_SUBTRACT | NEG_MULTIPLY, "fnmsc");
  848. }
  849. /*
  850. * sd = sn * sm
  851. */
  852. static u32 vfp_single_fmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  853. {
  854. struct vfp_single vsd, vsn, vsm;
  855. u32 exceptions;
  856. s32 n = vfp_get_float(state, sn);
  857. pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, n);
  858. vfp_single_unpack(&vsn, n);
  859. if (vsn.exponent == 0 && vsn.significand)
  860. vfp_single_normalise_denormal(&vsn);
  861. vfp_single_unpack(&vsm, m);
  862. if (vsm.exponent == 0 && vsm.significand)
  863. vfp_single_normalise_denormal(&vsm);
  864. exceptions = vfp_single_multiply(&vsd, &vsn, &vsm, fpscr);
  865. return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fmul");
  866. }
  867. /*
  868. * sd = -(sn * sm)
  869. */
  870. static u32 vfp_single_fnmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  871. {
  872. struct vfp_single vsd, vsn, vsm;
  873. u32 exceptions;
  874. s32 n = vfp_get_float(state, sn);
  875. pr_debug("VFP: s%u = %08x\n", sn, n);
  876. vfp_single_unpack(&vsn, n);
  877. if (vsn.exponent == 0 && vsn.significand)
  878. vfp_single_normalise_denormal(&vsn);
  879. vfp_single_unpack(&vsm, m);
  880. if (vsm.exponent == 0 && vsm.significand)
  881. vfp_single_normalise_denormal(&vsm);
  882. exceptions = vfp_single_multiply(&vsd, &vsn, &vsm, fpscr);
  883. vsd.sign = vfp_sign_negate(vsd.sign);
  884. return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fnmul");
  885. }
  886. /*
  887. * sd = sn + sm
  888. */
  889. static u32 vfp_single_fadd(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  890. {
  891. struct vfp_single vsd, vsn, vsm;
  892. u32 exceptions;
  893. s32 n = vfp_get_float(state, sn);
  894. pr_debug("VFP: s%u = %08x\n", sn, n);
  895. /*
  896. * Unpack and normalise denormals.
  897. */
  898. vfp_single_unpack(&vsn, n);
  899. if (vsn.exponent == 0 && vsn.significand)
  900. vfp_single_normalise_denormal(&vsn);
  901. vfp_single_unpack(&vsm, m);
  902. if (vsm.exponent == 0 && vsm.significand)
  903. vfp_single_normalise_denormal(&vsm);
  904. exceptions = vfp_single_add(&vsd, &vsn, &vsm, fpscr);
  905. return vfp_single_normaliseround(state, sd, &vsd, fpscr, exceptions, "fadd");
  906. }
  907. /*
  908. * sd = sn - sm
  909. */
  910. static u32 vfp_single_fsub(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  911. {
  912. pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd);
  913. /*
  914. * Subtraction is addition with one sign inverted.
  915. */
  916. return vfp_single_fadd(state, sd, sn, vfp_single_packed_negate(m), fpscr);
  917. }
  918. /*
  919. * sd = sn / sm
  920. */
  921. static u32 vfp_single_fdiv(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr)
  922. {
  923. struct vfp_single vsd, vsn, vsm;
  924. u32 exceptions = 0;
  925. s32 n = vfp_get_float(state, sn);
  926. int tm, tn;
  927. pr_debug("VFP: s%u = %08x\n", sn, n);
  928. vfp_single_unpack(&vsn, n);
  929. vfp_single_unpack(&vsm, m);
  930. vsd.sign = vsn.sign ^ vsm.sign;
  931. tn = vfp_single_type(&vsn);
  932. tm = vfp_single_type(&vsm);
  933. /*
  934. * Is n a NAN?
  935. */
  936. if (tn & VFP_NAN)
  937. goto vsn_nan;
  938. /*
  939. * Is m a NAN?
  940. */
  941. if (tm & VFP_NAN)
  942. goto vsm_nan;
  943. /*
  944. * If n and m are infinity, the result is invalid
  945. * If n and m are zero, the result is invalid
  946. */
  947. if (tm & tn & (VFP_INFINITY|VFP_ZERO))
  948. goto invalid;
  949. /*
  950. * If n is infinity, the result is infinity
  951. */
  952. if (tn & VFP_INFINITY)
  953. goto infinity;
  954. /*
  955. * If m is zero, raise div0 exception
  956. */
  957. if (tm & VFP_ZERO)
  958. goto divzero;
  959. /*
  960. * If m is infinity, or n is zero, the result is zero
  961. */
  962. if (tm & VFP_INFINITY || tn & VFP_ZERO)
  963. goto zero;
  964. if (tn & VFP_DENORMAL)
  965. vfp_single_normalise_denormal(&vsn);
  966. if (tm & VFP_DENORMAL)
  967. vfp_single_normalise_denormal(&vsm);
  968. /*
  969. * Ok, we have two numbers, we can perform division.
  970. */
  971. vsd.exponent = vsn.exponent - vsm.exponent + 127 - 1;
  972. vsm.significand <<= 1;
  973. if (vsm.significand <= (2 * vsn.significand)) {
  974. vsn.significand >>= 1;
  975. vsd.exponent++;
  976. }
  977. {
  978. u64 significand = (u64)vsn.significand << 32;
  979. do_div(significand, vsm.significand);
  980. vsd.significand = significand;
  981. }
  982. if ((vsd.significand & 0x3f) == 0)
  983. vsd.significand |= ((u64)vsm.significand * vsd.significand != (u64)vsn.significand << 32);
  984. return vfp_single_normaliseround(state, sd, &vsd, fpscr, 0, "fdiv");
  985. vsn_nan:
  986. exceptions = vfp_propagate_nan(&vsd, &vsn, &vsm, fpscr);
  987. pack:
  988. vfp_put_float(state, vfp_single_pack(&vsd), sd);
  989. return exceptions;
  990. vsm_nan:
  991. exceptions = vfp_propagate_nan(&vsd, &vsm, &vsn, fpscr);
  992. goto pack;
  993. zero:
  994. vsd.exponent = 0;
  995. vsd.significand = 0;
  996. goto pack;
  997. divzero:
  998. exceptions = FPSCR_DZC;
  999. infinity:
  1000. vsd.exponent = 255;
  1001. vsd.significand = 0;
  1002. goto pack;
  1003. invalid:
  1004. vfp_put_float(state, vfp_single_pack(&vfp_single_default_qnan), sd);
  1005. return FPSCR_IOC;
  1006. }
  1007. static struct op fops[] = {
  1008. { vfp_single_fmac, 0 },
  1009. { vfp_single_fmsc, 0 },
  1010. { vfp_single_fmul, 0 },
  1011. { vfp_single_fadd, 0 },
  1012. { vfp_single_fnmac, 0 },
  1013. { vfp_single_fnmsc, 0 },
  1014. { vfp_single_fnmul, 0 },
  1015. { vfp_single_fsub, 0 },
  1016. { vfp_single_fdiv, 0 },
  1017. };
  1018. #define FREG_BANK(x) ((x) & 0x18)
  1019. #define FREG_IDX(x) ((x) & 7)
  1020. u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr)
  1021. {
  1022. u32 op = inst & FOP_MASK;
  1023. u32 exceptions = 0;
  1024. unsigned int dest;
  1025. unsigned int sn = vfp_get_sn(inst);
  1026. unsigned int sm = vfp_get_sm(inst);
  1027. unsigned int vecitr, veclen, vecstride;
  1028. struct op *fop;
  1029. pr_debug("In %s\n", __FUNCTION__);
  1030. vecstride = 1 + ((fpscr & FPSCR_STRIDE_MASK) == FPSCR_STRIDE_MASK);
  1031. fop = (op == FOP_EXT) ? &fops_ext[FEXT_TO_IDX(inst)] : &fops[FOP_TO_IDX(op)];
  1032. /*
  1033. * fcvtsd takes a dN register number as destination, not sN.
  1034. * Technically, if bit 0 of dd is set, this is an invalid
  1035. * instruction. However, we ignore this for efficiency.
  1036. * It also only operates on scalars.
  1037. */
  1038. if (fop->flags & OP_DD)
  1039. dest = vfp_get_dd(inst);
  1040. else
  1041. dest = vfp_get_sd(inst);
  1042. /*
  1043. * If destination bank is zero, vector length is always '1'.
  1044. * ARM DDI0100F C5.1.3, C5.3.2.
  1045. */
  1046. if ((fop->flags & OP_SCALAR) || FREG_BANK(dest) == 0)
  1047. veclen = 0;
  1048. else
  1049. veclen = fpscr & FPSCR_LENGTH_MASK;
  1050. pr_debug("VFP: vecstride=%u veclen=%u\n", vecstride,
  1051. (veclen >> FPSCR_LENGTH_BIT) + 1);
  1052. if (!fop->fn) {
  1053. printf("VFP: could not find single op %d, inst=0x%x@0x%x\n", FEXT_TO_IDX(inst), inst, state->Reg[15]);
  1054. exit(-1);
  1055. goto invalid;
  1056. }
  1057. for (vecitr = 0; vecitr <= veclen; vecitr += 1 << FPSCR_LENGTH_BIT) {
  1058. s32 m = vfp_get_float(state, sm);
  1059. u32 except;
  1060. char type;
  1061. type = fop->flags & OP_DD ? 'd' : 's';
  1062. if (op == FOP_EXT)
  1063. pr_debug("VFP: itr%d (%c%u) = op[%u] (s%u=%08x)\n",
  1064. vecitr >> FPSCR_LENGTH_BIT, type, dest, sn,
  1065. sm, m);
  1066. else
  1067. pr_debug("VFP: itr%d (%c%u) = (s%u) op[%u] (s%u=%08x)\n",
  1068. vecitr >> FPSCR_LENGTH_BIT, type, dest, sn,
  1069. FOP_TO_IDX(op), sm, m);
  1070. except = fop->fn(state, dest, sn, m, fpscr);
  1071. pr_debug("VFP: itr%d: exceptions=%08x\n",
  1072. vecitr >> FPSCR_LENGTH_BIT, except);
  1073. exceptions |= except;
  1074. /*
  1075. * CHECK: It appears to be undefined whether we stop when
  1076. * we encounter an exception. We continue.
  1077. */
  1078. dest = FREG_BANK(dest) + ((FREG_IDX(dest) + vecstride) & 7);
  1079. sn = FREG_BANK(sn) + ((FREG_IDX(sn) + vecstride) & 7);
  1080. if (FREG_BANK(sm) != 0)
  1081. sm = FREG_BANK(sm) + ((FREG_IDX(sm) + vecstride) & 7);
  1082. }
  1083. return exceptions;
  1084. invalid:
  1085. return (u32)-1;
  1086. }