vfpsingle.c 29 KB

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