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