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.

1553 lines
74 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. #ifndef IEL_H
  24. #define IEL_H
  25. #if defined(BIG_ENDIAN) && defined(BYTE_ORDER)
  26. #if BYTE_ORDER != BIG_ENDIAN
  27. #undef BIG_ENDIAN
  28. #endif
  29. #endif
  30. typedef char S1byte;
  31. typedef short S2byte;
  32. typedef int S4byte;
  33. typedef unsigned char U1byte;
  34. typedef unsigned short U2byte;
  35. typedef unsigned int U4byte;
  36. typedef unsigned short U16;
  37. typedef unsigned char U8;
  38. /*---------
  39. IEL types declarations
  40. ------------*/
  41. #ifdef LP64
  42. #ifdef WINNT
  43. typedef unsigned __int64 Ulong64;
  44. typedef __int64 Slong64;
  45. #else
  46. typedef unsigned long Ulong64;
  47. typedef long Slong64;
  48. #endif
  49. extern Ulong64 IEL_temp64;
  50. typedef union
  51. {
  52. U4byte dw[1];
  53. U4byte qw[1];
  54. }U32, S32;
  55. typedef union
  56. {
  57. Ulong64 qw[1];
  58. unsigned int dw[2];
  59. } U64,S64;
  60. typedef union
  61. {
  62. Ulong64 qw[2];
  63. unsigned int dw[4];
  64. } U128, S128;
  65. #else /* LP32 */
  66. typedef struct
  67. {
  68. U4byte dw[1];
  69. }U32, S32;
  70. typedef struct
  71. {
  72. U4byte dw[2];
  73. } U64, S64;
  74. typedef struct
  75. {
  76. U4byte dw[4];
  77. } U128,S128;
  78. #endif /* end of LP32 */
  79. /*---------
  80. IEL temporary variables
  81. ------------*/
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. extern unsigned int IEL_t1, IEL_t2, IEL_t3, IEL_t4;
  86. extern U32 IEL_tempc;
  87. extern U64 IEL_et1, IEL_et2;
  88. extern U128 IEL_ext1, IEL_ext2, IEL_ext3, IEL_ext4, IEL_ext5;
  89. extern U128 IEL_POSINF, IEL_NEGINF, IEL_MINUS1;
  90. extern S128 IEL_ts1, IEL_ts2;
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. /*---------
  95. IEL constants
  96. ------------*/
  97. #define IEL_MAX32 ((U4byte) (0xFFFFFFFF))
  98. #define IEL_UMAX32 ((U4byte) (0xFFFFFFFF))
  99. #define IEL_SMAX32 ((U4byte) (0x7FFFFFFF))
  100. #define IEL_UMAX64 0xffffffffffffffff
  101. #define IEL_SMAX64 0x7fffffffffffffff
  102. #define IEL128(x) (*(U128*)(&(x)))
  103. #define IEL64(x) (*(U64*)(&(x)))
  104. #define IEL32(x) (*(U32*)(&(x)))
  105. #define IEL_FALSE 0
  106. #define IEL_TRUE 1
  107. #ifdef __cplusplus
  108. #define IEL_OK 0
  109. #define IEL_OVFL 1
  110. typedef unsigned int IEL_Err;
  111. #else
  112. typedef enum
  113. {
  114. IEL_OK = 0,
  115. IEL_OVFL
  116. } IEL_Err;
  117. #endif
  118. typedef enum
  119. {
  120. IEL_BIN = 2,
  121. IEL_OCT = 8,
  122. IEL_DEC = 10,
  123. IEL_SDEC = 100,
  124. IEL_HEX = 16,
  125. IEL_UHEX = 116
  126. } IEL_Base;
  127. /*----------
  128. IEL structure elements
  129. ---------*/
  130. # ifdef BIG_ENDIAN
  131. # define qw0_64 qw[0]
  132. # define qw0_128 qw[1]
  133. # define qw1_128 qw[0]
  134. # define dw0_32 dw[0]
  135. # define dw0_64 dw[1]
  136. # define dw1_64 dw[0]
  137. # define dw0_128 dw[3]
  138. # define dw1_128 dw[2]
  139. # define dw2_128 dw[1]
  140. # define dw3_128 dw[0]
  141. # else /*** BIG_ENDIAN ***/
  142. # define qw0_64 qw[0]
  143. # define qw0_128 qw[0]
  144. # define qw1_128 qw[1]
  145. # define dw0_32 dw[0]
  146. # define dw0_64 dw[0]
  147. # define dw1_64 dw[1]
  148. # define dw0_128 dw[0]
  149. # define dw1_128 dw[1]
  150. # define dw2_128 dw[2]
  151. # define dw3_128 dw[3]
  152. # endif /*** BIG_ENDIAN ***/
  153. #define DW0(x) ((sizeof((x))==4)?((x).dw0_32):\
  154. (sizeof((x))==8)?((x).dw0_64):\
  155. (sizeof((x))==16)?((x).dw0_128):0)
  156. #define DW1(x) ((sizeof((x))==8)?((x).dw1_64):\
  157. (sizeof((x))==16)?((x).dw1_128):0)
  158. #define DW2(x) ((sizeof((x))==16)?((x).dw2_128):0)
  159. #define DW3(x) ((sizeof((x))==16)?((x).dw3_128):0)
  160. #define IEL_GETDW0(x) DW0(x)
  161. #define IEL_GETDW1(x) DW1(x)
  162. #define IEL_GETDW2(x) DW2(x)
  163. #define IEL_GETDW3(x) DW3(x)
  164. #ifdef LP64
  165. #define IEL_CONST32(x) {(U4byte )(x)}
  166. #define IEL_CONST(x) IEL_CONST32(x)
  167. #define IEL_CONST64L(x) {(Ulong64 )(x)}
  168. #ifdef BIG_ENDIAN
  169. #define IEL_CONST64(x0, x1) {((Ulong64)x0<<32)|x1}
  170. #define IEL_CONST128(x0, x1, x2, x3) {{((Ulong64)x2<<32)|x3, ((Ulong64)x0<<32)|x1}}
  171. #define IEL_CONST128L(x0, x1) {{(Ulong64 )x1, (Ulong64 )x0}}
  172. #else /* BIG_ENDIAN */
  173. #define IEL_CONST64(x0, x1) {((Ulong64)x1<<32)|x0}
  174. #define IEL_CONST128(x0, x1, x2, x3) {{((Ulong64)x1<<32)|x0, ((Ulong64)x3<<32)|x2}}
  175. #define IEL_CONST128L(x0, x1) {{(Ulong64 )x0, (Ulong64 )x1}}
  176. #endif /* BIG_ENDIAN */
  177. #define IEL_GETQW0(x) ((sizeof(x)==4) ? (Ulong64)((x).dw0_32) : \
  178. ((sizeof(x)==8) ? (x).qw0_64 : \
  179. ((sizeof(x)==16) ? (x).qw0_128 : 0)))
  180. #define IEL_GETQW1(x) ((sizeof(x)==sizeof (U128)) ? ((x).qw1_128) : (0))
  181. #define QW0(x) IEL_GETQW0(x)
  182. #define QW1(x) IEL_GETQW1(x)
  183. #define SQW0(x) ((sizeof(x)==4)? (((x).dw0_32 & 0x80000000)? \
  184. (((Ulong64)(-1)<<32) | (Ulong64)(x).dw0_32) : (Ulong64)(x).dw0_32) : \
  185. (sizeof(x)==8)?((x).qw0_64):\
  186. (sizeof(x)==16)?((x).qw0_128):0)
  187. #define SQW1(x) ((sizeof(x)==4)? (((x).dw0_32 & 0x80000000)? (Ulong64)(-1):0) :\
  188. (sizeof(x)==8)?((x).qw0_64 & 0x8000000000000000)?(Ulong64)(-1):0 :\
  189. (sizeof(x)==16)?((x).qw1_128):0)
  190. #define IEL_INCU(x) ((sizeof(x) == sizeof(U32)) ? \
  191. ((x).dw0_32++,((x).dw0_32==0)) :\
  192. (sizeof(x) == sizeof(U64)) ? \
  193. ((x).qw0_64++,((x).qw0_64==0)) : \
  194. (sizeof(x) == sizeof(U128)) ? \
  195. ((x).qw0_128++,(!(x).qw0_128) ? \
  196. ((x).qw1_128++, ((x).qw1_128==0)) : \
  197. IEL_OK) : IEL_OVFL)
  198. #define IEL_INCS(x) ((sizeof(x) == sizeof(U32)) ? \
  199. (((x).dw0_32++),(((x).dw0_32==0x80000000)||((x).dw0_32==0))) : \
  200. (sizeof(x) == sizeof(U64)) ? \
  201. (((x).qw0_64++),(((x).qw0_64==0x8000000000000000)||((x).qw0_64==0))) : \
  202. (sizeof(x) == sizeof(U128)) ? \
  203. ((x).qw0_128++, !(x).qw0_128? ((x).qw0_128=0, (x).qw1_128++, \
  204. (((x).qw1_128==0)||((x).qw1_128==0x8000000000000000))) : IEL_OK): \
  205. IEL_OVFL)
  206. #define IEL_DECU(x) ((sizeof(x) == sizeof(U32)) ? \
  207. (((x).dw0_32--),((x).dw0_32==IEL_MAX32)) : \
  208. (sizeof(x) == sizeof(U64)) ? \
  209. ((x).qw0_64--,((x).qw0_64==IEL_UMAX64)) : \
  210. (sizeof(x) == sizeof(U128)) ? \
  211. ((x).qw0_128--,((x).qw0_128==IEL_UMAX64) ? \
  212. ((x).qw1_128--, ((x).qw1_128==IEL_UMAX64)) : \
  213. IEL_OK) : IEL_OVFL)
  214. #define IEL_DECS(x) ((sizeof(x) == sizeof(U32)) ? \
  215. (((x).dw0_32--),((x).dw0_32==IEL_UMAX32) || \
  216. (x).dw0_32==IEL_SMAX32) : \
  217. (sizeof(x) == sizeof(U64)) ? \
  218. (((x).qw0_64--),(((x).qw0_64==IEL_UMAX64))||((x).qw0_64==IEL_SMAX64)) : \
  219. (sizeof(x) == sizeof(U128)) ? \
  220. ((x).qw0_128--,((x).qw0_128==IEL_UMAX64) ? \
  221. ((x).qw1_128--, ((x).qw1_128==IEL_UMAX64)|| \
  222. ((x).qw1_128==IEL_SMAX64)): \
  223. IEL_OK) : IEL_OVFL)
  224. #define IEL_AND(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  225. ((x).dw0_32 = DW0(y) & DW0(z), \
  226. ((DW1(y) & DW1(z)) || (QW1(y) & QW1(z)))) : \
  227. (sizeof(x) == sizeof (U64)) ? \
  228. (((x).qw0_64 = QW0(y) & QW0(z)), \
  229. ((QW1(y) & QW1(z)) != 0)) : \
  230. (sizeof(x) == sizeof (U128)) ? \
  231. ((x).qw0_128 = QW0(y) & QW0(z), \
  232. (x).qw1_128 = QW1(y) & QW1(z),IEL_OK) : \
  233. IEL_OVFL)
  234. #define IEL_OR(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  235. ((x).dw0_32 = DW0(y) | DW0(z), \
  236. (((DW1(y) | DW1(z)) ||(QW1(y) | QW1(z))))) : \
  237. (sizeof(x) == sizeof (U64)) ? \
  238. (((x).qw0_64 = QW0(y) | QW0(z)), \
  239. ((QW1(y) | QW1(z)) != 0)) : \
  240. (sizeof(x) == sizeof (U128)) ? \
  241. ((x).qw0_128 = QW0(y) | QW0(z), \
  242. (x).qw1_128 = QW1(y) | QW1(z),IEL_OK) : \
  243. IEL_OVFL)
  244. #define IEL_XOR(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  245. ((x).dw0_32 = DW0(y) ^ DW0(z), \
  246. (((DW1(y) ^ DW1(z))||(QW1(y) ^ QW1(z))))) : \
  247. (sizeof(x) == sizeof (U64)) ? \
  248. (((x).qw0_64 = QW0(y) ^ QW0(z)), \
  249. ((QW1(y) ^ QW1(z)) != 0)) : \
  250. (sizeof(x) == sizeof (U128)) ? \
  251. ((x).qw0_128 = QW0(y) ^ QW0(z), \
  252. (x).qw1_128 = QW1(y) ^ QW1(z),IEL_OK) : \
  253. IEL_OVFL)
  254. #define IEL_ANDNOT(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  255. ((x).dw0_32 = DW0(y) & ~DW0(z), \
  256. (((DW1(y) & ~DW1(z))||(QW1(y) & ~QW1(z))))) : \
  257. (sizeof(x) == sizeof (U64)) ? \
  258. (((x).qw0_64 = QW0(y) & (~QW0(z))), \
  259. ((QW1(y) & (~QW1(z))) != 0)) : \
  260. (sizeof(x) == sizeof (U128)) ? \
  261. ((x).qw0_128 = QW0(y) & (~QW0(z)), \
  262. (x).qw1_128 = QW1(y) & (~QW1(z)),IEL_OK) : \
  263. IEL_OVFL)
  264. #define IEL_ASSIGNU(x, y) ((sizeof(x) == sizeof(U32)) ?\
  265. ((x).dw0_32 = (y).dw0_32, (DW1(y) || QW1(y))):\
  266. (sizeof(x) == sizeof (U64)) ? \
  267. ((x).qw0_64 = QW0(y), (QW1(y)!=0)) : \
  268. (sizeof(x) == sizeof (U128)) ? \
  269. ((x).qw0_128 = QW0(y), (x).qw1_128 = QW1(y), \
  270. IEL_OK) : IEL_OVFL)
  271. #define IEL_ASSIGNS(x, y) (IEL_ext1.qw0_128 = SQW0(y), \
  272. IEL_ext1.qw1_128 = SQW1(y), \
  273. (sizeof(x) == sizeof (U32)) ? \
  274. ((x).dw0_32 = IEL_ext1.dw0_128, \
  275. ((x).dw0_32 & 0x80000000) ? \
  276. (~IEL_ext1.dw1_128||~IEL_ext1.qw1_128) : \
  277. (IEL_ext1.dw1_128 || IEL_ext1.qw1_128)) : \
  278. (sizeof(x) == sizeof (U64)) ? \
  279. ((x).qw0_64 = IEL_ext1.qw0_128,\
  280. ((x).qw0_64 & 0x8000000000000000)?\
  281. (~IEL_ext1.qw1_128 !=0): (IEL_ext1.qw1_128!=0)):\
  282. (sizeof(x) == sizeof (U128)) ? \
  283. ((x).qw0_128 = IEL_ext1.qw0_128,\
  284. (x).qw1_128 = IEL_ext1.qw1_128, IEL_OK):\
  285. IEL_OVFL)
  286. #define IEL_NOT(x, y) ((sizeof(x )== sizeof(U32)) ? \
  287. ((x).dw0_32 = (~DW0(y)), \
  288. ((~DW1(y))|| (~QW1(y)))): \
  289. (sizeof(x) == sizeof (U64)) ? \
  290. ((x).qw0_64 = (~QW0(y)), \
  291. ((~QW1(y)) != 0)) : \
  292. (sizeof(x) == sizeof (U128)) ? \
  293. ((x).qw0_128 = (~QW0(y)),\
  294. (x).qw1_128 = (~QW1(y)), \
  295. IEL_OK) : IEL_OVFL)
  296. #define IEL_ZERO(x) ((sizeof(x) == sizeof (U32)) ? \
  297. ((x).dw0_32 = 0) : \
  298. (sizeof(x) == sizeof (U64)) ? \
  299. ((x).qw0_64 = 0) : \
  300. (sizeof(x) == sizeof (U128)) ? \
  301. ((x).qw0_128 = 0, (x).qw1_128 = 0, IEL_OK): \
  302. IEL_OVFL)
  303. #define QW1_1(x) ((sizeof(x)==16)? ((x).qw1_128):1)
  304. #define IEL_C0(x) (QW0(x) < QW0(IEL_ext1))
  305. /*#define IEL_C1(x) ((QW1(x)-IEL_C0(x)) < QW1(IEL_ext1))*/
  306. #define IEL_C1(x) (IEL_C0(x) ? (QW1_1(x)<=QW1(IEL_ext1)) : (QW1(x)<QW1(IEL_ext1)))
  307. #define IEL_ADDU(x, y, z) ((sizeof(x)==sizeof(U32))?\
  308. (IEL_t1=DW0(y),(x).dw0_32=DW0(y)+DW0(z),\
  309. ((IEL_t1>DW0(x))||(DW1(y))||(QW1(y)) ||\
  310. (DW1(z))||(QW1(z)))):\
  311. (sizeof(x)==sizeof(U64))?\
  312. (IEL_temp64 = QW0(y),(x).qw0_64=QW0(y)+QW0(z),\
  313. ((IEL_temp64 > QW0(x))||(QW1(y))||(QW1(z)))):\
  314. (sizeof(x)==sizeof(U128))?\
  315. (IEL_ASSIGNU(IEL_ext1, y),\
  316. (x).qw0_128=QW0(y)+QW0(z),\
  317. (x).qw1_128=QW1(y)+QW1(z)+IEL_C0(x),\
  318. IEL_C1(x)) : IEL_OVFL)
  319. #define IEL_EQU(x, y) (((Ulong64)QW0(x)==(Ulong64)QW0(y)) && \
  320. ((Ulong64)QW1(x)==(Ulong64)QW1(y)))
  321. #define IEL_ISZERO(x) ((QW0(x)==0) && (QW1(x)==0))
  322. #define IEL_CMPGU(x, y) ((QW1(x)>QW1(y)) || \
  323. ((QW1(x)==QW1(y)) && (QW0(x)>QW0(y))))
  324. #define IEL_CMPGEU(x, y) ((QW1(x)>QW1(y)) || \
  325. ((QW1(x)==QW1(y)) && (QW0(x)>=QW0(y))))
  326. #define IEL_SHL(x, y, n) ((((n) <=0) || ((n) >= (sizeof(x) << 3)))? \
  327. ((IEL_ISZERO(y)||(!(n)))? \
  328. (IEL_ASSIGNU(x,y),IEL_OK) : \
  329. (IEL_ZERO(x), IEL_OVFL)) : \
  330. ((sizeof(x) == sizeof (U32)) ? \
  331. (IEL_t1 = (DW1(y) || DW2(y) || DW3(y) \
  332. || (DW0(y)>= (U4byte)1<<(32-(n)))), \
  333. (x).dw0_32 = DW0(y) << (n), (IEL_t1)) : \
  334. (sizeof(x) == sizeof (U64)) ? \
  335. (IEL_t1 = QW1(y)||(QW0(y) >= (Ulong64)1<<(64-(n))), \
  336. (x).qw0_64= QW0(y)<<(n),IEL_t1): \
  337. ((sizeof(x) == sizeof(U128)) ? \
  338. ((n)==64)? \
  339. (IEL_t1=(QW1(y)>0),(x).qw1_128=QW0(y),\
  340. (x).qw0_128=0,IEL_t1) : \
  341. ((n)<64)? \
  342. (IEL_t1 = (QW1(y) >= (Ulong64)1<<(64-(n))),\
  343. (x).qw1_128 = (QW1(y)<<(n))|\
  344. QW0(y)>>(64-(n)),\
  345. (x).qw0_128 = QW0(y) << (n), IEL_t1) :\
  346. /* n > 64 */\
  347. (IEL_t1 = (QW1(y))||\
  348. (QW0(y) >= (Ulong64)1<<(128-(n))),\
  349. (x).qw1_128 = QW0(y) << ((n)-64),(x).qw0_128 = 0,\
  350. IEL_t1):IEL_OVFL)))
  351. #define IEL_SHL128(x, y, n) (((n)==64)? \
  352. (IEL_t1=(QW1(y)>0),(x).qw1_128=QW0(y),\
  353. (x).qw0_128=0,IEL_t1) : \
  354. ((n)<64)? \
  355. (IEL_t1 = (QW1(y) >= (Ulong64)1<<(64-(n))),\
  356. (x).qw1_128 = (QW1(y)<<(n))|\
  357. QW0(y)>>(64-(n)),\
  358. (x).qw0_128 = QW0(y) << (n), IEL_t1) :\
  359. /* n > 64 */\
  360. (IEL_t1 = QW1(y)||\
  361. (QW0(y) >= (Ulong64)1<<(128-(n))),\
  362. (x).qw1_128 = QW0(y) << ((n)-64),(x).qw0_128 = 0,\
  363. IEL_t1))
  364. #define IEL_ISNEG(x) ((sizeof(x) == sizeof(U32)) ? \
  365. ((DW0(x) & 0x80000000)!=0) : \
  366. (sizeof(x) == sizeof(U64)) ? \
  367. ((QW0(x) & 0x8000000000000000)!=0) : \
  368. (sizeof(x) == sizeof(U128)) ? \
  369. ((QW1(x) & 0x8000000000000000)!=0) : IEL_FALSE)
  370. #define IEL_ISNINF(x) ((sizeof(x) == sizeof(U32)) ? \
  371. (DW0(x)==0x80000000) : \
  372. (sizeof(x) == sizeof(U64)) ? \
  373. (QW0(x)==0x8000000000000000) : \
  374. (sizeof(x) == sizeof(U128)) ? \
  375. (QW1(x)==0x8000000000000000 && QW0(x)==0) : \
  376. (IEL_OVFL))
  377. #define IEL_INL(x, n) (((((Ulong64)1<<n)-1) & x))
  378. #define IEL_INH(x, n) (x>>n)
  379. #define IEL_SHR(x, y, n) \
  380. (((n) <=0)? ((IEL_ISZERO(y)||(!n)) \
  381. ? (IEL_ASSIGNU(x,y),IEL_OK)\
  382. : (IEL_ZERO(x), IEL_OVFL))\
  383. : \
  384. ((sizeof(x) == sizeof (U32)) ? \
  385. ((n)==64) ? \
  386. ((x).dw0_32 = (U4byte)QW1(y), (DW3(y)!=0)) : \
  387. ((n)>64) ? \
  388. ((x).dw0_32 = (U4byte)(QW1(y)>>((n)-64)),\
  389. ((QW1(y)>>((n)-64))> QW0(x))) : \
  390. /* n < 64 */ \
  391. (IEL_temp64 = (QW0(y)>>(n))|(QW1(y)<<(64-(n))),\
  392. (x).dw0_32 = (U4byte)IEL_temp64, \
  393. ((QW1(y)>>(n))> 0) || (IEL_temp64 > QW0(x))) : \
  394. (sizeof(x) == sizeof (U64)) \
  395. ? (((n)==64)? ((x).qw0_64=QW1(y),IEL_OK)\
  396. :(((n) < 64)? ((x).qw0_64 = (QW0(y)>>(n))|(QW1(y)<<(64-(n))),\
  397. (QW1(y)>>(n)!=0))\
  398. /* n > 64 */ : ((x).qw0_64 = QW1(y)>>((n)-64), IEL_OK)))\
  399. :(sizeof(x) == sizeof(U128)) \
  400. ? (((n)==64)? ((x).qw0_128=QW1(y),(x).qw1_128=0,IEL_OK) \
  401. : (((n)<64)? ((x).qw0_128 = (QW0(y)>>(n))|(QW1(y)<<(64-(n))),\
  402. (x).qw1_128 = QW1(y)>>(n),\
  403. IEL_OK)\
  404. /* n>64 */: ((x).qw0_128=QW1(y)>>((n)-64),(x).qw1_128=0,\
  405. IEL_OK)))\
  406. : IEL_OVFL))
  407. #define IEL_SHR128(x, y, n) (((n) <=0) ? \
  408. ((IEL_ISZERO(y)||!(n)) ? \
  409. (IEL_ASSIGNU(x, y), IEL_OK) :\
  410. (IEL_ZERO(x), IEL_OVFL)): \
  411. (sizeof(x) == sizeof (U128)) ? \
  412. (n==64) ? \
  413. ((x).qw0_128 = QW1(y), \
  414. (x).qw1_128 = 0, (IEL_OK)) : \
  415. (((n)<64)? ((x).qw0_128 = (QW0(y)>>(n))|(QW1(y)<<(64-(n))),\
  416. (x).qw1_128 = QW1(y)>>(n),IEL_OK)\
  417. /* n>64 */: ((x).qw0_128=QW1(y)>>((n)-64),(x).qw1_128=0,\
  418. IEL_OK)): IEL_OVFL)
  419. #define IEL_SEXT(x, y) (IEL_ASSIGNU(x,y),\
  420. ((!IEL_ISNEG(y)) || (sizeof(x)==sizeof(y))) ? \
  421. (IEL_OK) : \
  422. ((sizeof(x) == sizeof(U64)) ? \
  423. ((sizeof(y) == sizeof(U32)) ? \
  424. ((x).dw1_64=IEL_MAX32,IEL_OK):(IEL_OVFL)): \
  425. ((sizeof(x) == sizeof(U128)) ? \
  426. ((sizeof(y) == sizeof(U32)) ? \
  427. ((x).dw1_128 = IEL_MAX32, \
  428. (x).dw2_128 = IEL_MAX32, \
  429. (x).dw3_128 = IEL_MAX32, IEL_OK) : \
  430. (sizeof(y) == sizeof (U64)) ? \
  431. ((x).dw2_128 = IEL_MAX32, \
  432. (x).dw3_128 = IEL_MAX32, IEL_OK):IEL_OVFL):\
  433. (IEL_OVFL))))
  434. #define IEL_ISNEG128(x) (((x).qw1_128 & 0x8000000000000000)!=0)
  435. #define IEL_ADDU128(x, y, z) (IEL_ASSIGNU(IEL_ext1, y),\
  436. (x).qw0_128=(y).qw0_128 + (z).qw0_128,\
  437. (x).qw1_128=(y).qw1_128+(z).qw1_128+ IEL_C0(x),\
  438. IEL_C1(x))
  439. #define iel_check_result_sign(addend1, addend2, res)\
  440. ((((addend1.qw1_128 ^ addend2.qw1_128) & 0x8000000000000000) == 0) && \
  441. (((addend1.qw1_128 ^ res.qw1_128) & 0x8000000000000000) != 0))
  442. #define IEL_ADDS(x, y, z) (IEL_ASSIGNS(IEL_ext4, y), \
  443. IEL_ASSIGNS(IEL_ext2, z), \
  444. IEL_ADDU128(IEL_ext3, IEL_ext4, IEL_ext2), \
  445. IEL_ASSIGNS(x, IEL_ext3)||\
  446. iel_check_result_sign(IEL_ext4, IEL_ext2, IEL_ext3))
  447. #define IEL_SUBU(x, y, z) (IEL_ISZERO(z) ? IEL_ASSIGNU(x, y) : \
  448. (IEL_COMP(IEL_ext2 ,z), \
  449. (!(IEL_ADDU(x, y,IEL_ext2)))))
  450. #define IEL_CONVERT4L(x, y0, y1) \
  451. ((sizeof(x) == sizeof(U64)) ? \
  452. ((x).qw0_64 = y0, y1):\
  453. (sizeof(x) == sizeof(U128)) ? \
  454. ((x).qw0_128 = y0, \
  455. (x).qw1_128 = y1, \
  456. IEL_OK) : IEL_OVFL)
  457. #define IEL_CONVERT2L(x,y0) IEL_CONVERT4L(x,y0,0)
  458. #define IEL128(x) (*(U128*)(&(x)))
  459. #else /* not LP64 */
  460. #define IEL_CONST32(x) {(U4byte )(x)}
  461. #define IEL_CONST(x) IEL_CONST32(x)
  462. #ifdef BIG_ENDIAN
  463. #define IEL_CONST64(x0, x1) {{(U4byte )(x1),(U4byte )(x0)}}
  464. #define IEL_CONST128(x0, x1, x2, x3) {{x3, x2, x1, x0}}
  465. #else /* BIG_ENDIAN */
  466. #define IEL_CONST64(x0, x1) {{(U4byte )(x0), (U4byte )(x1)}}
  467. #define IEL_CONST128(x0, x1, x2, x3) {{x0, x1, x2, x3}}
  468. #endif /* BIG_ENDIAN */
  469. /* DWn_1(x) macros return 1 (instead of 0) in order to prevent warnings */
  470. /* This does not affect the produced code since the 1 can appear only in */
  471. /* a "dead portion of code" derived by preprocessor */
  472. #define DW1_1(x) ((sizeof((x))==8)?((x).dw1_64):\
  473. (sizeof((x))==16)?((x).dw1_128):1)
  474. #define DW2_1(x) ((sizeof((x))==16)?((x).dw2_128):1)
  475. #define DW3_1(x) ((sizeof((x))==16)?((x).dw3_128):1)
  476. #define SDW0(x) ((sizeof((x))==4)?((x).dw0_32):\
  477. (sizeof((x))==8)?((x).dw0_64):\
  478. (sizeof((x))==16)?((x).dw0_128):0)
  479. #define SDW1(x) ((sizeof((x))==4)?((x).dw0_32 & 0x80000000) ? -1 : 0 : \
  480. (sizeof((x))==8)?((x).dw1_64): \
  481. (sizeof((x))==16)?((x).dw1_128):0)
  482. #define SDW2(x) ((sizeof((x))==4)?((x).dw0_32 & 0x80000000) ? -1 : 0 :\
  483. (sizeof((x))==8)?((x).dw1_64 & 0x80000000) ? -1 : 0 :\
  484. (sizeof((x))==16)?((x).dw2_128):0)
  485. #define SDW3(x) ((sizeof((x))==4)?((x).dw0_32 & 0x80000000) ? -1 : 0 :\
  486. (sizeof((x))==8)?((x).dw1_64 & 0x80000000) ? -1 : 0 :\
  487. (sizeof((x))==16)?((x).dw3_128):0)
  488. #define IEL_INCU(x) ((sizeof(x)==4) ? \
  489. (((x).dw0_32++),((x).dw0_32==0)) : \
  490. (sizeof(x)==8) ? \
  491. (((x).dw0_64++),!((x).dw0_64) ? \
  492. ((x).dw1_64++, ((x).dw1_64==0)) : IEL_OK) : \
  493. (sizeof(x)==16) ? \
  494. (((x).dw0_128++),!((x).dw0_128) ? \
  495. (((x).dw1_128++),!((x).dw1_128) ? \
  496. (((x).dw2_128++),!((x).dw2_128) ? \
  497. (((x).dw3_128++),((x).dw3_128==0)) : \
  498. (IEL_OK)) : (IEL_OK)) : (IEL_OK)) : IEL_OVFL)
  499. #define IEL_INCS(x) ((sizeof(x) == sizeof(U32)) ? \
  500. (((x).dw0_32++),(((x).dw0_32==0)) || \
  501. (x).dw0_32==0x80000000): \
  502. (sizeof(x) == sizeof(U64)) ? \
  503. (((x).dw0_64++),!((x).dw0_64) ? \
  504. ((x).dw1_64++, ((x).dw1_64==0) || \
  505. (x).dw1_64==0x80000000) : IEL_OK) : \
  506. (sizeof(x) == sizeof(U128)) ? \
  507. (((x).dw0_128++),!((x).dw0_128) ? \
  508. (((x).dw1_128++),!((x).dw1_128) ? \
  509. (((x).dw2_128++),!((x).dw2_128) ? \
  510. (((x).dw3_128++),((x).dw3_128==0) || \
  511. (x).dw3_128==0x80000000) : \
  512. (IEL_OK)) : (IEL_OK)) : (IEL_OK)) : IEL_OVFL)
  513. #define IEL_DECU(x) ((sizeof(x) == sizeof(U32)) ? \
  514. (((x).dw0_32--),((x).dw0_32==IEL_MAX32)) : \
  515. (sizeof(x) == sizeof(U64)) ? \
  516. (((x).dw0_64--),((x).dw0_64==IEL_MAX32) ? \
  517. ((x).dw1_64--, ((x).dw1_64==IEL_MAX32)) : IEL_OK):\
  518. (sizeof(x) == sizeof(U128)) ? \
  519. (((x).dw0_128--),((x).dw0_128==IEL_MAX32) ? \
  520. (((x).dw1_128--),((x).dw1_128==IEL_MAX32) ? \
  521. (((x).dw2_128--),((x).dw2_128==IEL_MAX32) ? \
  522. (((x).dw3_128--),((x).dw3_128==IEL_MAX32)) : \
  523. (IEL_OK)) : (IEL_OK)) : (IEL_OK)) : IEL_OVFL)
  524. #define IEL_DECS(x) ((sizeof(x) == sizeof(U32)) ? \
  525. (((x).dw0_32--),((x).dw0_32==IEL_MAX32) || \
  526. (x).dw0_32==0x7fffffff) : \
  527. (sizeof(x) == sizeof(U64)) ? \
  528. (((x).dw0_64--),((x).dw0_64==IEL_MAX32) ? \
  529. ((x).dw1_64--, ((x).dw1_64==IEL_MAX32) || \
  530. (x).dw1_64==0x7fffffff) : IEL_OK) : \
  531. (sizeof(x) == sizeof(U128)) ? \
  532. (((x).dw0_128--),((x).dw0_128==IEL_MAX32) ? \
  533. (((x).dw1_128--),((x).dw1_128==IEL_MAX32) ? \
  534. (((x).dw2_128--),((x).dw2_128==IEL_MAX32) ? \
  535. (((x).dw3_128--),((x).dw3_128==IEL_MAX32) || \
  536. (x).dw3_128==0x7fffffff) : \
  537. (IEL_OK)) : (IEL_OK)) : (IEL_OK)) : IEL_OVFL)
  538. #define IEL_AND(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  539. ((x).dw0_32 = DW0(y) & DW0(z), \
  540. (((DW1(y) & DW1(z)) | (DW2(y) & DW2(z)) |\
  541. (DW3(y) & DW3(z))) != 0)) : \
  542. (sizeof(x) == sizeof (U64)) ? \
  543. (((x).dw0_64 = DW0(y) & DW0(z), \
  544. ((x).dw1_64 = DW1(y) & DW1(z))), \
  545. ((DW2(y) & DW2(z)) | \
  546. (DW3(y) & DW3(z))) != 0) : \
  547. (sizeof(x) == sizeof (U128)) ? \
  548. (((x).dw0_128 = DW0(y) & DW0(z)), \
  549. ((x).dw1_128 = DW1(y) & DW1(z)), \
  550. ((x).dw2_128 = DW2(y) & DW2(z)), \
  551. ((x).dw3_128 = DW3(y) & DW3(z)), \
  552. IEL_OK) : IEL_OVFL)
  553. #define IEL_OR(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  554. ((x).dw0_32 = DW0(y) | DW0(z), \
  555. (((DW1(y) | DW1(z)) | (DW2(y) | DW2(z)) |\
  556. (DW3(y) | DW3(z))) != 0)) : \
  557. (sizeof(x) == sizeof (U64)) ? \
  558. (((x).dw0_64 = DW0(y) | DW0(z), \
  559. ((x).dw1_64 = DW1(y) | DW1(z))), \
  560. ((DW2(y) | DW2(z)) | \
  561. (DW3(y) | DW3(z))) != 0) : \
  562. (sizeof(x) == sizeof (U128)) ? \
  563. (((x).dw0_128 = DW0(y) | DW0(z)), \
  564. ((x).dw1_128 = DW1(y) | DW1(z)), \
  565. ((x).dw2_128 = DW2(y) | DW2(z)), \
  566. ((x).dw3_128 = DW3(y) | DW3(z)), \
  567. IEL_OK) : IEL_OVFL)
  568. #define IEL_XOR(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  569. ((x).dw0_32 = DW0(y) ^ DW0(z), \
  570. (((DW1(y) ^ DW1(z)) | (DW2(y) ^ DW2(z)) |\
  571. (DW3(y) ^ DW3(z))) != 0)) : \
  572. (sizeof(x) == sizeof (U64)) ? \
  573. (((x).dw0_64 = DW0(y) ^ DW0(z), \
  574. ((x).dw1_64 = DW1(y) ^ DW1(z))), \
  575. ((DW2(y) ^ DW2(z)) | \
  576. (DW3(y) ^ DW3(z))) != 0) : \
  577. (sizeof(x) == sizeof (U128)) ? \
  578. (((x).dw0_128 = DW0(y) ^ DW0(z)), \
  579. ((x).dw1_128 = DW1(y) ^ DW1(z)), \
  580. ((x).dw2_128 = DW2(y) ^ DW2(z)), \
  581. ((x).dw3_128 = DW3(y) ^ DW3(z)), \
  582. IEL_OK) : IEL_OVFL)
  583. #define IEL_ANDNOT(x, y, z) ((sizeof(x) == sizeof (U32)) ? \
  584. ((x).dw0_32 = DW0(y) & (~DW0(z)), \
  585. (((DW1(y) & (~DW1(z))) | (DW2(y)&(~DW2(z)))\
  586. | (DW3(y) & (~DW3(z)))) != 0)) : \
  587. (sizeof(x) == sizeof (U64)) ? \
  588. (((x).dw0_64 = DW0(y) & (~DW0(z)), \
  589. ((x).dw1_64 = DW1(y) & (~DW1(z)))), \
  590. ((DW2(y) & (~DW2(z))) | \
  591. (DW3(y) & (~DW3(z)))) != 0) : \
  592. (sizeof(x) == sizeof (U128)) ? \
  593. (((x).dw0_128 = DW0(y) & (~DW0(z))), \
  594. ((x).dw1_128 = DW1(y) & (~DW1(z))), \
  595. ((x).dw2_128 = DW2(y) & (~DW2(z))), \
  596. ((x).dw3_128 = DW3(y) & (~DW3(z))), \
  597. IEL_OK) : IEL_OVFL)
  598. #define IEL_ASSIGNU(x, y) ((sizeof(x) == sizeof (U32)) ? \
  599. ((x).dw0_32 = DW0(y), \
  600. ((DW1(y) | DW2(y) | DW3(y)) != 0)) : \
  601. (sizeof(x) == sizeof (U64)) ? \
  602. ((x).dw0_64 = DW0(y), (x).dw1_64 = DW1(y), \
  603. ((DW2(y) | DW3(y)) != 0)) : \
  604. (sizeof(x) == sizeof(U128)) ? \
  605. ((x).dw0_128 = DW0(y), (x).dw1_128 = DW1(y),\
  606. (x).dw2_128 = DW2(y), (x).dw3_128 = DW3(y),\
  607. IEL_OK) : IEL_OVFL)
  608. #define IEL_ASSIGNS(x, y) (IEL_ext1.dw0_128 = SDW0(y), \
  609. IEL_ext1.dw1_128 = SDW1(y), \
  610. IEL_ext1.dw2_128 = SDW2(y), \
  611. IEL_ext1.dw3_128 = SDW3(y), \
  612. (sizeof(x) == sizeof (U32)) ? \
  613. ((x).dw0_32 = IEL_ext1.dw0_128, \
  614. ((x).dw0_32 & 0x80000000) ? \
  615. ((~IEL_ext1.dw1_128||~IEL_ext1.dw2_128||\
  616. ~IEL_ext1.dw3_128)) : \
  617. ((IEL_ext1.dw1_128 || IEL_ext1.dw2_128||\
  618. IEL_ext1.dw3_128) != 0)) : \
  619. (sizeof(x) == sizeof (U64)) ? \
  620. ((x).dw0_64 = IEL_ext1.dw0_128, \
  621. (x).dw1_64 = IEL_ext1.dw1_128, \
  622. ((x).dw1_64 & 0x80000000) ? \
  623. (~IEL_ext1.dw2_128||~IEL_ext1.dw3_128):\
  624. (IEL_ext1.dw2_128|| IEL_ext1.dw3_128)):\
  625. (sizeof(x) == sizeof(U128)) ? \
  626. ((x).dw0_128 = IEL_ext1.dw0_128,\
  627. (x).dw1_128 = IEL_ext1.dw1_128,\
  628. (x).dw2_128 = IEL_ext1.dw2_128,\
  629. (x).dw3_128 = IEL_ext1.dw3_128,\
  630. IEL_OK) : IEL_OVFL)
  631. /* Duplicate IEL_ASSIGNS for macro-->function transform */
  632. #define IEL_REAL_ASSIGNS(x, y) (IEL_ext1.dw0_128 = SDW0(y), \
  633. IEL_ext1.dw1_128 = SDW1(y), \
  634. IEL_ext1.dw2_128 = SDW2(y), \
  635. IEL_ext1.dw3_128 = SDW3(y), \
  636. (sizeof(x) == sizeof (U32)) ? \
  637. ((x).dw0_32 = IEL_ext1.dw0_128, \
  638. ((x).dw0_32 & 0x80000000) ? \
  639. ((~IEL_ext1.dw1_128||~IEL_ext1.dw2_128||\
  640. ~IEL_ext1.dw3_128)) : \
  641. ((IEL_ext1.dw1_128 || IEL_ext1.dw2_128||\
  642. IEL_ext1.dw3_128) != 0)) : \
  643. (sizeof(x) == sizeof (U64)) ? \
  644. ((x).dw0_64 = IEL_ext1.dw0_128, \
  645. (x).dw1_64 = IEL_ext1.dw1_128, \
  646. ((x).dw1_64 & 0x80000000) ? \
  647. (~IEL_ext1.dw2_128||~IEL_ext1.dw3_128):\
  648. (IEL_ext1.dw2_128|| IEL_ext1.dw3_128)):\
  649. (sizeof(x) == sizeof(U128)) ? \
  650. ((x).dw0_128 = IEL_ext1.dw0_128,\
  651. (x).dw1_128 = IEL_ext1.dw1_128,\
  652. (x).dw2_128 = IEL_ext1.dw2_128,\
  653. (x).dw3_128 = IEL_ext1.dw3_128,\
  654. IEL_OK) : IEL_OVFL)
  655. #define IEL_NOT(x, y) ((sizeof(x)==4) ? \
  656. ((x).dw0_32 = (~DW0(y)), \
  657. (((~DW1(y))|(~DW2(y)) | (~DW3(y))) != 0)): \
  658. (sizeof(x)==8) ? \
  659. ((x).dw0_64=(~DW0(y)), (x).dw1_64=(~DW1(y)),\
  660. (((~DW2(y)) | (~DW3(y))) != 0)) : \
  661. (sizeof(x)==16) ? \
  662. ((x).dw0_128=(~DW0(y)), \
  663. (x).dw1_128=(~DW1(y)), \
  664. (x).dw2_128 = (~DW2(y)), \
  665. (x).dw3_128 = (~DW3(y)), \
  666. IEL_OK) : IEL_OVFL)
  667. #define IEL_ZERO(x) ((sizeof(x) == sizeof(U32)) ? \
  668. ((x).dw0_32 = 0) : \
  669. (sizeof(x) == sizeof (U64)) ? \
  670. ((x).dw0_64 = 0, (x).dw1_64 = 0) : \
  671. (sizeof(x) == sizeof (U128)) ? \
  672. ((x).dw0_128 = 0, (x).dw1_128 = 0, \
  673. (x).dw2_128 = 0, (x).dw3_128 = 0, IEL_OK) :\
  674. IEL_OVFL)
  675. #define IEL_C1_1(x) (IEL_C0(x) ? (DW1_1(x)<=DW1(IEL_ext1)) : \
  676. (DW1(x)<DW1(IEL_ext1)))
  677. #define IEL_C2_1(x) (IEL_C1_1(x) ? (DW2_1(x)<=DW2(IEL_ext1)) : \
  678. (DW2(x)<DW2(IEL_ext1)))
  679. #define IEL_C3_1(x) (IEL_C2_1(x) ? (DW3_1(x)<=DW3(IEL_ext1)) : \
  680. (DW3(x)<DW3(IEL_ext1)))
  681. #define IEL_C0(x) (DW0(x) < DW0(IEL_ext1))
  682. #define IEL_C1(x) (IEL_C0(x) ? (DW1(x)<=DW1(IEL_ext1)) : \
  683. (DW1(x)<DW1(IEL_ext1)))
  684. #define IEL_C2(x) (IEL_C1(x) ? (DW2(x)<=DW2(IEL_ext1)) : \
  685. (DW2(x)<DW2(IEL_ext1)))
  686. #define IEL_C3(x) (IEL_C2(x) ? (DW3(x)<=DW3(IEL_ext1)) : \
  687. (DW3(x)<DW3(IEL_ext1)))
  688. #define IEL_R_C0(x) (DW0(x) < DW0(IEL_ext1))
  689. #define IEL_R_C1(x) (IEL_R_C0(x) ? (DW1(x)<=DW1(IEL_ext1)) : \
  690. (DW1(x)<DW1(IEL_ext1)))
  691. #define IEL_R_C2(x) (IEL_R_C1(x) ? ((sizeof(x) == sizeof(U128)) ? \
  692. (DW2_1(x)<=DW2(IEL_ext1)) : 1) : \
  693. (DW2(x)<DW2(IEL_ext1)))
  694. #define IEL_R_C3(x) (IEL_R_C2(x) ? ((sizeof(x) == sizeof(U128)) ? \
  695. (DW3_1(x)<=DW3(IEL_ext1)) : 1) : \
  696. (DW3(x)<DW3(IEL_ext1)))
  697. #define IEL_ADDU(x, y, z) ((sizeof(x)==4)?\
  698. (IEL_t1=DW0(y),(x).dw0_32=DW0(y)+DW0(z),\
  699. ((IEL_t1>DW0(x))||(DW1(y))||(DW2(y)) ||\
  700. (DW3(y))||(DW1(z))||(DW2(z))||(DW3(z)))):\
  701. (sizeof(x)==8)?\
  702. (IEL_ASSIGNU(IEL_ext1, y),\
  703. (x).dw0_64=DW0(y)+DW0(z),\
  704. (x).dw1_64=DW1(y)+DW1(z)+IEL_C0(x),\
  705. (IEL_C1_1(x)||(DW2(y))||(DW3(y))||\
  706. (DW2(z))||(DW3(z)))):\
  707. (sizeof(x)==16)?\
  708. (IEL_ASSIGNU(IEL_ext1, y),\
  709. (x).dw0_128=DW0(y)+DW0(z),\
  710. (x).dw1_128=DW1(y)+DW1(z)+IEL_C0(x),\
  711. (x).dw2_128=DW2(y)+DW2(z)+IEL_C1_1(x),\
  712. (x).dw3_128=DW3(y)+DW3(z)+IEL_C2_1(x),\
  713. (IEL_C3_1(x))): IEL_OVFL)
  714. #define IEL_EQU(x, y) ((DW0(x)==DW0(y)) && (DW1(x)==DW1(y)) && \
  715. (DW2(x)==DW2(y)) && (DW3(x)==DW3(y)))
  716. #define IEL_ISZERO(x) ((DW0(x)==0) && (DW1(x)==0) && (DW2(x)==0) && \
  717. (DW3(x)==0))
  718. #define IEL_ISNEG(x) ((sizeof(x)==4)?\
  719. ((DW0(x)&0x80000000)!=0) : \
  720. (sizeof(x)==8)?\
  721. ((DW1(x) & 0x80000000)!=0) : \
  722. (sizeof(x)==16)?\
  723. ((DW3(x)&0x80000000)!=0) : IEL_FALSE)
  724. #define IEL_ISNINF(x) ((sizeof(x) == sizeof(U32)) ? \
  725. (DW0(x)==0x80000000) : \
  726. (sizeof(x) == sizeof(U64)) ? \
  727. (DW1(x)==0x80000000 && DW0(x)==0) : \
  728. (sizeof(x) == sizeof(U128)) ? \
  729. (DW3(x)==0x80000000 && DW2(x)==0 && \
  730. DW1(x)==0 && DW0(x)==0) : IEL_FALSE)
  731. #define IEL_SEXT(x, y) (IEL_ASSIGNU(x,y),\
  732. ((!IEL_ISNEG(y)) || (sizeof(x)==sizeof(y))) ? \
  733. (IEL_OK) : \
  734. ((sizeof(x) == sizeof(U64)) ? \
  735. ((sizeof(y) == sizeof(U32)) ? \
  736. ((x).dw1_64=IEL_MAX32,IEL_OK):(IEL_OVFL)): \
  737. ((sizeof(x) == sizeof(U128)) ? \
  738. ((sizeof(y) == sizeof(U32)) ? \
  739. ((x).dw1_128 = IEL_MAX32, \
  740. (x).dw2_128 = IEL_MAX32, \
  741. (x).dw3_128 = IEL_MAX32, IEL_OK) : \
  742. (sizeof(y) == sizeof (U64)) ? \
  743. ((x).dw2_128 = IEL_MAX32, \
  744. (x).dw3_128 = IEL_MAX32, IEL_OK):IEL_OVFL):\
  745. (IEL_OVFL))))
  746. #define IEL_CMPGU(x, y) ((sizeof(x) == sizeof(U128)) ? \
  747. ((DW3_1(x)>DW3(y)) || \
  748. ((DW3(x)==DW3(y)) && (DW2_1(x)>DW2(y))) || \
  749. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  750. (DW1_1(x)>DW1(y))) || \
  751. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  752. (DW1(x)==DW1(y)) && (DW0(x)>DW0(y)))) : \
  753. (sizeof(x) == sizeof(U64)) ? \
  754. (((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  755. (DW1_1(x)>DW1(y))) || \
  756. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  757. (DW1(x)==DW1(y)) && (DW0(x)>DW0(y)))) : \
  758. /* (sizeof(x) == sizeof(U32)) */ \
  759. (((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  760. (DW1(x)==DW1(y)) && (DW0(x)>DW0(y)))))
  761. #define IEL_CMPGEU(x, y) ((sizeof(x) == sizeof(U128)) ? \
  762. ((DW3_1(x)>DW3(y)) || \
  763. ((DW3(x)==DW3(y)) && (DW2_1(x)>DW2(y))) || \
  764. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  765. (DW1_1(x)>DW1(y))) || \
  766. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  767. (DW1(x)==DW1(y)) && (DW0(x)>=DW0(y)))) : \
  768. (sizeof(x) == sizeof(U64)) ? \
  769. (((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  770. (DW1_1(x)>DW1(y))) || \
  771. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  772. (DW1(x)==DW1(y)) && (DW0(x)>=DW0(y)))) : \
  773. /* (sizeof(x) == sizeof(U32)) */ \
  774. (((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  775. (DW1(x)==DW1(y)) && (DW0(x)>=DW0(y)))))
  776. /*
  777. #define IEL_CMPGU(x, y) ((DW3(x)>DW3(y)) || \
  778. ((DW3(x)==DW3(y)) && (DW2(x)>DW2(y))) || \
  779. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  780. (DW1(x)>DW1(y))) || \
  781. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  782. (DW1(x)==DW1(y)) && (DW0(x)>DW0(y))))
  783. #define IEL_CMPGEU(x, y) ((DW3(x)>DW3(y)) || \
  784. ((DW3(x)==DW3(y)) && (DW2(x)>DW2(y))) || \
  785. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  786. (DW1(x)>DW1(y))) || \
  787. ((DW3(x)==DW3(y)) && (DW2(x)==DW2(y)) && \
  788. (DW1(x)==DW1(y)) && (DW0(x)>=DW0(y))))
  789. */
  790. #define IEL_SHL(x, y, n) (IEL_t2=n, \
  791. ((n) <=0 || (n) >= (sizeof(x)<<3)) ? \
  792. ((IEL_ISZERO(y)||!(n)) ? \
  793. (IEL_ASSIGNU(x, y), IEL_OK) :\
  794. (IEL_ZERO(x), IEL_OVFL)):\
  795. ((sizeof(x) == sizeof (U32)) ? \
  796. (IEL_t1 = (DW1(y) || DW2(y) || DW3(y) \
  797. || (DW0(y)>= ((U4byte)1<<(32-IEL_t2)))), \
  798. (x).dw0_32 = DW0(y) << IEL_t2, (IEL_t1)) : \
  799. (sizeof(x) == sizeof (U64)) ? \
  800. ((n) == 32) ? ((IEL_t1 = DW3(y) || DW2(y)\
  801. || DW1(y)), \
  802. (x).dw1_64 = DW0(y), \
  803. (x).dw0_64 = 0, \
  804. (IEL_t1)) : \
  805. ((n) < 32) ? \
  806. (IEL_t1 = (DW2(y) || DW3(y) || \
  807. (DW1(y)>=((U4byte)1<<(32-IEL_t2)))), \
  808. (x).dw1_64 = DW1(y)<<IEL_t2 | \
  809. DW0(y)>>(32-IEL_t2), \
  810. (x).dw0_64 = DW0(y)<<IEL_t2,(IEL_t1)) :\
  811. (IEL_t1 = (DW1(y) || DW2(y) || DW3(y) ||\
  812. ((DW0(y)>=((U4byte)1<<(64-IEL_t2))))),\
  813. (x).dw1_64 = DW0(y)<<(IEL_t2-32), \
  814. (x).dw0_64 = 0, (IEL_t1)) : \
  815. (sizeof(x) == sizeof (U128)) ? \
  816. ((n)==32) ? (IEL_t1 = (DW3(y)), \
  817. (x).dw3_128 = DW2(y), \
  818. (x).dw2_128 = DW1(y), \
  819. (x).dw1_128 = DW0(y), \
  820. (x).dw0_128 = 0, (IEL_t1!=0)) : \
  821. ((n)==64) ? (IEL_t1 = (DW3(y) || DW2(y)),\
  822. (x).dw3_128 = DW1(y), \
  823. (x).dw2_128 = DW0(y), \
  824. (x).dw1_128 = 0, \
  825. (x).dw0_128 = 0, (IEL_t1)) : \
  826. ((n)==96) ? (IEL_t1 = (DW3(y) || DW2(y) \
  827. || DW1(y)), \
  828. (x).dw3_128 = DW0(y), \
  829. (x).dw2_128 = 0, \
  830. (x).dw1_128 = 0, \
  831. (x).dw0_128 = 0, (IEL_t1)) : \
  832. ((n)>96) ? \
  833. (IEL_t1 = (DW1(y) || DW2(y) || DW3(y) ||\
  834. ((DW0(y)>=((U4byte)1<<(128-IEL_t2))))), \
  835. (x).dw3_128 = DW0(y)<<(IEL_t2-96), \
  836. (x).dw2_128 = 0, \
  837. (x).dw1_128 = 0, \
  838. (x).dw0_128 = 0, \
  839. (IEL_t1)) : \
  840. ((n)>64) ? \
  841. (IEL_t1 = (DW2(y) || DW3(y) || \
  842. ((DW1(y)>=(U4byte)1<<(96-IEL_t2)))),\
  843. (x).dw3_128 = DW1(y)<<(IEL_t2-64) | \
  844. DW0(y)>>(96-IEL_t2),\
  845. (x).dw2_128 = DW0(y)<<(IEL_t2-64), \
  846. (x).dw1_128 = 0, \
  847. (x).dw0_128 = 0, \
  848. (IEL_t1)) : \
  849. ((n)>32) ? \
  850. (IEL_t1 = (DW3(y) || ((IEL_t2!=32) & \
  851. (DW2(y)>=(U4byte)1<<(64-IEL_t2)))),\
  852. (x).dw3_128 = DW2(y)<<(IEL_t2-32) | \
  853. DW1(y)>>(64-IEL_t2),\
  854. (x).dw2_128 = DW1(y)<<(IEL_t2-32) | \
  855. DW0(y)>>(64-IEL_t2),\
  856. (x).dw1_128 = DW0(y)<<(IEL_t2-32), \
  857. (x).dw0_128 = 0, \
  858. (IEL_t1)) : \
  859. (IEL_t1 = (DW3(y)>=(U4byte)1<<(32-IEL_t2)), \
  860. (x).dw3_128 = DW3(y)<<(IEL_t2) | \
  861. DW2(y)>>(32-IEL_t2),\
  862. (x).dw2_128 = DW2(y)<<(IEL_t2) | \
  863. DW1(y)>>(32-IEL_t2),\
  864. (x).dw1_128 = DW1(y)<<(IEL_t2) | \
  865. DW0(y)>>(32-IEL_t2),\
  866. (x).dw0_128 = DW0(y)<<IEL_t2, \
  867. (IEL_t1)) : (IEL_OVFL)))
  868. #define IEL_SHL128(x, y, n) (IEL_t2=(n), \
  869. (sizeof(x) == sizeof (U128)) ? \
  870. ((n)==32) ? (IEL_t1 = (U4byte)(DW3(y)), \
  871. (x).dw3_128 = (U4byte)DW2(y), \
  872. (x).dw2_128 = (U4byte)DW1(y), \
  873. (x).dw1_128 = (U4byte)DW0(y), \
  874. (x).dw0_128 = 0, (IEL_t1!=0)) : \
  875. ((n)==64) ? (IEL_t1 = (U4byte)(DW3(y) || DW2(y)),\
  876. (x).dw3_128 = (U4byte)DW1(y), \
  877. (x).dw2_128 = (U4byte)DW0(y), \
  878. (x).dw1_128 = 0, \
  879. (x).dw0_128 = 0, (IEL_t1)) : \
  880. ((n)==96) ? (IEL_t1 = (U4byte)(DW3(y) || DW2(y) \
  881. || DW1(y)), \
  882. (x).dw3_128 = (U4byte)DW0(y), \
  883. (x).dw2_128 = 0, \
  884. (x).dw1_128 = 0, \
  885. (x).dw0_128 = 0, (IEL_t1)) : \
  886. ((n)>96) ? \
  887. (IEL_t1 = (U4byte)(DW1(y) || DW2(y) || DW3(y) ||\
  888. ((DW0(y)>=((U4byte)1<<(128-IEL_t2))))), \
  889. (x).dw3_128 = (U4byte)DW0(y)<<(IEL_t2-96), \
  890. (x).dw2_128 = 0, \
  891. (x).dw1_128 = 0, \
  892. (x).dw0_128 = 0, \
  893. (IEL_t1)) : \
  894. ((n)>64) ? \
  895. (IEL_t1 = (U4byte)(DW2(y) || DW3(y) || \
  896. ((DW1(y)>=(U4byte)1<<(96-IEL_t2)))),\
  897. (x).dw3_128 = (U4byte)DW1(y)<<(IEL_t2-64) | \
  898. DW0(y)>>(96-IEL_t2),\
  899. (x).dw2_128 = (U4byte)DW0(y)<<(IEL_t2-64), \
  900. (x).dw1_128 = 0, \
  901. (x).dw0_128 = 0, \
  902. (IEL_t1)) : \
  903. ((n)>32) ? \
  904. (IEL_t1 = (U4byte)(DW3(y) || ((IEL_t2!=32) & \
  905. (DW2(y)>=(U4byte)1<<(64-IEL_t2)))),\
  906. (x).dw3_128 = (U4byte)DW2(y)<<(IEL_t2-32) | \
  907. DW1(y)>>(64-IEL_t2),\
  908. (x).dw2_128 = (U4byte)DW1(y)<<(IEL_t2-32) | \
  909. DW0(y)>>(64-IEL_t2),\
  910. (x).dw1_128 = (U4byte)DW0(y)<<(IEL_t2-32), \
  911. (x).dw0_128 = 0, \
  912. (IEL_t1)) : \
  913. (IEL_t1 = (U4byte)(DW3(y)>=(U4byte)1<<(32-IEL_t2)), \
  914. (x).dw3_128 = (U4byte)DW3(y)<<(IEL_t2) | \
  915. DW2(y)>>(32-IEL_t2),\
  916. (x).dw2_128 = (U4byte)DW2(y)<<(IEL_t2) | \
  917. DW1(y)>>(32-IEL_t2),\
  918. (x).dw1_128 = (U4byte)DW1(y)<<(IEL_t2) | \
  919. DW0(y)>>(32-IEL_t2),\
  920. (x).dw0_128 = (U4byte)DW0(y)<<IEL_t2, \
  921. (IEL_t1)) : (IEL_OVFL))
  922. #define IEL_INL(x, n) (((((U4byte)1<<n)-1) & x))
  923. #define IEL_INH(x, n) (x>>n)
  924. #define IEL_SHR(x, y, n) (IEL_t2=n, \
  925. ((n) <=0) ? \
  926. ((IEL_ISZERO(y)||!(n)) ? \
  927. (IEL_ASSIGNU(x, y), IEL_OK) :\
  928. (IEL_ZERO(x), IEL_OVFL)): \
  929. ((sizeof(x) == sizeof (U32)) ? \
  930. ((n)==32) ? \
  931. ((x).dw0_32 = DW1(y), \
  932. (DW3(y) || DW2(y))) : \
  933. ((n)==64) ? \
  934. ((x).dw0_32 = DW2(y), \
  935. (DW3(y)!=0)) : \
  936. ((n)==96) ? \
  937. ((x).dw0_32 = DW3(y), \
  938. (IEL_OK)) : \
  939. ((n)>96) ? \
  940. ((x).dw0_32 = DW3(y)>>(IEL_t2-96), \
  941. (IEL_OK)) : \
  942. ((n)>64) ? \
  943. ((x).dw0_32 = ((DW2(y)>>(IEL_t2-64))| \
  944. (DW3(y)<<(96-IEL_t2))),\
  945. ((DW3(y)>>(IEL_t2-64))!=0)) : \
  946. ((n)>32) ? \
  947. ((x).dw0_32 = ((DW1(y)>>(IEL_t2-32))| \
  948. (DW2(y)<<(64-IEL_t2))), \
  949. ((DW2(y)>>(IEL_t2-32)) || DW3(y))) : \
  950. ((x).dw0_32 = DW0(y)>>(IEL_t2) | \
  951. DW1(y)<<(32-IEL_t2),\
  952. (DW3(y) || DW2(y) ||DW1(y)>>(IEL_t2))) : \
  953. (sizeof(x) == sizeof (U64)) ? \
  954. ((n)==32) ? \
  955. ((x).dw0_64 = DW1(y), \
  956. (x).dw1_64 = DW2(y), \
  957. (DW3(y)!=0)) : \
  958. ((n)==64) ? \
  959. ((x).dw0_64 = DW2(y), \
  960. (x).dw1_64 = DW3(y), \
  961. (IEL_OK)) : \
  962. ((n)==96) ? \
  963. ((x).dw0_64 = DW3(y), \
  964. (x).dw1_64 = 0, \
  965. (IEL_OK)) : \
  966. ((n)>96) ? \
  967. ((x).dw0_64 = DW3(y)>>(IEL_t2-96), \
  968. (x).dw1_64 = 0, \
  969. (IEL_OK)) : \
  970. ((n)>64) ? \
  971. ((x).dw0_64 = ((DW2(y)>>(IEL_t2-64))| \
  972. (DW3(y)<<(96-IEL_t2))),\
  973. (x).dw1_64 = DW3(y)>>(IEL_t2-64), \
  974. (IEL_OK)) : \
  975. ((n)>32) ? \
  976. ((x).dw0_64 = ((DW1(y)>>(IEL_t2-32))| \
  977. (DW2(y)<<(64-IEL_t2))), \
  978. (x).dw1_64 = ((DW2(y)>>(IEL_t2-32))| \
  979. (DW3(y)<<(64-IEL_t2))),\
  980. (DW3(y)>>(IEL_t2-32) != 0)) : \
  981. ((x).dw0_64 = DW0(y)>>(IEL_t2) | \
  982. DW1(y)<<(32-IEL_t2),\
  983. (x).dw1_64 = DW1(y)>>(IEL_t2) | \
  984. DW2(y)<<(32-IEL_t2),\
  985. (DW3(y) || DW2(y)>>(IEL_t2))) : \
  986. (sizeof(x) == sizeof (U128)) ? \
  987. ((n)==32) ? \
  988. ((x).dw0_128 = DW1(y), \
  989. (x).dw1_128 = DW2(y), \
  990. (x).dw2_128 = DW3(y), \
  991. (x).dw3_128 = 0, (IEL_OK)) : \
  992. ((n)==64) ? \
  993. ((x).dw0_128 = DW2(y), \
  994. (x).dw1_128 = DW3(y), \
  995. (x).dw2_128 = 0, \
  996. (x).dw3_128 = 0, (IEL_OK)) : \
  997. ((n)==96) ? \
  998. ((x).dw0_128 = DW3(y), \
  999. (x).dw1_128 = 0, \
  1000. (x).dw2_128 = 0, \
  1001. (x).dw3_128 = 0, (IEL_OK)) : \
  1002. ((n)>96) ? \
  1003. ((x).dw0_128 = DW3(y)>>(IEL_t2-96), \
  1004. (x).dw1_128 = 0, \
  1005. (x).dw2_128 = 0, \
  1006. (x).dw3_128 = 0, \
  1007. (IEL_OK)) : \
  1008. ((n)>64) ? \
  1009. ((x).dw0_128 = ((DW2(y)>>(IEL_t2-64))| \
  1010. (DW3(y)<<(96-IEL_t2))),\
  1011. (x).dw1_128 = DW3(y)>>(IEL_t2-64), \
  1012. (x).dw2_128 = 0, \
  1013. (x).dw3_128 = 0, \
  1014. (IEL_OK)) : \
  1015. ((n)>32) ? \
  1016. ((x).dw0_128 = ((DW1(y)>>(IEL_t2-32))| \
  1017. (DW2(y)<<(64-IEL_t2))), \
  1018. (x).dw1_128 = ((DW2(y)>>(IEL_t2-32))| \
  1019. (DW3(y)<<(64-IEL_t2))),\
  1020. (x).dw2_128 = DW3(y)>>(IEL_t2-32), \
  1021. (x).dw3_128 = 0, \
  1022. (IEL_OK)) : \
  1023. ((x).dw0_128 = DW0(y)>>(IEL_t2) | \
  1024. DW1(y)<<(32-IEL_t2),\
  1025. (x).dw1_128 = DW1(y)>>(IEL_t2) | \
  1026. DW2(y)<<(32-IEL_t2),\
  1027. (x).dw2_128 = DW2(y)>>(IEL_t2) | \
  1028. DW3(y)<<(32-IEL_t2),\
  1029. (x).dw3_128 = DW3(y)>>IEL_t2, \
  1030. (IEL_OK)) : (IEL_OVFL)))
  1031. #define IEL_SHR128(x, y, n) (IEL_t2=n, \
  1032. ((n) <=0) ? \
  1033. ((IEL_ISZERO(y)||!(n)) ? \
  1034. (IEL_ASSIGNU(x, y), IEL_OK) :\
  1035. (IEL_ZERO(x), IEL_OVFL)): \
  1036. (sizeof(x) == sizeof (U128)) ? \
  1037. ((n)==32) ? \
  1038. ((x).dw0_128 = DW1(y), \
  1039. (x).dw1_128 = DW2(y), \
  1040. (x).dw2_128 = DW3(y), \
  1041. (x).dw3_128 = 0, (IEL_OK)) : \
  1042. ((n)==64) ? \
  1043. ((x).dw0_128 = DW2(y), \
  1044. (x).dw1_128 = DW3(y), \
  1045. (x).dw2_128 = 0, \
  1046. (x).dw3_128 = 0, (IEL_OK)) : \
  1047. ((n)==96) ? \
  1048. ((x).dw0_128 = DW3(y), \
  1049. (x).dw1_128 = 0, \
  1050. (x).dw2_128 = 0, \
  1051. (x).dw3_128 = 0, (IEL_OK)) : \
  1052. ((n)>96) ? \
  1053. ((x).dw0_128 = DW3(y)>>(IEL_t2-96), \
  1054. (x).dw1_128 = 0, \
  1055. (x).dw2_128 = 0, \
  1056. (x).dw3_128 = 0, \
  1057. (IEL_OK)) : \
  1058. ((n)>64) ? \
  1059. ((x).dw0_128 = ((DW2(y)>>(IEL_t2-64))| \
  1060. (DW3(y)<<(96-IEL_t2))),\
  1061. (x).dw1_128 = DW3(y)>>(IEL_t2-64), \
  1062. (x).dw2_128 = 0, \
  1063. (x).dw3_128 = 0, \
  1064. (IEL_OK)) : \
  1065. ((n)>32) ? \
  1066. ((x).dw0_128 = ((DW1(y)>>(IEL_t2-32))| \
  1067. (DW2(y)<<(64-IEL_t2))), \
  1068. (x).dw1_128 = ((DW2(y)>>(IEL_t2-32))| \
  1069. (DW3(y)<<(64-IEL_t2))),\
  1070. (x).dw2_128 = DW3(y)>>(IEL_t2-32), \
  1071. (x).dw3_128 = 0, \
  1072. (IEL_OK)) : \
  1073. ((x).dw0_128 = DW0(y)>>(IEL_t2) | \
  1074. DW1(y)<<(32-IEL_t2),\
  1075. (x).dw1_128 = DW1(y)>>(IEL_t2) | \
  1076. DW2(y)<<(32-IEL_t2),\
  1077. (x).dw2_128 = DW2(y)>>(IEL_t2) | \
  1078. DW3(y)<<(32-IEL_t2),\
  1079. (x).dw3_128 = DW3(y)>>IEL_t2, \
  1080. (IEL_OK)) : (IEL_OVFL))
  1081. #ifndef IEL_USE_FUNCTIONS
  1082. #define IEL_ADDS(x, y, z) (IEL_ASSIGNS(IEL_ext4, y), \
  1083. IEL_ASSIGNS(IEL_ext2, z), \
  1084. IEL_ADDU (IEL_ext3, IEL_ext4, IEL_ext2), \
  1085. ((IEL_ISNEG(IEL_ext4) && IEL_ISNEG(IEL_ext2) && \
  1086. (!(IEL_ISNEG(IEL_ext3)))) | \
  1087. ((!(IEL_ISNEG(IEL_ext4))) && \
  1088. (!(IEL_ISNEG(IEL_ext2))) && \
  1089. IEL_ISNEG(IEL_ext3)) | \
  1090. (IEL_ASSIGNS(x, IEL_ext3))))
  1091. #else
  1092. #define IEL_ADDU128(x, y, z) (IEL_ASSIGNU(IEL_ext1, y),\
  1093. (x).dw0_128=DW0(y)+DW0(z),\
  1094. (x).dw1_128=DW1(y)+DW1(z)+IEL_C0(x),\
  1095. (x).dw2_128=DW2(y)+DW2(z)+IEL_C1(x),\
  1096. (x).dw3_128=DW3(y)+DW3(z)+IEL_C2(x),\
  1097. (IEL_C3(x)))
  1098. #define IEL_ISNEG128(x) ((DW3(x)&0x80000000)!=0)
  1099. #define IEL_ADDS(x, y, z) (IEL_ASSIGNS(IEL_ext4, y), \
  1100. IEL_ASSIGNS(IEL_ext2, z), \
  1101. IEL_ADDU128 (IEL_ext3, IEL_ext4, IEL_ext2), \
  1102. ((IEL_ISNEG128(IEL_ext4) && \
  1103. IEL_ISNEG128(IEL_ext2) && \
  1104. (!(IEL_ISNEG128(IEL_ext3)))) | \
  1105. ((!(IEL_ISNEG128(IEL_ext4))) && \
  1106. (!(IEL_ISNEG128(IEL_ext2))) && \
  1107. IEL_ISNEG128(IEL_ext3)) | \
  1108. (IEL_ASSIGNS(x, IEL_ext3))))
  1109. #endif
  1110. #endif /*** not LP64 ***/
  1111. #define IEL_SEXT64(x) ((x).dw1_64 = ((x).dw0_64 & 0x80000000) ? -1 : 0)
  1112. /* common for lp32 and lp64 */
  1113. #define IEL_CONVERT4(x, y0, y1, y2, y3) \
  1114. ((sizeof(x) == sizeof(U32)) ? \
  1115. ((x).dw0_32 = y0, y1 || y2 || y3) : \
  1116. (sizeof(x) == sizeof(U64)) ? \
  1117. ((x).dw0_64 = y0, \
  1118. (x).dw1_64 = y1, \
  1119. y2 || y3) :\
  1120. (sizeof(x) == sizeof(U128)) ? \
  1121. ((x).dw0_128 = y0, \
  1122. (x).dw1_128 = y1, \
  1123. (x).dw2_128 = y2, \
  1124. (x).dw3_128 = y3, \
  1125. IEL_OK) : IEL_OVFL)
  1126. #define IEL_CONVERT2(x, y0, y1) IEL_CONVERT4(x, y0, y1, 0, 0)
  1127. #define IEL_CONVERT1(x, y0) IEL_CONVERT4(x, y0, 0, 0, 0)
  1128. #define IEL_CONVERT IEL_CONVERT4
  1129. #define IEL_COMP(x, y) (IEL_NOT(x, y), IEL_INCU(x), IEL_OK)
  1130. #define IEL_COMPLEMENTS(x, y) (IEL_ASSIGNS(IEL_ts1, y), \
  1131. IEL_COMP(IEL_ts1, IEL_ts1), \
  1132. IEL_ASSIGNS(x, IEL_ts1))
  1133. #define IEL_CMPEU(x, y) IEL_EQU(x, y)
  1134. #define IEL_CMPNEU(x, y) (!(IEL_EQU(x, y)))
  1135. #define IEL_CMPLU(x, y) IEL_CMPGU(y, x)
  1136. #define IEL_CMPLEU(x, y) IEL_CMPGEU(y, x)
  1137. #define IEL_CMPU(x, y) (IEL_CMPGU(x, y)-IEL_CMPLU(x, y))
  1138. #define IEL_SUBU(x, y, z) (IEL_ISZERO(z) ? IEL_ASSIGNU(x, y) : \
  1139. (IEL_COMP(IEL_ext2 ,z), \
  1140. (!(IEL_ADDU(x, y,IEL_ext2)))))
  1141. #define IEL_SUBS(x, y, z) (IEL_ISZERO(z) ? IEL_ASSIGNS(x, y) : \
  1142. (IEL_ASSIGNS(IEL_ext5, z), \
  1143. IEL_COMP(IEL_ext5,IEL_ext5),\
  1144. IEL_ADDS(x, y, IEL_ext5)||IEL_ISNINF(IEL_ext5)))
  1145. #define IEL_CMPES(x, y) (IEL_ASSIGNS(IEL_ts1, x), \
  1146. IEL_ASSIGNS(IEL_ts2, y), \
  1147. IEL_CMPEU(IEL_ts1, IEL_ts2))
  1148. #define IEL_CMPNES(x, y) (!(IEL_CMPES(x, y)))
  1149. #define IEL_CMPGS(x, y) (((IEL_ISNEG(x)) && (!(IEL_ISNEG(y)))) ? (0) : \
  1150. ((!(IEL_ISNEG(x))) && (IEL_ISNEG(y))) ? (1) : \
  1151. (IEL_ASSIGNS(IEL_ext3, x), \
  1152. IEL_ASSIGNS(IEL_ext4, y), \
  1153. IEL_CMPGU(IEL_ext3, IEL_ext4)))
  1154. #define IEL_CMPGES(x, y) (IEL_CMPGS(x, y) || IEL_CMPES(x, y))
  1155. #define IEL_CMPLES(x, y) IEL_CMPGES(y, x)
  1156. #define IEL_CMPLS(x, y) IEL_CMPGS(y, x)
  1157. #define IEL_CMPS(x, y) (IEL_CMPGS(x, y)-IEL_CMPLS(x, y))
  1158. #define IEL_CHECKU(x, n) (!IEL_SHL128(IEL_ext1, x, 128-(n)))
  1159. #define IEL_CHECKS(x, n) ((IEL_ISNEG(x)) ? \
  1160. (IEL_ASSIGNS(IEL_ts1, x), \
  1161. IEL_COMP(IEL_ts1, IEL_ts1), \
  1162. !((IEL_SHL128(IEL_ts1, IEL_ts1, 128-(n))) || \
  1163. (IEL_ISNEG(IEL_ts1)&&(!IEL_ISNINF(IEL_ts1))))):\
  1164. (!(IEL_SHL128(IEL_ts1, x, 128-(n)) || \
  1165. IEL_ISNEG(IEL_ts1))))
  1166. #define IEL_SAR(x, y, n) (IEL_ISNEG(y) ? \
  1167. (IEL_SEXT(IEL_ext4, y), (IEL_SHR(x, IEL_ext4, n), \
  1168. IEL_SHL(IEL_ext5, IEL_MINUS1, 128-n), \
  1169. IEL_OR(IEL_ext5, x, IEL_ext5) , \
  1170. ((IEL_ASSIGNS(x,IEL_ext5))||(n>=(sizeof(x)<<3))))) \
  1171. : IEL_SHR(x, y, n))
  1172. #define IEL_MULU(x, y, z) (IEL_ASSIGNU (IEL_ext2, y), \
  1173. IEL_ASSIGNU (IEL_ext3, z), \
  1174. (IEL_t4=IEL_mul(&IEL_ext1,&IEL_ext2,&IEL_ext3),\
  1175. IEL_ASSIGNU (x, IEL_ext1) || IEL_t4))
  1176. #define IEL_MULS(x, y, z) (IEL_ASSIGNS (IEL_ext2, y), \
  1177. IEL_ASSIGNS (IEL_ext3, z), \
  1178. IEL_t3 = IEL_ISNEG(y)^IEL_ISNEG(z), \
  1179. (IEL_ISNEG(IEL_ext2)) ? \
  1180. IEL_COMP(IEL_ext2, IEL_ext2) : (0),\
  1181. (IEL_ISNEG(IEL_ext3)) ? \
  1182. IEL_COMP(IEL_ext3, IEL_ext3) : (0),\
  1183. IEL_t2 = \
  1184. (IEL_mul(&IEL_ext1, &IEL_ext2, &IEL_ext3) ||\
  1185. (IEL_ISNEG(IEL_ext1) && \
  1186. (!IEL_ISNINF(IEL_ext1)))), \
  1187. IEL_t3 ? IEL_COMP(IEL_ext1,IEL_ext1):(0),\
  1188. (IEL_ASSIGNS(x,IEL_ext1) || IEL_t2))
  1189. #define IEL_DIVU(x, y, z) (IEL_ISZERO(z) ? (IEL_ASSIGNU(x,IEL_POSINF), \
  1190. IEL_OVFL):\
  1191. (IEL_ASSIGNU (IEL_ext2, y), \
  1192. IEL_ASSIGNU (IEL_ext3, z), \
  1193. (IEL_t4=IEL_div(&IEL_ext1,&IEL_ext2,&IEL_ext3),\
  1194. IEL_ASSIGNU (x, IEL_ext1) || IEL_t4)))
  1195. #define IEL_DIVS(x, y, z) (IEL_ISZERO(z) ? ((IEL_ISNEG(y)) ? \
  1196. IEL_ASSIGNU(IEL_ext2, IEL_NEGINF): \
  1197. IEL_ASSIGNU(IEL_ext2, IEL_POSINF)\
  1198. , IEL_ASSIGNU(x, IEL_ext2), IEL_OVFL) :\
  1199. (IEL_ASSIGNS (IEL_ext2, y), \
  1200. IEL_ASSIGNS (IEL_ext3, z), \
  1201. IEL_t3 = IEL_ISNEG(y)^IEL_ISNEG(z), \
  1202. (IEL_ISNEG(IEL_ext2)) ? \
  1203. IEL_COMP(IEL_ext2, IEL_ext2) : (0),\
  1204. (IEL_ISNEG(IEL_ext3)) ? \
  1205. IEL_COMP(IEL_ext3, IEL_ext3) : (0),\
  1206. IEL_t2 = \
  1207. (IEL_div(&IEL_ext1, &IEL_ext2, &IEL_ext3) ||\
  1208. (IEL_ISNEG(IEL_ext1) && (!IEL_t3))), \
  1209. IEL_t3 ? IEL_COMP(IEL_ext1,IEL_ext1):(0),\
  1210. (IEL_ASSIGNS(x,IEL_ext1) || IEL_t2)))
  1211. #define IEL_REMU(x, y, z) (IEL_ASSIGNU (IEL_ext2, y), \
  1212. IEL_ASSIGNU (IEL_ext3, z), \
  1213. (IEL_t1 = IEL_rem(&IEL_ext1, &IEL_ext2, &IEL_ext3), \
  1214. IEL_t2 = IEL_ASSIGNU (x, IEL_ext1), IEL_t1||IEL_t2))
  1215. #define IEL_REMS(x, y, z) (IEL_ASSIGNS (IEL_ext2, y), \
  1216. IEL_ASSIGNS (IEL_ext3, z), \
  1217. IEL_t3 = IEL_ISNEG(y), \
  1218. (IEL_ISNEG(IEL_ext2)) ? \
  1219. IEL_COMP(IEL_ext2, IEL_ext2) : (0),\
  1220. (IEL_ISNEG(IEL_ext3)) ? \
  1221. IEL_COMP(IEL_ext3, IEL_ext3) : (0),\
  1222. IEL_t2 = \
  1223. (IEL_rem(&IEL_ext1, &IEL_ext2, &IEL_ext3)|| \
  1224. IEL_ISNEG(IEL_ext1)), \
  1225. IEL_t3 ? IEL_COMP(IEL_ext1,IEL_ext1):(0),\
  1226. (IEL_ASSIGNS(x,IEL_ext1) || IEL_t2))
  1227. /**** INT64.H MACROS ****/
  1228. #ifdef IEL_INT64
  1229. #define INCU64(x) (IEL_INCU(IEL64(x)), (x))
  1230. #define DECU64(x) (IEL_DECU(IEL64(x)), (x))
  1231. #define ADDU64(x, y, t) (IEL_ADDU(IEL64(x), IEL64(x), IEL64(y)), (x))
  1232. #define SUBU64(x, y, t) (IEL_SUBU(IEL64(x), IEL64(x), IEL64(y)), (x))
  1233. #define ANDNOT64(x, y) (IEL_ANDNOT(IEL64(x), IEL64(x), IEL64(y)),(x))
  1234. #define AND64NOT32(x, y) (IEL_ANDNOT(IEL64(x), IEL64(x), IEL32(y)),(x))
  1235. #define ANDU64(x, y) (IEL_AND(IEL64(x), IEL64(x), IEL64(y)), (x))
  1236. #define ORU64(x, y) (IEL_OR(IEL64(x), IEL64(x), IEL64(y)), (x))
  1237. #define NOTU64(x) (IEL_NOT(IEL64(x), IEL64(x)), (x))
  1238. #define ZU64(x) (IEL_ZERO(IEL64(x)), (x))
  1239. #define INIT64(x, y) (IEL_CONVERT1(x, y), (x))
  1240. #define CONST64(x) IEL_CONST64(x, 0)
  1241. #define SCONST64(x) IEL_CONST64(x, x>>31)
  1242. #define CONST64_64(x, y) IEL_CONST64(y, x)
  1243. #define ISZERO64(x) (IEL_ISZERO(IEL64(x)))
  1244. #define EQU64(x, y) (IEL_EQU(IEL64(x), IEL64(y)))
  1245. #define LEU64(x, y) (IEL_CMPLEU(IEL64(x), IEL64(y)))
  1246. #define LU64(x, y) (IEL_CMPLU(IEL64(x), IEL64(y)))
  1247. #define LSU64(x, y) (IEL_CMPLS(IEL64(x), IEL64(y)))
  1248. #define GEU64(x, y) (IEL_CMPGEU(IEL64(x), IEL64(y)))
  1249. #define GU64(x, y) (IEL_CMPGU(IEL64(x), IEL64(y)))
  1250. #define CMP64(x, y, t) (IEL_CMPU(IEL64(x), IEL64(y)))
  1251. #define SHL64(x, y) (IEL_SHL(IEL64(x), IEL64(x), y), (x))
  1252. #define ISNEG(x) (IEL_ISNEG(IEL64(x)))
  1253. #define SEXT64(x) ((x).dw1_64 = ((x).dw0_64 & 0x80000000) ? -1 : 0)
  1254. #define CMP128(x, y, t) (IEL_CMPU(IEL128(x), IEL128(y)))
  1255. #define EQU128(x, y) (IEL_EQU(IEL128(x), IEL128(y)))
  1256. #define LU64TU32(a, b) (IEL_CMPLU(IEL64(a), IEL32(b)))
  1257. #define LU64EU32(a,b) (IEL_CMPLEU(IEL64(a), IEL32(b)))
  1258. #define GU64TU32(a,b) (IEL_CMPGU(IEL64(a), IEL32(b)))
  1259. #define GU64EU32(a,b) (IEL_CMPGEU(IEL64(a), IEL32(b)))
  1260. #define GU64_32(a,b) (GU64TU32(a, b))
  1261. #define INITL64(x, y, z) (IEL_CONVERT2(x, z, y), (IEL64(x)))
  1262. #ifdef LP64
  1263. # define ADD2U64(x, y) ADDU64(x, y, 0)
  1264. # define SUB2U64(x, y) SUBU64(x, y, 0)
  1265. # define LOWER32(x) (*(int*)(&x) & 0x00000000ffffffff)
  1266. # define HIGHER32(x) (*(int*)(&x)>>32)
  1267. #else /*** LP64 ***/
  1268. # define ADD2U64(x, y) ((x).low+=(y), (x).high += ((x).low < (y)), (x))
  1269. # define SUB2U64(x, y) ( (x).high -= ((x).low < (y)),(x).low-=(y), (x))
  1270. # define LOWER32(x) (IEL_GETDW0(IEL64(x)))
  1271. # define HIGHER32(x) (IEL_GETDW1(IEL64(x)))
  1272. #endif /*** LP64 ***/
  1273. #endif /*** IEL_INT64 ***/
  1274. #ifndef LP64
  1275. /* In order to decrease the macro expansion space */
  1276. #ifdef IEL_USE_FUNCTIONS
  1277. #ifdef __cplusplus
  1278. extern "C" {
  1279. #endif
  1280. int IEL_au(void *x, void *y, int sx, int sy);
  1281. int IEL_c0(void *x, int sx);
  1282. int IEL_c1(void *x, int sx);
  1283. int IEL_c2(void *x, int sx);
  1284. int IEL_c3(void *x, int sx);
  1285. IEL_Err IEL_as(void *x, void *y, int sx, int sy);
  1286. #ifdef __cplusplus
  1287. }
  1288. #endif
  1289. #undef IEL_ASSIGNU
  1290. #undef IEL_ASSIGNS
  1291. #undef IEL_C0
  1292. #undef IEL_C1
  1293. #undef IEL_C2
  1294. #undef IEL_C3
  1295. #define IEL_ASSIGNU(x, y) IEL_au((void *)&(x),(void *)&(y),sizeof(x),sizeof(y))
  1296. #define IEL_ASSIGNS(x, y) IEL_as((void *)&(x),(void *)&(y),sizeof(x),sizeof(y))
  1297. #define IEL_C0(x) IEL_c0((void *)&(x),sizeof(x))
  1298. #define IEL_C1(x) IEL_c1((void *)&(x),sizeof(x))
  1299. #define IEL_C2(x) IEL_c2((void *)&(x),sizeof(x))
  1300. #define IEL_C3(x) IEL_c3((void *)&(x),sizeof(x))
  1301. #endif /* IEL_USE_FUNCTIONS */
  1302. #endif /* LP64 */
  1303. /* Prototypes */
  1304. #ifdef __cplusplus
  1305. extern "C" {
  1306. #endif
  1307. IEL_Err IEL_mul(U128 *xr, U128 *y, U128 *z);
  1308. IEL_Err IEL_rem(U128 *x, U128 *y, U128 *z);
  1309. IEL_Err IEL_div(U128 *x, U128 *y, U128 *z);
  1310. IEL_Err IEL_U128tostr(const U128 *x, char *strptr, int base, const unsigned int length);
  1311. IEL_Err IEL_U64tostr(const U64 *x, char *strptr, int base, const unsigned int length);
  1312. IEL_Err IEL_S128tostr(const S128 *x, char *strptr, int base,const unsigned int length);
  1313. IEL_Err IEL_S64tostr(const S64 *x, char *strptr, int base,const unsigned int length);
  1314. IEL_Err IEL_strtoU128( char *str1, char **endptr, int base, U128 *x);
  1315. IEL_Err IEL_strtoU64(char *str1, char **endptr, int base, U64 *x);
  1316. IEL_Err IEL_strtoS128(char *str1, char **endptr, int base, S128 *x);
  1317. IEL_Err IEL_strtoS64(char *str1, char **endptr, int base, S64 *x);
  1318. #ifdef __cplusplus
  1319. }
  1320. #endif
  1321. /* INT64, inside varibales redefinition */
  1322. #ifdef IEL_INT64
  1323. #undef low
  1324. #define low dw0_64
  1325. #undef high
  1326. #define high dw1_64
  1327. #undef b1st
  1328. #undef b2st
  1329. #undef b3st
  1330. #undef b4st
  1331. #define b1st dw0_128
  1332. #define b2st dw1_128
  1333. #define b3st dw3_128
  1334. #define b4st dw4_128
  1335. #endif
  1336. #endif /**** IEL_H ****/