vfpsingle.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  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 u32 (* const fop_extfns[32])(int sd, int unused, s32 m, u32 fpscr) = {
  604. [FEXT_TO_IDX(FEXT_FCPY)] = vfp_single_fcpy,
  605. [FEXT_TO_IDX(FEXT_FABS)] = vfp_single_fabs,
  606. [FEXT_TO_IDX(FEXT_FNEG)] = vfp_single_fneg,
  607. [FEXT_TO_IDX(FEXT_FSQRT)] = vfp_single_fsqrt,
  608. [FEXT_TO_IDX(FEXT_FCMP)] = vfp_single_fcmp,
  609. [FEXT_TO_IDX(FEXT_FCMPE)] = vfp_single_fcmpe,
  610. [FEXT_TO_IDX(FEXT_FCMPZ)] = vfp_single_fcmpz,
  611. [FEXT_TO_IDX(FEXT_FCMPEZ)] = vfp_single_fcmpez,
  612. [FEXT_TO_IDX(FEXT_FCVT)] = vfp_single_fcvtd,
  613. [FEXT_TO_IDX(FEXT_FUITO)] = vfp_single_fuito,
  614. [FEXT_TO_IDX(FEXT_FSITO)] = vfp_single_fsito,
  615. [FEXT_TO_IDX(FEXT_FTOUI)] = vfp_single_ftoui,
  616. [FEXT_TO_IDX(FEXT_FTOUIZ)] = vfp_single_ftouiz,
  617. [FEXT_TO_IDX(FEXT_FTOSI)] = vfp_single_ftosi,
  618. [FEXT_TO_IDX(FEXT_FTOSIZ)] = vfp_single_ftosiz,
  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 u32 (* const fop_fns[16])(int sd, int sn, s32 m, u32 fpscr) = {
  981. [FOP_TO_IDX(FOP_FMAC)] = vfp_single_fmac,
  982. [FOP_TO_IDX(FOP_FNMAC)] = vfp_single_fnmac,
  983. [FOP_TO_IDX(FOP_FMSC)] = vfp_single_fmsc,
  984. [FOP_TO_IDX(FOP_FNMSC)] = vfp_single_fnmsc,
  985. [FOP_TO_IDX(FOP_FMUL)] = vfp_single_fmul,
  986. [FOP_TO_IDX(FOP_FNMUL)] = vfp_single_fnmul,
  987. [FOP_TO_IDX(FOP_FADD)] = vfp_single_fadd,
  988. [FOP_TO_IDX(FOP_FSUB)] = vfp_single_fsub,
  989. [FOP_TO_IDX(FOP_FDIV)] = vfp_single_fdiv,
  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. u32 (*fop)(int, int, s32, u32);
  1002. veclen = fpscr & FPSCR_LENGTH_MASK;
  1003. vecstride = 1 + ((fpscr & FPSCR_STRIDE_MASK) == FPSCR_STRIDE_MASK);
  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 ((inst & FEXT_MASK) == FEXT_FCVT) {
  1011. veclen = 0;
  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 (FREG_BANK(dest) == 0)
  1020. veclen = 0;
  1021. pr_debug("VFP: vecstride=%u veclen=%u\n", vecstride,
  1022. (veclen >> FPSCR_LENGTH_BIT) + 1);
  1023. fop = (op == FOP_EXT) ? fop_extfns[FEXT_TO_IDX(inst)] : fop_fns[FOP_TO_IDX(op)];
  1024. if (!fop)
  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. if (op == FOP_EXT && (inst & FEXT_MASK) == FEXT_FCVT)
  1030. pr_debug("VFP: itr%d (d%u) = op[%u] (s%u=%08x)\n",
  1031. vecitr >> FPSCR_LENGTH_BIT, dest, sn, sm, m);
  1032. else if (op == FOP_EXT)
  1033. pr_debug("VFP: itr%d (s%u) = op[%u] (s%u=%08x)\n",
  1034. vecitr >> FPSCR_LENGTH_BIT, dest, sn, sm, m);
  1035. else
  1036. pr_debug("VFP: itr%d (s%u) = (s%u) op[%u] (s%u=%08x)\n",
  1037. vecitr >> FPSCR_LENGTH_BIT, dest, sn,
  1038. FOP_TO_IDX(op), sm, m);
  1039. except = fop(dest, sn, m, fpscr);
  1040. pr_debug("VFP: itr%d: exceptions=%08x\n",
  1041. vecitr >> FPSCR_LENGTH_BIT, except);
  1042. exceptions |= except;
  1043. /*
  1044. * This ensures that comparisons only operate on scalars;
  1045. * comparisons always return with one FPSCR status bit set.
  1046. */
  1047. if (except & (FPSCR_N|FPSCR_Z|FPSCR_C|FPSCR_V))
  1048. break;
  1049. /*
  1050. * CHECK: It appears to be undefined whether we stop when
  1051. * we encounter an exception. We continue.
  1052. */
  1053. dest = FREG_BANK(dest) + ((FREG_IDX(dest) + vecstride) & 7);
  1054. sn = FREG_BANK(sn) + ((FREG_IDX(sn) + vecstride) & 7);
  1055. if (FREG_BANK(sm) != 0)
  1056. sm = FREG_BANK(sm) + ((FREG_IDX(sm) + vecstride) & 7);
  1057. }
  1058. return exceptions;
  1059. invalid:
  1060. return (u32)-1;
  1061. }