Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

859 lines
15 KiB

  1. /*
  2. * Copyright (c) 2000, Intel Corporation
  3. * All rights reserved.
  4. *
  5. * WARRANTY DISCLAIMER
  6. *
  7. * THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  8. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  9. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  10. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  11. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  12. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  13. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  14. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  15. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  16. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE
  17. * MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18. *
  19. * Intel Corporation is the author of the Materials, and requests that all
  20. * problem reports or change requests be submitted to it directly at
  21. * http://developer.intel.com/opensource.
  22. */
  23. #include "stdio.h"
  24. #include "stdlib.h"
  25. #include "string.h"
  26. #include "ctype.h"
  27. #include "iel.h"
  28. typedef struct
  29. {
  30. unsigned short w[8];
  31. } MUL128;
  32. U32 digits_value[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
  33. IEL_Err IEL_mul(U128 *xr, U128 *y, U128 *z)
  34. {
  35. MUL128 y1, z1;
  36. U128 temp[16], x;
  37. char ovfl=0;
  38. unsigned long i, j, ui, uj, tmin, tmax;
  39. unsigned long meanterm;
  40. for (i=0; i<16; i++)
  41. IEL_ZERO (temp[i]);
  42. y1 = *(MUL128*)(y);
  43. z1 = *(MUL128*)(z);
  44. #ifndef BIG_ENDIAN
  45. for (ui=8; ((ui>0) && (!y1.w[ui-1])); ui--);
  46. for (uj=8; ((uj>0) && (!z1.w[uj-1])); uj--);
  47. if ((ui+uj)<8)
  48. {
  49. tmin = ui+uj;
  50. tmax = 0;
  51. } else
  52. {
  53. tmin = 8;
  54. tmax = ui+uj-8;
  55. }
  56. #else
  57. ui=8;
  58. uj=8;
  59. tmin = 8;
  60. tmax = 8;
  61. #endif
  62. for (i=0; i<ui; i++)
  63. for (j=0; j<uj; j++)
  64. {
  65. #ifndef BIG_ENDIAN
  66. meanterm = y1.w[i] * z1.w[j];
  67. #else
  68. meanterm = y1.w[7-i] * z1.w[7-j];
  69. #endif
  70. IEL_ADDU (temp[i+j], temp[i+j], IEL32(meanterm));
  71. }
  72. for (i=1; i<tmin; i++)
  73. ovfl = IEL_SHL128 (temp[i], temp[i], 16*i) || ovfl;
  74. for (i=0; i<tmax; i++)
  75. ovfl = !(IEL_ISZERO (temp[i+8])) || ovfl;
  76. IEL_ZERO (x);
  77. for (i=0; i<tmin; i++)
  78. ovfl = IEL_ADDU (x, x, temp[i]) || ovfl;
  79. IEL_ASSIGNU (IEL128(*xr), x);
  80. return (ovfl);
  81. }
  82. /* char find_hi_bit(U128 x)
  83. {
  84. char place;
  85. long num, k;
  86. char parts[4];
  87. char j,part;
  88. if ((num = DW3(x))) place=96; else
  89. if ((num = DW2(x))) place=64; else
  90. if ((num = DW1(x))) place=32; else
  91. if ((num = DW0(x))) place=0; else
  92. return(0);
  93. *(long *)(parts) = num;
  94. if ((part = parts[0])) place+=24; else
  95. if ((part = parts[1])) place+=16; else
  96. if ((part = parts[2])) place+=8; else
  97. part = parts[3];
  98. j = 8;
  99. k = 128;
  100. for (j=8, k=128; !(part & k); j--, k=k>>1);
  101. part+=j;
  102. }
  103. */
  104. IEL_Err IEL_rem(U128 *x, U128 *y, U128 *z)
  105. {
  106. U128 x1, y1, z1, t1, z2;
  107. long carry, i,j;
  108. if (IEL_ISZERO(*z))
  109. {
  110. IEL_ASSIGNU(*x, *y);
  111. return (IEL_OVFL);
  112. }
  113. IEL_ASSIGNU(y1, *y);
  114. IEL_ZERO(x1);
  115. while (IEL_CMPGEU(y1, *z))
  116. {
  117. IEL_CONVERT(t1, 1, 0, 0, 0);
  118. IEL_ASSIGNU(z1, *z);
  119. IEL_ASSIGNU(z2, z1);
  120. j = 0;
  121. for (i=64; i>0; i=i>>1)
  122. {
  123. carry = IEL_SHL(z2, z2, i);
  124. if (IEL_CMPGEU(y1, z2) && (!carry))
  125. {
  126. j+=i;
  127. IEL_ASSIGNU(z1, z2);
  128. } else
  129. {
  130. IEL_ASSIGNU(z2, z1);
  131. }
  132. }
  133. IEL_SHL(t1, t1, j);
  134. IEL_SUBU(y1, y1, z2);
  135. IEL_ADDU(x1, x1, t1);
  136. }
  137. IEL_ASSIGNU(IEL128(*x), y1);
  138. return (IEL_OK);
  139. }
  140. IEL_Err IEL_div(U128 *x, U128 *y, U128 *z)
  141. {
  142. U128 x1, y1, z1, t1, z2;
  143. long carry, i, j;
  144. IEL_ASSIGNU(y1, *y);
  145. IEL_ZERO(x1);
  146. if (IEL_ISZERO(*z))
  147. {
  148. (*x).dw3_128 = 0;
  149. return (IEL_OVFL);
  150. }
  151. while (IEL_CMPGEU (y1, *z))
  152. {
  153. IEL_CONVERT(t1, 1, 0, 0, 0);
  154. IEL_ASSIGNU(z1, *z);
  155. IEL_ASSIGNU(z2, z1);
  156. j = 0;
  157. for (i=64; i>0; i=i>>1)
  158. {
  159. carry = IEL_SHL(z2, z2, i);
  160. if (IEL_CMPGEU(y1, z2) && (!carry))
  161. {
  162. j+=i;
  163. IEL_ASSIGNU(z1, z2);
  164. } else
  165. {
  166. IEL_ASSIGNU(z2, z1);
  167. }
  168. }
  169. IEL_SHL(t1, t1, j);
  170. IEL_SUBU(y1, y1, z2);
  171. IEL_ADDU(x1, x1, t1);
  172. }
  173. IEL_ASSIGNU(IEL128(*x), x1);
  174. return (IEL_OK);
  175. }
  176. static void transpose(char *st)
  177. {
  178. unsigned long i;
  179. char c;
  180. unsigned long len;
  181. len = strlen(st);
  182. for (i=0; i<(strlen(st)/2); i++)
  183. {
  184. c = st[i];
  185. st[i]=st[len-i-1];
  186. st[len-i-1]=c;
  187. }
  188. }
  189. static long leadzero(char *st)
  190. {
  191. long j=0, i=0;
  192. while (st[i++]=='0') j++;
  193. return(j);
  194. }
  195. static void backzero(char *st)
  196. {
  197. unsigned long i;
  198. i = strlen(st);
  199. while (st[--i]=='0');
  200. st[++i]='\0';
  201. }
  202. IEL_Err IEL_U128tostr(const U128 *x, char *strptr, int base, const unsigned int length)
  203. {
  204. char digit[17] = "0123456789abcdef";
  205. U128 x1, y1, z1, t1;
  206. unsigned long i, j = 0, k, len, lead;
  207. char tempplace[1100];
  208. char *tempstr = tempplace, negative = IEL_FALSE;
  209. unsigned long dwtemp=0, bit;
  210. IEL_ASSIGNU (t1, IEL128(*x));
  211. tempstr[0]='\0';
  212. if (base == 100)
  213. {
  214. if (IEL_ISNEG(t1))
  215. {
  216. IEL_COMPLEMENTS(t1, t1);
  217. negative = IEL_TRUE;
  218. }
  219. base = 10;
  220. }
  221. if IEL_ISZERO(t1)
  222. {
  223. tempstr[0]='0';
  224. tempstr[1]='\0';
  225. } else
  226. if ((base==16) || (base == 116))
  227. {
  228. if (base ==16)
  229. {
  230. sprintf(tempstr,"%lx%08lx%08lx%08lx",DW3(t1),DW2(t1),DW1(t1),DW0(t1));
  231. } else
  232. {
  233. sprintf(tempstr,"%lX%08lX%08lX%08lX",DW3(t1),DW2(t1),DW1(t1),DW0(t1));
  234. }
  235. lead = leadzero(tempstr);
  236. for(i=lead; i<=strlen(tempstr); i++)
  237. {
  238. tempstr[i-lead]=tempstr[i];
  239. }
  240. } else
  241. if (base==2)
  242. {
  243. len = 0;
  244. for (j=0; j<4; j++)
  245. {
  246. switch(j)
  247. {
  248. case 0:
  249. dwtemp = DW0(t1);
  250. break;
  251. case 1:
  252. dwtemp = DW1(t1);
  253. break;
  254. case 2:
  255. dwtemp = DW2(t1);
  256. break;
  257. case 3:
  258. dwtemp = DW3(t1);
  259. break;
  260. }
  261. bit = 1;
  262. for (i=0; i<32; i++)
  263. {
  264. if (bit & dwtemp)
  265. {
  266. tempstr[len]='1';
  267. } else
  268. {
  269. tempstr[len]='0';
  270. }
  271. bit<<=1;
  272. len++;
  273. }
  274. }
  275. tempstr[len]='\0';
  276. transpose(tempstr);
  277. lead = leadzero(tempstr);
  278. for(i=lead; i<=strlen(tempstr); i++)
  279. {
  280. tempstr[i-lead]=tempstr[i];
  281. }
  282. } else
  283. if (base==10)
  284. {
  285. len=0;
  286. IEL_ASSIGNU(y1, t1);
  287. IEL_CONVERT(z1, 1000000000, 0, 0, 0);
  288. while (!IEL_ISZERO(y1))
  289. {
  290. IEL_rem (&x1, &y1, &z1);
  291. IEL_ASSIGNU (IEL32(i), x1);
  292. for (k=0; k<9; k++)
  293. {
  294. j=i%10;
  295. tempstr[len+1]='\0';
  296. tempstr[len]=digit[j];
  297. i=i/10;
  298. len++;
  299. }
  300. IEL_div(&y1, &y1, &z1);
  301. }
  302. if (negative)
  303. {
  304. backzero(tempstr);
  305. tempstr[strlen(tempstr)+1]='\0';
  306. tempstr[strlen(tempstr)]='-';
  307. transpose(tempstr);
  308. } else
  309. {
  310. transpose(tempstr);
  311. lead = leadzero(tempstr);
  312. for(i=lead; i<=strlen(tempstr); i++)
  313. {
  314. tempstr[i-lead]=tempstr[i];
  315. }
  316. }
  317. } else
  318. if (base==8)
  319. {
  320. len=0;
  321. IEL_ASSIGNU(y1, t1);
  322. IEL_CONVERT(z1, 010000000000, 0, 0, 0);
  323. while (!IEL_ISZERO(y1))
  324. {
  325. IEL_rem (&x1, &y1, &z1);
  326. IEL_ASSIGNU (IEL32(i), x1);
  327. for (k=0; k<10; k++)
  328. {
  329. j=i%8;
  330. tempstr[len+1]='\0';
  331. tempstr[len]=digit[j];
  332. i=i/8;
  333. len++;
  334. }
  335. IEL_div(&y1, &y1, &z1);
  336. }
  337. if (negative)
  338. {
  339. backzero(tempstr);
  340. tempstr[strlen(tempstr)+1]='\0';
  341. tempstr[strlen(tempstr)]='-';
  342. transpose(tempstr);
  343. } else
  344. {
  345. transpose(tempstr);
  346. lead = leadzero(tempstr);
  347. for(i=lead; i<=strlen(tempstr); i++)
  348. {
  349. tempstr[i-lead]=tempstr[i];
  350. }
  351. }
  352. } else
  353. {
  354. IEL_ASSIGNU (z1, IEL32(base));
  355. IEL_ASSIGNU (y1, t1);
  356. while (!IEL_ISZERO(y1))
  357. {
  358. IEL_rem (&x1, &y1, &z1);
  359. IEL_ASSIGNU (IEL32(i), x1);
  360. tempstr[strlen(tempstr)+1]='\0';
  361. tempstr[strlen(tempstr)]=digit[i];
  362. IEL_div (&y1, &y1, &z1);
  363. }
  364. transpose(tempstr);
  365. }
  366. if (length < strlen (tempstr)+1)
  367. {
  368. return (IEL_OVFL);
  369. } else
  370. {
  371. for (i=0; i<=strlen(tempstr); i++)
  372. strptr[i]=tempstr[i];
  373. return (IEL_OK);
  374. }
  375. }
  376. IEL_Err IEL_U64tostr(const U64 *x, char *strptr, int base, const unsigned int length)
  377. {
  378. U128 y;
  379. IEL_ASSIGNU(y, (*x));
  380. return (IEL_U128tostr (&y, strptr, base, length));
  381. }
  382. IEL_Err IEL_S128tostr(const S128 *x, char *strptr, int base, const unsigned int length)
  383. {
  384. U128 y;
  385. IEL_ASSIGNU(y, (*x));
  386. return(IEL_U128tostr( &y, strptr, base, length));
  387. }
  388. IEL_Err IEL_S64tostr(const S64 *x, char *strptr, int base, const unsigned int length)
  389. {
  390. U128 y;
  391. IEL_SEXT(y, (*x));
  392. return(IEL_U128tostr( &y, strptr, base, length));
  393. }
  394. IEL_Err IEL_strtoU128( char *str1, char **endptr, int base, U128 *x)
  395. {
  396. U128 sum;
  397. unsigned long i, j=0;
  398. int negative=IEL_FALSE;
  399. unsigned long inbase, insum;
  400. IEL_Err ovfl = IEL_OK;
  401. if (str1[0]=='-')
  402. {
  403. negative = IEL_TRUE;
  404. str1++;
  405. }
  406. if (base == 0)
  407. {
  408. if (str1[0]=='0')
  409. {
  410. if (strlen(str1)==1)
  411. {
  412. IEL_ZERO((*x));
  413. return (IEL_OK);
  414. } else
  415. if (strchr("01234567",str1[1]))
  416. {
  417. base = 8;
  418. str1++;
  419. } else
  420. {
  421. switch (str1[1])
  422. {
  423. case 'B':
  424. case 'b': base=2;
  425. str1+=2;
  426. break;
  427. case 'X':
  428. case 'x':
  429. case 'H':
  430. case 'h': base=16;
  431. str1+=2;
  432. break;
  433. default: return (IEL_OVFL);
  434. }
  435. }
  436. } else
  437. {
  438. base = 10;
  439. }
  440. }
  441. switch(base)
  442. {
  443. case 10:
  444. for (j=0; str1[j]>='0' && str1[j]<='9';)
  445. {
  446. insum = str1[j++]-'0';
  447. inbase = 10;
  448. i=1;
  449. while ((i<9) && str1[j]>='0' && str1[j]<='9')
  450. {
  451. i++;
  452. inbase = inbase * 10;
  453. insum *= 10;
  454. insum += str1[j++]-'0';
  455. }
  456. if (j<10)
  457. {
  458. IEL_ASSIGNU (sum, IEL32(insum));
  459. } else
  460. {
  461. ovfl = IEL_MULU(sum, sum, IEL32(inbase)) || ovfl;
  462. ovfl = IEL_ADDU(sum, sum, IEL32(insum)) || ovfl;
  463. }
  464. }
  465. break;
  466. case 2:
  467. for (j=0; str1[j]>='0' && str1[j]<='1';)
  468. {
  469. insum = str1[j++]-'0';
  470. inbase = 1;
  471. i=1;
  472. while ((i<32) && str1[j]>='0' && str1[j]<='9')
  473. {
  474. i++;
  475. inbase++;
  476. insum *= 2;
  477. insum += str1[j++]-'0';
  478. }
  479. if (j<33)
  480. {
  481. IEL_ASSIGNU (sum, IEL32(insum));
  482. } else
  483. {
  484. ovfl = IEL_SHL128(sum, sum, inbase) || ovfl;
  485. ovfl = IEL_ADDU(sum, sum, IEL32(insum)) || ovfl;
  486. }
  487. }
  488. break;
  489. case 8:
  490. for (j=0; str1[j]>='0' && str1[j]<='7';)
  491. {
  492. insum = str1[j++]-'0';
  493. inbase = 3;
  494. i=1;
  495. while ((i<10) && str1[j]>='0' && str1[j]<='7')
  496. {
  497. i++;
  498. inbase+=3;
  499. insum *= 8;
  500. insum += str1[j++]-'0';
  501. }
  502. if (j<11)
  503. {
  504. IEL_ASSIGNU (sum, IEL32(insum));
  505. } else
  506. {
  507. ovfl = IEL_SHL128(sum, sum, inbase) || ovfl;
  508. ovfl = IEL_ADDU(sum, sum, IEL32(insum)) || ovfl;
  509. }
  510. }
  511. break;
  512. case 16:
  513. for (j=0; ((str1[j]>='0' && str1[j]<='9') ||
  514. (tolower(str1[j])>='a' && tolower(str1[j]<='f'))); )
  515. {
  516. if (str1[j]<='9')
  517. {
  518. insum = str1[j++]-'0';
  519. } else
  520. {
  521. insum = tolower(str1[j++])-'a'+10;
  522. }
  523. inbase = 4;
  524. i=1;
  525. while ((i<8) && ((str1[j]>='0' && str1[j]<='9') ||
  526. (tolower(str1[j])>='a' && tolower(str1[j]<='f'))))
  527. {
  528. i++;
  529. inbase += 4;
  530. insum *= 16;
  531. if (str1[j]<='9')
  532. {
  533. insum += (str1[j++]-'0');
  534. } else
  535. {
  536. insum += (tolower(str1[j++])-'a'+10);
  537. }
  538. }
  539. if (j<9)
  540. {
  541. IEL_ASSIGNU (sum, IEL32(insum));
  542. } else
  543. {
  544. ovfl = IEL_SHL128(sum, sum, inbase) || ovfl;
  545. ovfl = IEL_ADDU(sum, sum, IEL32(insum)) || ovfl;
  546. }
  547. }
  548. break;
  549. }
  550. IEL_ASSIGNU(IEL128(*x), sum);
  551. if (negative)
  552. {
  553. ovfl = ovfl || (IEL_ISNEG(*x) && !IEL_ISNINF(*x));
  554. IEL_COMPLEMENTS(IEL128(*x), IEL128(*x));
  555. }
  556. *endptr = str1+j;
  557. if (ovfl)
  558. {
  559. IEL_CONVERT4((*x), 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
  560. }
  561. return (ovfl);
  562. }
  563. IEL_Err IEL_strtoU64(char *str1, char **endptr, int base, U64 *x)
  564. {
  565. U128 y1;
  566. IEL_Err ovfl = IEL_strtoU128(str1, endptr, base, &y1);
  567. ovfl = IEL_ASSIGNU((*x), y1) || ovfl;
  568. if (ovfl)
  569. {
  570. IEL_CONVERT2(*x, 0xFFFFFFFF, 0xFFFFFFFF);
  571. }
  572. return (ovfl);
  573. }
  574. IEL_Err IEL_strtoS128(char *str1, char **endptr, int base, S128 *x)
  575. {
  576. U128 y1;
  577. IEL_Err ovfl = IEL_strtoU128(str1, endptr, base, &y1);
  578. if (str1[0] == '-')
  579. {
  580. IEL_ASSIGNU((*x), y1);
  581. if (ovfl)
  582. {
  583. IEL_CONVERT4(*x, 0, 0, 0, 0x80000000);
  584. }
  585. } else
  586. {
  587. IEL_ASSIGNU((*x), y1);
  588. ovfl = (IEL_ISNEG(y1)) || ovfl;
  589. if (ovfl)
  590. {
  591. IEL_CONVERT4(*x, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x7fffffff);
  592. }
  593. }
  594. return (ovfl);
  595. }
  596. IEL_Err IEL_strtoS64(char *str1, char **endptr, int base, S64 *x)
  597. {
  598. U128 y1;
  599. IEL_Err ovfl = IEL_strtoU128(str1, endptr, base, &y1);
  600. if (str1[0] == '-')
  601. {
  602. ovfl = IEL_ASSIGNS((*x), y1) || ovfl;
  603. if (ovfl)
  604. {
  605. IEL_CONVERT2(*x, 0, 0x80000000);
  606. }
  607. } else
  608. {
  609. ovfl = IEL_ASSIGNU((*x), y1) || ovfl;
  610. ovfl = IEL_ISNEG(*x) || ovfl;
  611. if (ovfl)
  612. {
  613. IEL_CONVERT2(*x, 0xFFFFFFFF, 0x7fffffff);
  614. }
  615. }
  616. return (ovfl);
  617. }
  618. #ifndef LP64
  619. int IEL_c0(void *x, int sx)
  620. {
  621. U64 u64x;
  622. U128 u128x;
  623. /* sx can be only 64 or 128 bits */
  624. if (sx == sizeof(U64))
  625. {
  626. IEL_ASSIGNU(u64x,*((U64 *)(x)));
  627. return(IEL_R_C0(u64x));
  628. } else
  629. {
  630. IEL_ASSIGNU(u128x, *((U128 *)(x)));
  631. return(IEL_R_C0(u128x));
  632. }
  633. }
  634. int IEL_c1(void *x, int sx)
  635. {
  636. U64 u64x;
  637. U128 u128x;
  638. /* sx can be only 64 or 128 bits */
  639. if (sx == sizeof(U64))
  640. {
  641. IEL_ASSIGNU(u64x,*((U64 *)(x)));
  642. return(IEL_R_C1(u64x));
  643. } else
  644. {
  645. IEL_ASSIGNU(u128x, *((U128 *)(x)));
  646. return(IEL_R_C1(u128x));
  647. }
  648. }
  649. int IEL_c2(void *x, int sx)
  650. {
  651. U64 u64x;
  652. U128 u128x;
  653. /* sx can be only 64 or 128 bits */
  654. if (sx == sizeof(U64))
  655. {
  656. IEL_ASSIGNU(u64x,*((U64 *)(x)));
  657. return(IEL_R_C2(u64x));
  658. } else
  659. {
  660. IEL_ASSIGNU(u128x, *((U128 *)(x)));
  661. return(IEL_R_C2(u128x));
  662. }
  663. }
  664. int IEL_c3(void *x, int sx)
  665. {
  666. U64 u64x;
  667. U128 u128x;
  668. /* sx can be only 64 or 128 bits */
  669. if (sx == sizeof(U64))
  670. {
  671. IEL_ASSIGNU(u64x,*((U64 *)(x)));
  672. return(IEL_R_C3(u64x));
  673. } else
  674. {
  675. IEL_ASSIGNU(u128x, *((U128 *)(x)));
  676. return(IEL_R_C3(u128x));
  677. }
  678. }
  679. int IEL_au(void *x, void *y, int sx, int sy)
  680. {
  681. U128 tmp, zero;
  682. if (x==y)
  683. return (IEL_OK);
  684. IEL_ZERO(zero);
  685. if (sx>=sy)
  686. {
  687. memset(x, 0, (size_t)sx);
  688. memcpy(x, y, (size_t)sy);
  689. } else
  690. {
  691. memset(&tmp, 0, sizeof(U128));
  692. memcpy(x, y, (size_t)sx);
  693. memcpy(&tmp, y, (size_t)sy);
  694. memset(&tmp, 0, (size_t)sx);
  695. if (memcmp(&zero, &tmp, sizeof(U128)))
  696. {
  697. return(IEL_OVFL);
  698. }
  699. }
  700. return (IEL_OK);
  701. }
  702. IEL_Err IEL_as(void *x, void *y, int sx, int sy)
  703. {
  704. S32 s32y;
  705. S64 s64y;
  706. S128 s128y;
  707. S32 s32x;
  708. S64 s64x;
  709. S128 s128x;
  710. IEL_Err ov=IEL_OK;
  711. switch (sy)
  712. {
  713. case sizeof(S32): s32y = *(S32 *)y; IEL_SEXT(s128y, s32y); break;
  714. case sizeof(S64): s64y = *(S64 *)y; IEL_SEXT(s128y, s64y); break;
  715. case sizeof(S128): s128y = *(S128 *)y; break;
  716. }
  717. switch (sx)
  718. {
  719. case sizeof(S32):
  720. ov = IEL_REAL_ASSIGNS(s32x, s128y);
  721. memcpy((char *)x, (char *)&s32x, (size_t)sx);
  722. break;
  723. case sizeof(S64):
  724. ov = IEL_REAL_ASSIGNS(s64x, s128y);
  725. memcpy((char *)x, (char *)&s64x, (size_t)sx);
  726. break;
  727. case sizeof(S128):
  728. ov = IEL_REAL_ASSIGNS(s128x, s128y);
  729. memcpy((char *)x, (char *)&s128x, (size_t)sx);
  730. break;
  731. }
  732. return(ov);
  733. }
  734. #endif /* LP64 */