vfpsingle.c 29 KB

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