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.

1113 lines
32 KiB

  1. /******************************
  2. Intel Confidential
  3. ******************************/
  4. #ifndef _EM_HELPER_H
  5. #define _EM_HELPER_H
  6. #include "fepublic.h"
  7. #undef FP_QNAN
  8. #undef FP_SNAN
  9. /***************************************************************************
  10. defines to get rid of ps in the prototypes and the
  11. definitions in EM_helper.c
  12. ***************************************************************************/
  13. #define fp_reg_read_hi(arg1) \
  14. fp82_reg_read_hi(EM_state_type *ps, arg1)
  15. #define fp_reg_read_lo(arg1) \
  16. fp82_reg_read_lo(EM_state_type *ps, arg1)
  17. #define fp_decode_environment(arg1, arg2, arg3) \
  18. fp82_fp_decode_environment(EM_state_type *ps, arg1, arg2, arg3)
  19. #define fp_ieee_rnd_to_int(arg1, arg2) \
  20. fp82_fp_ieee_rnd_to_int(EM_state_type *ps, arg1, arg2)
  21. #define fp_ieee_rnd_to_int_sp(arg1, arg2, arg3) \
  22. fp82_fp_ieee_rnd_to_int_sp(EM_state_type *ps, arg1, arg2, arg3)
  23. #define fp_ieee_round_sp(arg1, arg2, arg3) \
  24. fp82_fp_ieee_round_sp(EM_state_type *ps, arg1, arg2, arg3)
  25. #define fp_ieee_round(arg1,arg2) \
  26. fp82_fp_ieee_round(EM_state_type *ps, arg1, arg2)
  27. #define fp_reg_disabled(arg1, arg2, arg3, arg4) \
  28. fp82_fp_reg_disabled(EM_state_type *ps, arg1, arg2, arg3, arg4)
  29. #define fminmax_exception_fault_check(arg1, arg2, arg3, arg4) \
  30. fp82_fminmax_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4)
  31. #define fpminmax_exception_fault_check(arg1, arg2, arg3, arg4) \
  32. fp82_fpminmax_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4)
  33. #define fcmp_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  34. fp82_fcmp_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  35. #define fpcmp_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  36. fp82_fpcmp_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  37. #define fcvt_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  38. fp82_fcvt_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  39. #define fpcvt_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  40. fp82_fpcvt_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  41. #define fpma_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  42. fp82_fpma_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  43. #define fma_exception_fault_check(arg1, arg2, arg3, arg4, arg5, arg6) \
  44. fp82_fma_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5, arg6)
  45. #define fms_fnma_exception_fault_check(arg1, arg2, arg3, arg4, arg5, arg6) \
  46. fp82_fms_fnma_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5, arg6)
  47. #define fpms_fpnma_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  48. fp82_fpms_fpnma_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  49. #define frcpa_exception_fault_check(arg1, arg2, arg3, arg4) \
  50. fp82_frcpa_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4)
  51. #define fprcpa_exception_fault_check(arg1, arg2, arg3, arg4, arg5) \
  52. fp82_fprcpa_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4, arg5)
  53. #define frsqrta_exception_fault_check(arg1, arg2, arg3) \
  54. fp82_frsqrta_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3)
  55. #define fprsqrta_exception_fault_check(arg1, arg2, arg3, arg4) \
  56. fp82_fprsqrta_exception_fault_check(EM_state_type *ps, arg1, arg2, arg3, arg4)
  57. #define fp_update_fpsr(arg1, arg2) fp82_fp_update_fpsr(EM_state_type *ps, arg1, arg2)
  58. #define fp_update_psr(arg1) fp82_fp_update_psr(EM_state_type *ps, arg1)
  59. /* Function Prototypes for Helper functions */
  60. #define SET_STATUS_FLAG(status_flag) { \
  61. status_flag = 1; \
  62. }
  63. #define CLEAR_STATUS_FLAG(status_flag) { \
  64. status_flag = 0; \
  65. }
  66. // helper functions declarations
  67. EM_uint_t
  68. fp_extract_bits(
  69. EM_uint64_t input_value,
  70. unsigned int hi_bound,
  71. unsigned int lo_bound);
  72. EM_uint64_t
  73. fp_concatenate(EM_uint_t hi_val, EM_uint_t lo_val);
  74. INLINE EM_boolean_t
  75. fp_equal(
  76. EM_fp_reg_type fr1, EM_fp_reg_type fr2);
  77. INLINE EM_boolean_t
  78. fp_less_than(
  79. EM_fp_reg_type fr1,
  80. EM_fp_reg_type fr2);
  81. INLINE EM_boolean_t
  82. fp_lesser_or_equal(
  83. EM_fp_reg_type fr1, EM_fp_reg_type fr2);
  84. INLINE EM_boolean_t
  85. fp_unordered(
  86. EM_fp_reg_type fr1, EM_fp_reg_type fr2);
  87. EM_uint_t
  88. fp82_fp_decode_fault(
  89. EM_tmp_fp_env_type tmp_fp_env);
  90. EM_uint_t
  91. fp82_fp_decode_trap(
  92. EM_tmp_fp_env_type tmp_fp_env);
  93. // MACH
  94. void
  95. fp_decode_environment(
  96. EM_opcode_pc_type pc,
  97. EM_opcode_sf_type sf,
  98. EM_tmp_fp_env_type *tmp_fp_env);
  99. EM_uint_t
  100. fp_reg_disabled(
  101. EM_uint_t f1,
  102. EM_uint_t f2,
  103. EM_uint_t f3,
  104. EM_uint_t f4);
  105. INLINE EM_boolean_t
  106. fp_is_nan_or_inf(
  107. EM_fp_reg_type tmp_res);
  108. INLINE EM_fp_reg_type
  109. fp_dp_to_fr(
  110. EM_fp_dp_type tmp_res);
  111. INLINE EM_fp_dp_type
  112. fp_add(
  113. EM_fp_dp_type fp_dp, EM_fp_reg_type fr2,
  114. EM_tmp_fp_env_type tmp_fp_env);
  115. INLINE void
  116. fcmp_exception_fault_check(
  117. EM_fp_reg_specifier f2,
  118. EM_fp_reg_specifier f3,
  119. EM_opcode_frel_type frel,
  120. EM_opcode_sf_type sf,
  121. EM_tmp_fp_env_type *tmp_fp_env);
  122. INLINE void
  123. fpcmp_exception_fault_check(
  124. EM_fp_reg_specifier f2,
  125. EM_fp_reg_specifier f3,
  126. EM_opcode_frel_type frel,
  127. EM_opcode_sf_type sf,
  128. EM_tmp_fp_env_type *tmp_fp_env);
  129. INLINE EM_fp_reg_type
  130. fcvt_exception_fault_check(
  131. EM_fp_reg_specifier f2,
  132. EM_opcode_sf_type sf,
  133. EM_boolean_t signed_form,
  134. EM_boolean_t trunc_form,
  135. EM_tmp_fp_env_type *tmp_fp_env);
  136. EM_pair_fp_reg_type
  137. fpcvt_exception_fault_check(
  138. EM_fp_reg_specifier f2,
  139. EM_opcode_sf_type sf,
  140. EM_boolean_t signed_form,
  141. EM_boolean_t trunc_form,
  142. EM_tmp_fp_env_type *tmp_fp_env);
  143. EM_fp_reg_type
  144. fma_exception_fault_check(
  145. EM_fp_reg_specifier f2,
  146. EM_fp_reg_specifier f3,
  147. EM_fp_reg_specifier f4,
  148. EM_opcode_pc_type pc,
  149. EM_opcode_sf_type sf,
  150. EM_tmp_fp_env_type *tmp_fp_env);
  151. EM_pair_fp_reg_type
  152. fpma_exception_fault_check(
  153. EM_fp_reg_specifier f2,
  154. EM_fp_reg_specifier f3,
  155. EM_fp_reg_specifier f4,
  156. EM_opcode_sf_type sf,
  157. EM_tmp_fp_env_type *tmp_fp_env);
  158. INLINE void
  159. fminmax_exception_fault_check(
  160. EM_fp_reg_specifier f2,
  161. EM_fp_reg_specifier f3,
  162. EM_opcode_sf_type sf,
  163. EM_tmp_fp_env_type *tmp_fp_env);
  164. INLINE void
  165. fpminmax_exception_fault_check(
  166. EM_uint_t f2,
  167. EM_uint_t f3,
  168. EM_opcode_sf_type sf,
  169. EM_tmp_fp_env_type *tmp_fp_env);
  170. EM_fp_reg_type
  171. fms_fnma_exception_fault_check(
  172. EM_fp_reg_specifier f2,
  173. EM_fp_reg_specifier f3,
  174. EM_fp_reg_specifier f4,
  175. EM_opcode_pc_type pc,
  176. EM_opcode_sf_type sf,
  177. EM_tmp_fp_env_type *tmp_fp_env);
  178. EM_pair_fp_reg_type
  179. fpms_fpnma_exception_fault_check(
  180. EM_fp_reg_specifier f2,
  181. EM_fp_reg_specifier f3,
  182. EM_fp_reg_specifier f4,
  183. EM_opcode_sf_type sf,
  184. EM_tmp_fp_env_type *tmp_fp_env);
  185. INLINE EM_boolean_t
  186. fp_flag_set_is_enabled(
  187. EM_uint_t flags, EM_uint_t traps);
  188. INLINE EM_boolean_t
  189. fp_flag_set_is_clear(
  190. EM_uint_t flags, EM_uint_t traps);
  191. INLINE EM_fp_dp_type
  192. fp_max_or_infinity(
  193. EM_uint_t sign, EM_tmp_fp_env_type *tmp_fp_env,
  194. EM_uint_t e_max, EM_uint128_t max_significand);
  195. INLINE EM_fp_dp_type
  196. fp_mul(
  197. EM_fp_reg_type fr3, EM_fp_reg_type fr4);
  198. INLINE EM_fp_reg_type
  199. fp_normalize(EM_fp_reg_type freg);
  200. INLINE EM_fp_dp_type
  201. fp_normalize_dp(EM_fp_dp_type fp_dp);
  202. EM_fp_dp_type
  203. fp82_fp_fr_to_dp(EM_fp_reg_type fr1);
  204. INLINE EM_memory_type
  205. fr_to_mem4_bias_adjust(EM_fp_reg_type freg);
  206. EM_fp_reg_type
  207. frcpa_exception_fault_check(
  208. EM_fp_reg_specifier f2,
  209. EM_fp_reg_specifier f3,
  210. EM_opcode_sf_type sf,
  211. EM_tmp_fp_env_type *tmp_fp_env);
  212. EM_pair_fp_reg_type
  213. fprcpa_exception_fault_check(
  214. EM_fp_reg_specifier f2,
  215. EM_fp_reg_specifier f3,
  216. EM_opcode_sf_type sf,
  217. EM_tmp_fp_env_type *tmp_fp_env,
  218. EM_limits_check_fprcpa *limits_check);
  219. EM_fp_reg_type
  220. frsqrta_exception_fault_check(
  221. EM_fp_reg_specifier f3,
  222. EM_opcode_sf_type sf,
  223. EM_tmp_fp_env_type *tmp_fp_env);
  224. EM_pair_fp_reg_type
  225. fprsqrta_exception_fault_check(
  226. EM_fp_reg_specifier f3,
  227. EM_opcode_sf_type sf,
  228. EM_tmp_fp_env_type *tmp_fp_env,
  229. EM_limits_check_fprsqrta *limits_check);
  230. EM_fp_reg_type
  231. fp_ieee_rnd_to_int(
  232. EM_fp_reg_type fr1,
  233. EM_tmp_fp_env_type *tmp_fp_env);
  234. EM_fp_reg_type
  235. fp_ieee_rnd_to_int_sp(
  236. EM_fp_reg_type fr2,
  237. EM_simd_hilo hilo,
  238. EM_tmp_fp_env_type *tmp_fp_env);
  239. EM_fp_reg_type
  240. fp_ieee_round(
  241. EM_fp_dp_type fp_dp,
  242. EM_tmp_fp_env_type *tmp_fp_env);
  243. INLINE EM_boolean_t
  244. fp_is_finite(EM_fp_reg_type freg);
  245. INLINE EM_boolean_t
  246. fp_is_inf(EM_fp_reg_type freg);
  247. INLINE EM_boolean_t
  248. fp_is_inf_dp(EM_fp_dp_type tmp_res);
  249. INLINE EM_boolean_t
  250. fp_is_nan(EM_fp_reg_type freg);
  251. INLINE EM_boolean_t
  252. fp_is_nan_dp(EM_fp_dp_type tmp_res);
  253. INLINE EM_boolean_t
  254. fp_is_natval(EM_fp_reg_type freg);
  255. INLINE EM_boolean_t
  256. fp_is_neg_dp(EM_fp_dp_type tmp_res);
  257. INLINE EM_boolean_t
  258. fp_is_neg_inf(EM_fp_reg_type freg);
  259. INLINE EM_boolean_t
  260. fp_is_neg_non_zero(EM_fp_reg_type freg);
  261. INLINE EM_boolean_t
  262. fp_is_normal(EM_fp_reg_type freg);
  263. INLINE EM_boolean_t
  264. fp_is_normal_dp(EM_fp_dp_type tmp_res);
  265. INLINE EM_boolean_t
  266. fp_is_pos_dp(EM_fp_dp_type tmp_res);
  267. INLINE EM_boolean_t
  268. fp_is_pos_inf(EM_fp_reg_type freg);
  269. INLINE EM_boolean_t
  270. fp_is_pos_non_zero(EM_fp_reg_type freg);
  271. INLINE EM_boolean_t
  272. fp_is_pseudo_zero(EM_fp_reg_type freg);
  273. INLINE EM_boolean_t
  274. fp_is_qnan(EM_fp_reg_type freg);
  275. INLINE EM_boolean_t
  276. fp_is_snan(EM_fp_reg_type freg);
  277. INLINE EM_boolean_t
  278. fp_is_unorm(EM_fp_reg_type freg);
  279. INLINE EM_boolean_t
  280. fp_is_unsupported(EM_fp_reg_type freg);
  281. INLINE EM_boolean_t
  282. fp_is_unsupported_dp(EM_fp_dp_type tmp_res);
  283. INLINE EM_boolean_t
  284. fp_is_zero(EM_fp_reg_type freg);
  285. INLINE EM_boolean_t
  286. fp_is_zero_dp(EM_fp_dp_type tmp_res);
  287. EM_int_t
  288. fp82_fp_U64_lead0(EM_uint64_t value);
  289. INLINE EM_int_t
  290. fp_U128_lead0(EM_uint128_t value);
  291. EM_int_t
  292. fp82_fp_U256_lead0(EM_uint256_t value);
  293. EM_fp_reg_type
  294. fp_mem_to_fr_format(
  295. EM_memory_type mem,
  296. EM_uint_t size,
  297. EM_uint_t integer_form);
  298. EM_memory_type
  299. fp_fr_to_mem_format(
  300. EM_fp_reg_type freg,
  301. EM_uint_t size,
  302. EM_uint_t integer_form);
  303. INLINE EM_fp_reg_type
  304. fp_make_quiet_nan(EM_fp_reg_type freg);
  305. EM_boolean_t
  306. fp82_fp_raise_fault(EM_tmp_fp_env_type tmp_fp_env);
  307. EM_boolean_t
  308. fp82_fp_raise_traps(EM_tmp_fp_env_type tmp_fp_env);
  309. INLINE EM_fp_reg_type
  310. fp_reg_read(EM_fp_reg_type freg);
  311. INLINE EM_fp_reg_type
  312. fp_reg_read_hi(EM_uint_t freg);
  313. INLINE EM_fp_reg_type
  314. fp_reg_read_lo(EM_uint_t freg);
  315. INLINE EM_uint_t
  316. fp_single(EM_fp_reg_type freg);
  317. EM_uint_t
  318. fp_ieee_round_sp(
  319. EM_fp_dp_type fp_dp,
  320. EM_simd_hilo hilo,
  321. EM_tmp_fp_env_type *tmp_fp_env);
  322. INLINE void
  323. fp_ieee_to_hilo(
  324. EM_simd_hilo hilo,
  325. EM_tmp_fp_env_type *tmp_fp_env);
  326. EM_uint_t fp82_no_bytes(char *str);
  327. EM_uint_t fp82_not_int(char *str);
  328. INLINE void
  329. fp_update_fpsr(
  330. EM_opcode_sf_type sf,
  331. EM_tmp_fp_env_type tmp_fp_env);
  332. INLINE void
  333. fp_update_psr(
  334. EM_uint_t dest_freg);
  335. /* Basic Types Support Functions */
  336. /* 128-bit unsigned int support routines */
  337. EM_boolean_t
  338. fp82_fp_U128_eq(EM_uint128_t value1, EM_uint128_t value2);
  339. static INLINE EM_boolean_t
  340. fp_U128_ge(EM_uint128_t value1, EM_uint128_t value2);
  341. static INLINE EM_boolean_t
  342. fp_U128_gt(EM_uint128_t value1, EM_uint128_t value2);
  343. static INLINE EM_boolean_t
  344. fp_U128_le(EM_uint128_t value1, EM_uint128_t value2);
  345. EM_boolean_t
  346. fp82_fp_U128_lt(EM_uint128_t value1, EM_uint128_t value2);
  347. EM_boolean_t
  348. fp82_ne_U128(EM_uint128_t value1, EM_uint128_t value2);
  349. static INLINE EM_uint128_t
  350. bld_U128(EM_uint64_t hi, EM_uint64_t lo);
  351. EM_uint128_t
  352. fp82_fp_U128_lsh(EM_uint128_t value, EM_uint_t count);
  353. EM_uint128_t
  354. fp82_fp_U128_rsh(EM_uint128_t value, EM_uint_t count);
  355. EM_uint128_t
  356. fp82_fp_U64_x_U64_to_U128(EM_uint64_t value1, EM_uint64_t value2);
  357. INLINE EM_uint128_t
  358. fp_I64_x_I64_to_I128(EM_uint64_t value1, EM_uint64_t value2);
  359. EM_uint128_t
  360. fp82_fp_U128_inc(EM_uint128_t value1);
  361. static INLINE EM_uint128_t
  362. fp_U128_neg(EM_uint128_t value);
  363. EM_uint128_t
  364. fp82_fp_U128_add(EM_uint128_t value1, EM_uint128_t value2);
  365. EM_uint128_t
  366. fp82_fp_U128_bor(EM_uint128_t value1, EM_uint128_t value2);
  367. EM_uint128_t
  368. fp82_fp_U128_band(EM_uint128_t value1, EM_uint128_t value2);
  369. /* 256-bit unsigned int support routines */
  370. EM_boolean_t
  371. fp82_fp_U256_eq(EM_uint256_t value1, EM_uint256_t value2);
  372. EM_boolean_t
  373. fp82_ne_U256(EM_uint256_t value1, EM_uint256_t value2);
  374. static INLINE EM_uint256_t
  375. bld_U256(
  376. EM_uint64_t hh, EM_uint64_t hl,
  377. EM_uint64_t lh, EM_uint64_t ll);
  378. EM_uint256_t
  379. fp82_fp_U256_lsh(EM_uint256_t value, EM_uint_t count);
  380. EM_uint256_t
  381. fp82_fp_U256_rsh(EM_uint256_t value, EM_uint_t count);
  382. EM_uint256_t
  383. fp82_fp_U256_inc(EM_uint256_t value1);
  384. static INLINE EM_uint256_t
  385. fp_U256_neg(EM_uint256_t value);
  386. static INLINE EM_uint256_t
  387. fp_U256_add(EM_uint256_t value1,
  388. EM_uint256_t value2);
  389. /* Basic Conversion Routines */
  390. INLINE EM_uint128_t
  391. fp_U64_to_U128(EM_uint64_t value);
  392. INLINE EM_uint64_t
  393. fp_U128_to_U64(EM_uint128_t value);
  394. static INLINE EM_uint256_t
  395. fp_U64_to_U256(EM_uint64_t value);
  396. static INLINE EM_uint64_t
  397. fp_U256_to_U64(EM_uint256_t value);
  398. EM_uint256_t
  399. fp82_fp_U128_to_U256(EM_uint128_t value);
  400. static INLINE EM_uint128_t
  401. fp_U256_to_U128(EM_uint256_t value);
  402. EM_boolean_t
  403. is_reserved_field(
  404. EM_opcode_type calling_instruction,
  405. EM_opcode_sf_type sf,
  406. EM_uint_t val) ;
  407. /* Basic Constants */
  408. static const EM_uint64_t U64_0 = CONST_FORMAT( 0x0000000000000000 );
  409. static const EM_uint64_t U64_1 = CONST_FORMAT( 0x0000000000000001 );
  410. static const EM_uint64_t U64_0x0000000080000000 = CONST_FORMAT( 0x0000000080000000 );
  411. static const EM_uint64_t U64_0x2000000000000000 = CONST_FORMAT( 0x2000000000000000 );
  412. static const EM_uint64_t U64_0x4000000000000000 = CONST_FORMAT( 0x4000000000000000 );
  413. static const EM_uint64_t U64_0x8000000000000000 = CONST_FORMAT( 0x8000000000000000 );
  414. static const EM_uint64_t U64_0xC000000000000000 = CONST_FORMAT( 0xC000000000000000 );
  415. static const EM_uint64_t U64_0x3FFFFFFFFFFFFFFF = CONST_FORMAT( 0x3FFFFFFFFFFFFFFF );
  416. static const EM_uint64_t U64_0x7FFFFFFFFFFFFFFF = CONST_FORMAT( 0x7FFFFFFFFFFFFFFF );
  417. static const EM_uint64_t U64_0xFFFFFF0000000000 = CONST_FORMAT( 0xFFFFFF0000000000 );
  418. static const EM_uint64_t U64_0xFFFFFFFFFFFFF800 = CONST_FORMAT( 0xFFFFFFFFFFFFF800 );
  419. static const EM_uint64_t U64_0xFFFFFFFFFFFFFFFF = CONST_FORMAT( 0xFFFFFFFFFFFFFFFF );
  420. static const EM_uint64_t U64_0xFFFFFFFF00000000 = CONST_FORMAT( 0xFFFFFFFF00000000 );
  421. static const EM_uint64_t U64_0xFFFF000000000000 = CONST_FORMAT( 0xFFFF000000000000 );
  422. static const EM_uint64_t U64_0xFF00000000000000 = CONST_FORMAT( 0xFF00000000000000 );
  423. static const EM_uint128_t U128_0
  424. = {
  425. #ifdef BIG_ENDIAN
  426. CONST_FORMAT( 0x0000000000000000 ),
  427. CONST_FORMAT( 0x0000000000000000 ),
  428. #endif
  429. #ifdef LITTLE_ENDIAN
  430. CONST_FORMAT( 0x0000000000000000 ),
  431. CONST_FORMAT( 0x0000000000000000 ),
  432. #endif
  433. };
  434. static const EM_uint128_t U128_0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  435. = {
  436. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  437. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF )
  438. };
  439. static const EM_uint128_t U128_0x00000000000000000000000000003FFF
  440. = {
  441. #ifdef BIG_ENDIAN
  442. CONST_FORMAT( 0x0000000000000000 ),
  443. CONST_FORMAT( 0x0000000000003FFF ),
  444. #endif
  445. #ifdef LITTLE_ENDIAN
  446. CONST_FORMAT( 0x0000000000003FFF ),
  447. CONST_FORMAT( 0x0000000000000000 ),
  448. #endif
  449. };
  450. static const EM_uint128_t U128_0x00000000000000000000000000007FFF
  451. = {
  452. #ifdef BIG_ENDIAN
  453. CONST_FORMAT( 0x0000000000000000 ),
  454. CONST_FORMAT( 0x0000000000007FFF ),
  455. #endif
  456. #ifdef LITTLE_ENDIAN
  457. CONST_FORMAT( 0x0000000000007FFF ),
  458. CONST_FORMAT( 0x0000000000000000 ),
  459. #endif
  460. };
  461. static const EM_uint128_t U128_0x00000000000000000000000000004000
  462. = {
  463. #ifdef BIG_ENDIAN
  464. CONST_FORMAT( 0x0000000000000000 ),
  465. CONST_FORMAT( 0x0000000000004000 ),
  466. #endif
  467. #ifdef LITTLE_ENDIAN
  468. CONST_FORMAT( 0x0000000000004000 ),
  469. CONST_FORMAT( 0x0000000000000000 ),
  470. #endif
  471. };
  472. static const EM_uint128_t U128_0x00000000000000000000000000008000
  473. = {
  474. #ifdef BIG_ENDIAN
  475. CONST_FORMAT( 0x0000000000000000 ),
  476. CONST_FORMAT( 0x0000000000008000 ),
  477. #endif
  478. #ifdef LITTLE_ENDIAN
  479. CONST_FORMAT( 0x0000000000008000 ),
  480. CONST_FORMAT( 0x0000000000000000 ),
  481. #endif
  482. };
  483. static const EM_uint128_t U128_0xFFFFFFFFFFFFFFFFFFFFFFFFFFFF8000
  484. = {
  485. #ifdef BIG_ENDIAN
  486. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  487. CONST_FORMAT( 0x0000000000008000 ),
  488. #endif
  489. #ifdef LITTLE_ENDIAN
  490. CONST_FORMAT( 0x0000000000008000 ),
  491. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  492. #endif
  493. };
  494. static const EM_uint128_t U128_0x40000000000000000000000000000000
  495. = {
  496. #ifdef BIG_ENDIAN
  497. CONST_FORMAT( 0x4000000000000000 ),
  498. CONST_FORMAT( 0x0000000000000000 ),
  499. #endif
  500. #ifdef LITTLE_ENDIAN
  501. CONST_FORMAT( 0x0000000000000000 ),
  502. CONST_FORMAT( 0x4000000000000000 ),
  503. #endif
  504. };
  505. static const EM_uint128_t U128_0x00000100000000000000000000000000
  506. = {
  507. #ifdef BIG_ENDIAN
  508. CONST_FORMAT( 0x0000010000000000 ),
  509. CONST_FORMAT( 0x0000000000000000 ),
  510. #endif
  511. #ifdef LITTLE_ENDIAN
  512. CONST_FORMAT( 0x0000000000000000 ),
  513. CONST_FORMAT( 0x0000010000000000 ),
  514. #endif
  515. };
  516. static const EM_uint128_t U128_0x00000080000000000000000000000000
  517. = {
  518. #ifdef BIG_ENDIAN
  519. CONST_FORMAT( 0x0000008000000000 ),
  520. CONST_FORMAT( 0x0000000000000000 ),
  521. #endif
  522. #ifdef LITTLE_ENDIAN
  523. CONST_FORMAT( 0x0000000000000000 ),
  524. CONST_FORMAT( 0x0000008000000000 ),
  525. #endif
  526. };
  527. static const EM_uint128_t U128_0x00000000000008000000000000000000
  528. = {
  529. #ifdef BIG_ENDIAN
  530. CONST_FORMAT( 0x0000000000000800 ),
  531. CONST_FORMAT( 0x0000000000000000 ),
  532. #endif
  533. #ifdef LITTLE_ENDIAN
  534. CONST_FORMAT( 0x0000000000000000 ),
  535. CONST_FORMAT( 0x0000000000000800 ),
  536. #endif
  537. };
  538. static const EM_uint128_t U128_0x00000000000004000000000000000000
  539. = {
  540. #ifdef BIG_ENDIAN
  541. CONST_FORMAT( 0x0000000000000400 ),
  542. CONST_FORMAT( 0x0000000000000000 ),
  543. #endif
  544. #ifdef LITTLE_ENDIAN
  545. CONST_FORMAT( 0x0000000000000000 ),
  546. CONST_FORMAT( 0x0000000000000400 ),
  547. #endif
  548. };
  549. static const EM_uint128_t U128_0x00000000000000010000000000000000
  550. = {
  551. #ifdef BIG_ENDIAN
  552. CONST_FORMAT( 0x0000000000000001 ),
  553. CONST_FORMAT( 0x0000000000000000 ),
  554. #endif
  555. #ifdef LITTLE_ENDIAN
  556. CONST_FORMAT( 0x0000000000000000 ),
  557. CONST_FORMAT( 0x0000000000000001 ),
  558. #endif
  559. };
  560. static const EM_uint128_t U128_0x00000000000000008000000000000000
  561. = {
  562. #ifdef BIG_ENDIAN
  563. CONST_FORMAT( 0x0000000000000000 ),
  564. CONST_FORMAT( 0x8000000000000000 ),
  565. #endif
  566. #ifdef LITTLE_ENDIAN
  567. CONST_FORMAT( 0x8000000000000000 ),
  568. CONST_FORMAT( 0x0000000000000000 ),
  569. #endif
  570. };
  571. static const EM_uint128_t U128_0x00000000000000007FFFFFFFFFFFFFFF
  572. = {
  573. #ifdef BIG_ENDIAN
  574. CONST_FORMAT( 0x0000000000000000 ),
  575. CONST_FORMAT( 0x7FFFFFFFFFFFFFFF ),
  576. #endif
  577. #ifdef LITTLE_ENDIAN
  578. CONST_FORMAT( 0x7FFFFFFFFFFFFFFF ),
  579. CONST_FORMAT( 0x0000000000000000 ),
  580. #endif
  581. };
  582. static const EM_uint128_t U128_0x0000000000000000FFFFFFFFFFFFFFFF
  583. = {
  584. #ifdef BIG_ENDIAN
  585. CONST_FORMAT( 0x0000000000000000 ),
  586. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  587. #endif
  588. #ifdef LITTLE_ENDIAN
  589. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  590. CONST_FORMAT( 0x0000000000000000 ),
  591. #endif
  592. };
  593. static const EM_uint128_t U128_0xFFFFFFFFFFFFFFFF0000000000000000
  594. = {
  595. #ifdef BIG_ENDIAN
  596. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  597. CONST_FORMAT( 0x0000000000000000 ),
  598. #endif
  599. #ifdef LITTLE_ENDIAN
  600. CONST_FORMAT( 0x0000000000000000 ),
  601. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  602. #endif
  603. };
  604. static const EM_uint128_t U128_0xFFFFFFFFFFFFFFFF8000000000000000
  605. = {
  606. #ifdef BIG_ENDIAN
  607. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  608. CONST_FORMAT( 0x8000000000000000 ),
  609. #endif
  610. #ifdef LITTLE_ENDIAN
  611. CONST_FORMAT( 0x8000000000000000 ),
  612. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  613. #endif
  614. };
  615. static const EM_uint128_t U128_0x00000000000003FFFFFFFFFFFFFFFFFF
  616. = {
  617. #ifdef BIG_ENDIAN
  618. CONST_FORMAT( 0x00000000000003FF ),
  619. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  620. #endif
  621. #ifdef LITTLE_ENDIAN
  622. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  623. CONST_FORMAT( 0x00000000000003FF ),
  624. #endif
  625. };
  626. static const EM_uint128_t U128_0x00000000000007FFFFFFFFFFFFFFFFFF
  627. = {
  628. #ifdef BIG_ENDIAN
  629. CONST_FORMAT( 0x00000000000007FF ),
  630. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  631. #endif
  632. #ifdef LITTLE_ENDIAN
  633. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  634. CONST_FORMAT( 0x00000000000007FF ),
  635. #endif
  636. };
  637. static const EM_uint128_t U128_0xFFFFFFFFFFFFF8000000000000000000
  638. = {
  639. #ifdef BIG_ENDIAN
  640. CONST_FORMAT( 0xFFFFFFFFFFFFF800 ),
  641. CONST_FORMAT( 0x0000000000000000 ),
  642. #endif
  643. #ifdef LITTLE_ENDIAN
  644. CONST_FORMAT( 0x0000000000000000 ),
  645. CONST_FORMAT( 0xFFFFFFFFFFFFF800 ),
  646. #endif
  647. };
  648. static const EM_uint128_t U128_0xFFFFFFFFFFFFFC000000000000000000
  649. = {
  650. #ifdef BIG_ENDIAN
  651. CONST_FORMAT( 0xFFFFFFFFFFFFFC00 ),
  652. CONST_FORMAT( 0x0000000000000000 ),
  653. #endif
  654. #ifdef LITTLE_ENDIAN
  655. CONST_FORMAT( 0x0000000000000000 ),
  656. CONST_FORMAT( 0xFFFFFFFFFFFFFC00 ),
  657. #endif
  658. };
  659. static const EM_uint128_t U128_0x0000007FFFFFFFFFFFFFFFFFFFFFFFFF
  660. = {
  661. #ifdef BIG_ENDIAN
  662. CONST_FORMAT( 0x0000007FFFFFFFFF ),
  663. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  664. #endif
  665. #ifdef LITTLE_ENDIAN
  666. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  667. CONST_FORMAT( 0x0000007FFFFFFFFF ),
  668. #endif
  669. };
  670. static const EM_uint128_t U128_0x000000FFFFFFFFFFFFFFFFFFFFFFFFFF
  671. = {
  672. #ifdef BIG_ENDIAN
  673. CONST_FORMAT( 0x000000FFFFFFFFFF ),
  674. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  675. #endif
  676. #ifdef LITTLE_ENDIAN
  677. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  678. CONST_FORMAT( 0x000000FFFFFFFFFF ),
  679. #endif
  680. };
  681. static const EM_uint128_t U128_0xFFFFFF00000000000000000000000000
  682. = {
  683. #ifdef BIG_ENDIAN
  684. CONST_FORMAT( 0xFFFFFF0000000000 ),
  685. CONST_FORMAT( 0x0000000000000000 ),
  686. #endif
  687. #ifdef LITTLE_ENDIAN
  688. CONST_FORMAT( 0x0000000000000000 ),
  689. CONST_FORMAT( 0xFFFFFF0000000000 ),
  690. #endif
  691. };
  692. static const EM_uint128_t U128_0xFFFFFF80000000000000000000000000
  693. = {
  694. #ifdef BIG_ENDIAN
  695. CONST_FORMAT( 0xFFFFFF8000000000 ),
  696. CONST_FORMAT( 0x0000000000000000 ),
  697. #endif
  698. #ifdef LITTLE_ENDIAN
  699. CONST_FORMAT( 0x0000000000000000 ),
  700. CONST_FORMAT( 0xFFFFFF8000000000 ),
  701. #endif
  702. };
  703. static const EM_uint128_t U128_0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  704. = {
  705. #ifdef BIG_ENDIAN
  706. CONST_FORMAT( 0x7FFFFFFFFFFFFFFF ),
  707. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  708. #endif
  709. #ifdef LITTLE_ENDIAN
  710. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  711. CONST_FORMAT( 0x7FFFFFFFFFFFFFFF ),
  712. #endif
  713. };
  714. static const EM_uint128_t U128_0xC0000000000000000000000000000000
  715. = {
  716. #ifdef BIG_ENDIAN
  717. CONST_FORMAT( 0xC000000000000000 ),
  718. CONST_FORMAT( 0x0000000000000000 ),
  719. #endif
  720. #ifdef LITTLE_ENDIAN
  721. CONST_FORMAT( 0x0000000000000000 ),
  722. CONST_FORMAT( 0xC000000000000000 ),
  723. #endif
  724. };
  725. static const EM_uint128_t U128_0x3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  726. = {
  727. #ifdef BIG_ENDIAN
  728. CONST_FORMAT( 0x3FFFFFFFFFFFFFFF ),
  729. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  730. #endif
  731. #ifdef LITTLE_ENDIAN
  732. CONST_FORMAT( 0xFFFFFFFFFFFFFFFF ),
  733. CONST_FORMAT( 0x3FFFFFFFFFFFFFFF ),
  734. #endif
  735. };
  736. static const EM_uint128_t U128_0x80000000000000000000000000000000
  737. = {
  738. #ifdef BIG_ENDIAN
  739. CONST_FORMAT( 0x8000000000000000 ),
  740. CONST_FORMAT( 0x0000000000000000 ),
  741. #endif
  742. #ifdef LITTLE_ENDIAN
  743. CONST_FORMAT( 0x0000000000000000 ),
  744. CONST_FORMAT( 0x8000000000000000 ),
  745. #endif
  746. };
  747. static const EM_uint256_t U256_0
  748. = {
  749. #ifdef BIG_ENDIAN
  750. CONST_FORMAT( 0x0000000000000000 ),
  751. CONST_FORMAT( 0x0000000000000000 ),
  752. CONST_FORMAT( 0x0000000000000000 ),
  753. CONST_FORMAT( 0x0000000000000000 ),
  754. #endif
  755. #ifdef LITTLE_ENDIAN
  756. CONST_FORMAT( 0x0000000000000000 ),
  757. CONST_FORMAT( 0x0000000000000000 ),
  758. CONST_FORMAT( 0x0000000000000000 ),
  759. CONST_FORMAT( 0x0000000000000000 ),
  760. #endif
  761. };
  762. /* Floating Sign Constants */
  763. static const EM_uint_t FP_SIGN_POSITIVE = 0;
  764. static const EM_uint_t FP_SIGN_NEGATIVE = 1;
  765. /* Floating Exponent Constants */
  766. static const EM_uint_t FP_SGL_BIAS = 0x0007F;
  767. static const EM_uint_t FP_DBL_BIAS = 0x003FF;
  768. static const EM_uint_t FP_EXT_BIAS = 0x03FFF;
  769. static const EM_uint_t FP_REG_BIAS = 0x0FFFF;
  770. static const EM_uint_t FP_DP_BIAS = 0x3FFFF;
  771. static const EM_uint_t FP_SGL_EXP_ONES = 0x000FF;
  772. static const EM_uint_t FP_DBL_EXP_ONES = 0x007FF;
  773. static const EM_uint_t FP_EXT_EXP_ONES = 0x07FFF;
  774. static const EM_uint_t FP_REG_EXP_ONES = 0x1FFFF;
  775. static const EM_uint_t FP_DP_EXP_ONES = 0x7FFFF;
  776. static const EM_uint_t FP_SGL_EXP_WIDTH = 8;
  777. static const EM_uint_t FP_DBL_EXP_WIDTH = 11;
  778. static const EM_uint_t FP_EXT_EXP_WIDTH = 15;
  779. static const EM_uint_t FP_REG_EXP_WIDTH = 17;
  780. static const EM_uint_t FP_SGL_SIGNIFICAND_WIDTH = 23;
  781. static const EM_uint_t FP_DBL_SIGNIFICAND_WIDTH = 52;
  782. static const EM_uint_t FP_EXT_SIGNIFICAND_WIDTH = 64;
  783. static const EM_uint_t FP_REG_SIGNIFICAND_WIDTH = 64;
  784. static const EM_uint_t FP_REG_EXP_HALF = 0x0FFFE;
  785. static const EM_uint_t FP_INTEGER_EXP = 0x1003E;
  786. static const EM_uint_t FP_DP_INTEGER_EXP = 0x4003E;
  787. /* Floating Constants */
  788. static const EM_fp_reg_type
  789. FP_ZERO = {CONST_FORMAT( 0x0000000000000000 ), 0x00000, 0x0 }; /* 0.0 */
  790. static const EM_fp_reg_type
  791. FP_NEG_ZERO = {CONST_FORMAT( 0x0000000000000000 ), 0x00000, 0x1 }; /* -0.0 */
  792. static const EM_fp_reg_type
  793. FP_HALF = {CONST_FORMAT( 0x8000000000000000 ), 0x0FFFE, 0x0 }; /* 0.5 */
  794. static const EM_fp_reg_type
  795. FP_ONE = {CONST_FORMAT( 0x8000000000000000 ), 0x0FFFF, 0x0 }; /* 1.0 */
  796. static const EM_fp_reg_type
  797. FP_ONE_PAIR = {CONST_FORMAT( 0x3F8000003F800000 ), 0x1003E, 0x0 };
  798. /* Pair of ones for SIMD non-memory ops */
  799. static const EM_fp_reg_type
  800. FP_INFINITY = {CONST_FORMAT( 0x8000000000000000 ), 0x1FFFF, 0x0 }; /* Inf */
  801. static const EM_fp_reg_type
  802. FP_QNAN = {CONST_FORMAT( 0xC000000000000000 ), 0x1FFFF, 0x1 }; /* QNaN Indefinite */
  803. static const EM_fp_reg_type
  804. FP_SNAN = {CONST_FORMAT( 0x8000000000000000 ), 0x1FFFF, 0x0 }; /* SNaN*/
  805. static const EM_fp_reg_type
  806. FP_POS_2_TO_63 = {CONST_FORMAT( 0x8000000000000000 ), 0x1003E, 0x0 }; /* 2.0**63 */
  807. static const EM_fp_reg_type
  808. FP_NEG_2_TO_63 = {CONST_FORMAT( 0x8000000000000000 ), 0x1003E, 0x1 }; /* -2.0**63 */
  809. static const EM_fp_reg_type
  810. FP_POS_2_TO_64 = {CONST_FORMAT( 0x8000000000000000 ), 0x1003F, 0x0 }; /* 2.0**64 */
  811. static const EM_fp_reg_type
  812. FP_NEG_2_TO_64 = {CONST_FORMAT( 0x8000000000000000 ), 0x1003F, 0x1 }; /* -2.0**64 */
  813. static const EM_fp_reg_type
  814. FP_POS_2_TO_31 = {CONST_FORMAT( 0x0000000080000000 ), 0x1003E, 0x0 }; /* 2.0**31 */
  815. static const EM_fp_reg_type
  816. FP_NEG_2_TO_31 = {CONST_FORMAT( 0x0000000080000000 ), 0x1003E, 0x1 }; /* -2.0**31 */
  817. static const EM_fp_reg_type
  818. FP_POS_2_TO_32 = {CONST_FORMAT( 0x0000000080000000 ), 0x1003F, 0x0 }; /* 2.0**32 */
  819. static const EM_fp_reg_type
  820. FP_NEQ_2_TO_32 = {CONST_FORMAT( 0x0000000080000000 ), 0x1003F, 0x1 }; /* -2.0**32 */
  821. static const EM_fp_reg_type
  822. NATVAL = {CONST_FORMAT( 0x0000000000000000 ), 0x1FFFE, 0x0 }; /* NaTVal */
  823. static const EM_uint64_t
  824. INTEGER_INDEFINITE = CONST_FORMAT( 0x8000000000000000 ); /* -(2**63) */
  825. static const EM_uint_t
  826. INTEGER_INDEFINITE_32_BIT = 0x80000000; /* */
  827. /******************************************************************************/
  828. /* Define macros to simplify access to the fp82_ functions. This is done so */
  829. /* the namespace doesn't get cluttered, while retaining convenient access. */
  830. /* The FP82_NO_SHORTCUTS macro can be defined to prevent creation of these. */
  831. /******************************************************************************/
  832. #ifndef FP82_NO_SHORTCUTS
  833. #define fp_U64_x_U64_to_U128 fp82_fp_U64_x_U64_to_U128
  834. #define fp_U128_add fp82_fp_U128_add
  835. #define fp_U128_band fp82_fp_U128_band
  836. #define fp_U128_bor fp82_fp_U128_bor
  837. #define fp_U128_eq fp82_fp_U128_eq
  838. #define fp_U256_eq fp82_fp_U256_eq
  839. #define fp_U128_to_U256 fp82_fp_U128_to_U256
  840. #define fp_U128_lt fp82_fp_U128_lt
  841. #define fp_U128_inc fp82_fp_U128_inc
  842. #define fp_U256_inc fp82_fp_U256_inc
  843. #define fp_U128_rsh fp82_fp_U128_rsh
  844. #define fp_U128_lsh fp82_fp_U128_lsh
  845. #define fp_U256_rsh fp82_fp_U256_rsh
  846. #define fp_U256_lsh fp82_fp_U256_lsh
  847. #define fp_U256_rsh fp82_fp_U256_rsh
  848. #define fp_U64_lead0 fp82_fp_U64_lead0
  849. #define fp_U256_lead0 fp82_fp_U256_lead0
  850. #define fp_raise_fault fp82_fp_raise_fault
  851. #define fp_raise_traps fp82_fp_raise_traps
  852. #define fp_decode_fault fp82_fp_decode_fault
  853. #define fp_decode_trap fp82_fp_decode_trap
  854. #define fp_fr_to_dp fp82_fp_fr_to_dp
  855. #endif /* FP82_NO_SHORTCUTS */
  856. #endif /* _EM_HELPER_H */