2007-09-27 H.J. Lu <hongjiu.lu@intel.com>
[official-gcc.git] / libgcc / config / libbid / bid64_compare.c
blobde22d59fd65489ae52cb2e2ad6827008ce16fff1
1 /* Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version.
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
17 executable.)
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301, USA. */
29 #include "bid_internal.h"
31 static const UINT64 mult_factor[16] = {
32 1ull, 10ull, 100ull, 1000ull,
33 10000ull, 100000ull, 1000000ull, 10000000ull,
34 100000000ull, 1000000000ull, 10000000000ull, 100000000000ull,
35 1000000000000ull, 10000000000000ull,
36 100000000000000ull, 1000000000000000ull
39 #if DECIMAL_CALL_BY_REFERENCE
40 void
41 bid64_quiet_equal (int *pres, UINT64 * px,
42 UINT64 *
43 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
44 _EXC_INFO_PARAM) {
45 UINT64 x = *px;
46 UINT64 y = *py;
47 #else
48 int
49 bid64_quiet_equal (UINT64 x,
50 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
51 _EXC_INFO_PARAM) {
52 #endif
53 int res;
54 int exp_x, exp_y, exp_t;
55 UINT64 sig_x, sig_y, sig_t;
56 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y, lcv;
58 // NaN (CASE1)
59 // if either number is NAN, the comparison is unordered,
60 // rather than equal : return 0
61 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
62 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
63 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
65 res = 0;
66 BID_RETURN (res);
68 // SIMPLE (CASE2)
69 // if all the bits are the same, these numbers are equivalent.
70 if (x == y) {
71 res = 1;
72 BID_RETURN (res);
74 // INFINITY (CASE3)
75 if (((x & MASK_INF) == MASK_INF) && ((y & MASK_INF) == MASK_INF)) {
76 res = (((x ^ y) & MASK_SIGN) != MASK_SIGN);
77 BID_RETURN (res);
79 // ONE INFINITY (CASE3')
80 if (((x & MASK_INF) == MASK_INF) || ((y & MASK_INF) == MASK_INF)) {
81 res = 0;
82 BID_RETURN (res);
84 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
85 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
86 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
87 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
88 if (sig_x > 9999999999999999ull) {
89 non_canon_x = 1;
90 } else {
91 non_canon_x = 0;
93 } else {
94 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
95 sig_x = (x & MASK_BINARY_SIG1);
96 non_canon_x = 0;
98 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
99 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
100 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
101 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
102 if (sig_y > 9999999999999999ull) {
103 non_canon_y = 1;
104 } else {
105 non_canon_y = 0;
107 } else {
108 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
109 sig_y = (y & MASK_BINARY_SIG1);
110 non_canon_y = 0;
112 // ZERO (CASE4)
113 // some properties:
114 // (+ZERO==-ZERO) => therefore ignore the sign
115 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
116 // therefore ignore the exponent field
117 // (Any non-canonical # is considered 0)
118 if (non_canon_x || sig_x == 0) {
119 x_is_zero = 1;
121 if (non_canon_y || sig_y == 0) {
122 y_is_zero = 1;
124 if (x_is_zero && y_is_zero) {
125 res = 1;
126 BID_RETURN (res);
127 } else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
128 res = 0;
129 BID_RETURN (res);
131 // OPPOSITE SIGN (CASE5)
132 // now, if the sign bits differ => not equal : return 0
133 if ((x ^ y) & MASK_SIGN) {
134 res = 0;
135 BID_RETURN (res);
137 // REDUNDANT REPRESENTATIONS (CASE6)
138 if (exp_x > exp_y) { // to simplify the loop below,
139 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
140 SWAP (sig_x, sig_y, sig_t); // and the smaller exp in x
142 if (exp_y - exp_x > 15) {
143 res = 0; // difference cannot be greater than 10^15
144 BID_RETURN (res);
146 for (lcv = 0; lcv < (exp_y - exp_x); lcv++) {
147 // recalculate y's significand upwards
148 sig_y = sig_y * 10;
149 if (sig_y > 9999999999999999ull) {
150 res = 0;
151 BID_RETURN (res);
154 res = (sig_y == sig_x);
155 BID_RETURN (res);
158 #if DECIMAL_CALL_BY_REFERENCE
159 void
160 bid64_quiet_greater (int *pres, UINT64 * px,
161 UINT64 *
162 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
163 _EXC_INFO_PARAM) {
164 UINT64 x = *px;
165 UINT64 y = *py;
166 #else
168 bid64_quiet_greater (UINT64 x,
169 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
170 _EXC_INFO_PARAM) {
171 #endif
172 int res;
173 int exp_x, exp_y;
174 UINT64 sig_x, sig_y;
175 UINT128 sig_n_prime;
176 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
178 // NaN (CASE1)
179 // if either number is NAN, the comparison is unordered, rather than equal :
180 // return 0
181 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
182 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
183 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
185 res = 0;
186 BID_RETURN (res);
188 // SIMPLE (CASE2)
189 // if all the bits are the same, these numbers are equal (not Greater).
190 if (x == y) {
191 res = 0;
192 BID_RETURN (res);
194 // INFINITY (CASE3)
195 if ((x & MASK_INF) == MASK_INF) {
196 // if x is neg infinity, there is no way it is greater than y, return 0
197 if (((x & MASK_SIGN) == MASK_SIGN)) {
198 res = 0;
199 BID_RETURN (res);
200 } else {
201 // x is pos infinity, it is greater, unless y is positive
202 // infinity => return y!=pos_infinity
203 res = (((y & MASK_INF) != MASK_INF)
204 || ((y & MASK_SIGN) == MASK_SIGN));
205 BID_RETURN (res);
207 } else if ((y & MASK_INF) == MASK_INF) {
208 // x is finite, so if y is positive infinity, then x is less, return 0
209 // if y is negative infinity, then x is greater, return 1
210 res = ((y & MASK_SIGN) == MASK_SIGN);
211 BID_RETURN (res);
213 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
214 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
215 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
216 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
217 if (sig_x > 9999999999999999ull) {
218 non_canon_x = 1;
219 } else {
220 non_canon_x = 0;
222 } else {
223 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
224 sig_x = (x & MASK_BINARY_SIG1);
225 non_canon_x = 0;
227 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
228 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
229 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
230 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
231 if (sig_y > 9999999999999999ull) {
232 non_canon_y = 1;
233 } else {
234 non_canon_y = 0;
236 } else {
237 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
238 sig_y = (y & MASK_BINARY_SIG1);
239 non_canon_y = 0;
241 // ZERO (CASE4)
242 // some properties:
243 //(+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
244 //(ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore ignore the
245 // exponent field
246 // (Any non-canonical # is considered 0)
247 if (non_canon_x || sig_x == 0) {
248 x_is_zero = 1;
250 if (non_canon_y || sig_y == 0) {
251 y_is_zero = 1;
253 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
254 if (x_is_zero && y_is_zero) {
255 res = 0;
256 BID_RETURN (res);
257 } else if (x_is_zero) {
258 // is x is zero, it is greater if Y is negative
259 res = ((y & MASK_SIGN) == MASK_SIGN);
260 BID_RETURN (res);
261 } else if (y_is_zero) {
262 // is y is zero, X is greater if it is positive
263 res = ((x & MASK_SIGN) != MASK_SIGN);
264 BID_RETURN (res);
266 // OPPOSITE SIGN (CASE5)
267 // now, if the sign bits differ, x is greater if y is negative
268 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
269 res = ((y & MASK_SIGN) == MASK_SIGN);
270 BID_RETURN (res);
272 // REDUNDANT REPRESENTATIONS (CASE6)
273 // if both components are either bigger or smaller,
274 // it is clear what needs to be done
275 if (sig_x > sig_y && exp_x > exp_y) {
276 res = ((x & MASK_SIGN) != MASK_SIGN);
277 BID_RETURN (res);
279 if (sig_x < sig_y && exp_x < exp_y) {
280 res = ((x & MASK_SIGN) == MASK_SIGN);
281 BID_RETURN (res);
283 // if exp_x is 15 greater than exp_y, no need for compensation
284 if (exp_x - exp_y > 15) { // difference cannot be greater than 10^15
285 if (x & MASK_SIGN) // if both are negative
286 res = 0;
287 else // if both are positive
288 res = 1;
289 BID_RETURN (res);
291 // if exp_x is 15 less than exp_y, no need for compensation
292 if (exp_y - exp_x > 15) {
293 if (x & MASK_SIGN) // if both are negative
294 res = 1;
295 else // if both are positive
296 res = 0;
297 BID_RETURN (res);
299 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
300 if (exp_x > exp_y) { // to simplify the loop below,
301 // otherwise adjust the x significand upwards
302 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
303 mult_factor[exp_x - exp_y]);
304 // if postitive, return whichever significand is larger (converse if neg.)
305 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
306 res = 0;
307 BID_RETURN (res);
309 res = (((sig_n_prime.w[1] > 0)
310 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
311 MASK_SIGN));
312 BID_RETURN (res);
314 // adjust the y significand upwards
315 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
316 mult_factor[exp_y - exp_x]);
317 // if postitive, return whichever significand is larger
318 // (converse if negative)
319 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
320 res = 0;
321 BID_RETURN (res);
323 res = (((sig_n_prime.w[1] == 0)
324 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
325 MASK_SIGN));
326 BID_RETURN (res);
329 #if DECIMAL_CALL_BY_REFERENCE
330 void
331 bid64_quiet_greater_equal (int *pres, UINT64 * px,
332 UINT64 *
333 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
334 _EXC_INFO_PARAM) {
335 UINT64 x = *px;
336 UINT64 y = *py;
337 #else
339 bid64_quiet_greater_equal (UINT64 x,
340 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
341 _EXC_INFO_PARAM) {
342 #endif
343 int res;
344 int exp_x, exp_y;
345 UINT64 sig_x, sig_y;
346 UINT128 sig_n_prime;
347 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
349 // NaN (CASE1)
350 // if either number is NAN, the comparison is unordered : return 1
351 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
352 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
353 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
355 res = 0;
356 BID_RETURN (res);
358 // SIMPLE (CASE2)
359 // if all the bits are the same, these numbers are equal.
360 if (x == y) {
361 res = 1;
362 BID_RETURN (res);
364 // INFINITY (CASE3)
365 if ((x & MASK_INF) == MASK_INF) {
366 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
367 if ((x & MASK_SIGN) == MASK_SIGN) {
368 // x is -inf, so it is less than y unless y is -inf
369 res = (((y & MASK_INF) == MASK_INF)
370 && (y & MASK_SIGN) == MASK_SIGN);
371 BID_RETURN (res);
372 } else { // x is pos_inf, no way for it to be less than y
373 res = 1;
374 BID_RETURN (res);
376 } else if ((y & MASK_INF) == MASK_INF) {
377 // x is finite, so:
378 // if y is +inf, x<y
379 // if y is -inf, x>y
380 res = ((y & MASK_SIGN) == MASK_SIGN);
381 BID_RETURN (res);
383 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
384 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
385 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
386 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
387 if (sig_x > 9999999999999999ull) {
388 non_canon_x = 1;
389 } else {
390 non_canon_x = 0;
392 } else {
393 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
394 sig_x = (x & MASK_BINARY_SIG1);
395 non_canon_x = 0;
397 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
398 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
399 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
400 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
401 if (sig_y > 9999999999999999ull) {
402 non_canon_y = 1;
403 } else {
404 non_canon_y = 0;
406 } else {
407 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
408 sig_y = (y & MASK_BINARY_SIG1);
409 non_canon_y = 0;
411 // ZERO (CASE4)
412 // some properties:
413 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
414 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
415 // therefore ignore the exponent field
416 // (Any non-canonical # is considered 0)
417 if (non_canon_x || sig_x == 0) {
418 x_is_zero = 1;
420 if (non_canon_y || sig_y == 0) {
421 y_is_zero = 1;
423 if (x_is_zero && y_is_zero) {
424 // if both numbers are zero, they are equal
425 res = 1;
426 BID_RETURN (res);
427 } else if (x_is_zero) {
428 // if x is zero, it is lessthan if Y is positive
429 res = ((y & MASK_SIGN) == MASK_SIGN);
430 BID_RETURN (res);
431 } else if (y_is_zero) {
432 // if y is zero, X is less if it is negative
433 res = ((x & MASK_SIGN) != MASK_SIGN);
434 BID_RETURN (res);
436 // OPPOSITE SIGN (CASE5)
437 // now, if the sign bits differ, x is less than if y is positive
438 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
439 res = ((y & MASK_SIGN) == MASK_SIGN);
440 BID_RETURN (res);
442 // REDUNDANT REPRESENTATIONS (CASE6)
443 // if both components are either bigger or smaller
444 if (sig_x > sig_y && exp_x >= exp_y) {
445 res = ((x & MASK_SIGN) != MASK_SIGN);
446 BID_RETURN (res);
448 if (sig_x < sig_y && exp_x <= exp_y) {
449 res = ((x & MASK_SIGN) == MASK_SIGN);
450 BID_RETURN (res);
452 // if exp_x is 15 greater than exp_y, no need for compensation
453 if (exp_x - exp_y > 15) {
454 res = ((x & MASK_SIGN) != MASK_SIGN);
455 // difference cannot be greater than 10^15
456 BID_RETURN (res);
458 // if exp_x is 15 less than exp_y, no need for compensation
459 if (exp_y - exp_x > 15) {
460 res = ((x & MASK_SIGN) == MASK_SIGN);
461 BID_RETURN (res);
463 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
464 if (exp_x > exp_y) { // to simplify the loop below,
465 // otherwise adjust the x significand upwards
466 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
467 mult_factor[exp_x - exp_y]);
468 // return 1 if values are equal
469 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
470 res = 1;
471 BID_RETURN (res);
473 // if postitive, return whichever significand abs is smaller
474 // (converse if negative)
475 res = (((sig_n_prime.w[1] == 0)
476 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
477 MASK_SIGN));
478 BID_RETURN (res);
480 // adjust the y significand upwards
481 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
482 mult_factor[exp_y - exp_x]);
483 // return 0 if values are equal
484 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
485 res = 1;
486 BID_RETURN (res);
488 // if positive, return whichever significand abs is smaller
489 // (converse if negative)
490 res = (((sig_n_prime.w[1] > 0)
491 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
492 MASK_SIGN));
493 BID_RETURN (res);
496 #if DECIMAL_CALL_BY_REFERENCE
497 void
498 bid64_quiet_greater_unordered (int *pres, UINT64 * px,
499 UINT64 *
500 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
501 _EXC_INFO_PARAM) {
502 UINT64 x = *px;
503 UINT64 y = *py;
504 #else
506 bid64_quiet_greater_unordered (UINT64 x,
507 UINT64 y _EXC_FLAGS_PARAM
508 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
509 #endif
510 int res;
511 int exp_x, exp_y;
512 UINT64 sig_x, sig_y;
513 UINT128 sig_n_prime;
514 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
516 // NaN (CASE1)
517 // if either number is NAN, the comparison is unordered, rather than equal :
518 // return 0
519 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
520 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
521 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
523 res = 1;
524 BID_RETURN (res);
526 // SIMPLE (CASE2)
527 // if all the bits are the same, these numbers are equal (not Greater).
528 if (x == y) {
529 res = 0;
530 BID_RETURN (res);
532 // INFINITY (CASE3)
533 if ((x & MASK_INF) == MASK_INF) {
534 // if x is neg infinity, there is no way it is greater than y, return 0
535 if (((x & MASK_SIGN) == MASK_SIGN)) {
536 res = 0;
537 BID_RETURN (res);
538 } else {
539 // x is pos infinity, it is greater, unless y is positive infinity =>
540 // return y!=pos_infinity
541 res = (((y & MASK_INF) != MASK_INF)
542 || ((y & MASK_SIGN) == MASK_SIGN));
543 BID_RETURN (res);
545 } else if ((y & MASK_INF) == MASK_INF) {
546 // x is finite, so if y is positive infinity, then x is less, return 0
547 // if y is negative infinity, then x is greater, return 1
548 res = ((y & MASK_SIGN) == MASK_SIGN);
549 BID_RETURN (res);
551 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
552 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
553 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
554 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
555 if (sig_x > 9999999999999999ull) {
556 non_canon_x = 1;
557 } else {
558 non_canon_x = 0;
560 } else {
561 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
562 sig_x = (x & MASK_BINARY_SIG1);
563 non_canon_x = 0;
565 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
566 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
567 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
568 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
569 if (sig_y > 9999999999999999ull) {
570 non_canon_y = 1;
571 } else {
572 non_canon_y = 0;
574 } else {
575 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
576 sig_y = (y & MASK_BINARY_SIG1);
577 non_canon_y = 0;
579 // ZERO (CASE4)
580 // some properties:
581 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
582 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
583 // therefore ignore the exponent field
584 // (Any non-canonical # is considered 0)
585 if (non_canon_x || sig_x == 0) {
586 x_is_zero = 1;
588 if (non_canon_y || sig_y == 0) {
589 y_is_zero = 1;
591 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
592 if (x_is_zero && y_is_zero) {
593 res = 0;
594 BID_RETURN (res);
595 } else if (x_is_zero) {
596 // is x is zero, it is greater if Y is negative
597 res = ((y & MASK_SIGN) == MASK_SIGN);
598 BID_RETURN (res);
599 } else if (y_is_zero) {
600 // is y is zero, X is greater if it is positive
601 res = ((x & MASK_SIGN) != MASK_SIGN);
602 BID_RETURN (res);
604 // OPPOSITE SIGN (CASE5)
605 // now, if the sign bits differ, x is greater if y is negative
606 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
607 res = ((y & MASK_SIGN) == MASK_SIGN);
608 BID_RETURN (res);
610 // REDUNDANT REPRESENTATIONS (CASE6)
611 // if both components are either bigger or smaller
612 if (sig_x > sig_y && exp_x >= exp_y) {
613 res = ((x & MASK_SIGN) != MASK_SIGN);
614 BID_RETURN (res);
616 if (sig_x < sig_y && exp_x <= exp_y) {
617 res = ((x & MASK_SIGN) == MASK_SIGN);
618 BID_RETURN (res);
620 // if exp_x is 15 greater than exp_y, no need for compensation
621 if (exp_x - exp_y > 15) {
622 // difference cannot be greater than 10^15
623 res = ((x & MASK_SIGN) != MASK_SIGN);
624 BID_RETURN (res);
626 // if exp_x is 15 less than exp_y, no need for compensation
627 if (exp_y - exp_x > 15) {
628 res = ((x & MASK_SIGN) == MASK_SIGN);
629 BID_RETURN (res);
631 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
632 if (exp_x > exp_y) { // to simplify the loop below,
633 // otherwise adjust the x significand upwards
634 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
635 mult_factor[exp_x - exp_y]);
636 // if postitive, return whichever significand is larger
637 // (converse if negative)
638 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
639 res = 0;
640 BID_RETURN (res);
642 res = (((sig_n_prime.w[1] > 0)
643 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
644 MASK_SIGN));
645 BID_RETURN (res);
647 // adjust the y significand upwards
648 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
649 mult_factor[exp_y - exp_x]);
650 // if postitive, return whichever significand is larger (converse if negative)
651 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
652 res = 0;
653 BID_RETURN (res);
655 res = (((sig_n_prime.w[1] == 0)
656 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
657 MASK_SIGN));
658 BID_RETURN (res);
661 #if DECIMAL_CALL_BY_REFERENCE
662 void
663 bid64_quiet_less (int *pres, UINT64 * px,
664 UINT64 *
665 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM _EXC_INFO_PARAM)
667 UINT64 x = *px;
668 UINT64 y = *py;
669 #else
671 bid64_quiet_less (UINT64 x,
672 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
673 _EXC_INFO_PARAM) {
674 #endif
675 int res;
676 int exp_x, exp_y;
677 UINT64 sig_x, sig_y;
678 UINT128 sig_n_prime;
679 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
681 // NaN (CASE1)
682 // if either number is NAN, the comparison is unordered : return 0
683 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
684 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
685 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
687 res = 0;
688 BID_RETURN (res);
690 // SIMPLE (CASE2)
691 // if all the bits are the same, these numbers are equal.
692 if (x == y) {
693 res = 0;
694 BID_RETURN (res);
696 // INFINITY (CASE3)
697 if ((x & MASK_INF) == MASK_INF) {
698 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
699 if ((x & MASK_SIGN) == MASK_SIGN) {
700 // x is -inf, so it is less than y unless y is -inf
701 res = (((y & MASK_INF) != MASK_INF)
702 || (y & MASK_SIGN) != MASK_SIGN);
703 BID_RETURN (res);
704 } else {
705 // x is pos_inf, no way for it to be less than y
706 res = 0;
707 BID_RETURN (res);
709 } else if ((y & MASK_INF) == MASK_INF) {
710 // x is finite, so:
711 // if y is +inf, x<y
712 // if y is -inf, x>y
713 res = ((y & MASK_SIGN) != MASK_SIGN);
714 BID_RETURN (res);
716 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
717 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
718 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
719 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
720 if (sig_x > 9999999999999999ull) {
721 non_canon_x = 1;
722 } else {
723 non_canon_x = 0;
725 } else {
726 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
727 sig_x = (x & MASK_BINARY_SIG1);
728 non_canon_x = 0;
730 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
731 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
732 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
733 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
734 if (sig_y > 9999999999999999ull) {
735 non_canon_y = 1;
736 } else {
737 non_canon_y = 0;
739 } else {
740 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
741 sig_y = (y & MASK_BINARY_SIG1);
742 non_canon_y = 0;
744 // ZERO (CASE4)
745 // some properties:
746 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
747 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
748 // therefore ignore the exponent field
749 // (Any non-canonical # is considered 0)
750 if (non_canon_x || sig_x == 0) {
751 x_is_zero = 1;
753 if (non_canon_y || sig_y == 0) {
754 y_is_zero = 1;
756 if (x_is_zero && y_is_zero) {
757 // if both numbers are zero, they are equal
758 res = 0;
759 BID_RETURN (res);
760 } else if (x_is_zero) {
761 // if x is zero, it is lessthan if Y is positive
762 res = ((y & MASK_SIGN) != MASK_SIGN);
763 BID_RETURN (res);
764 } else if (y_is_zero) {
765 // if y is zero, X is less if it is negative
766 res = ((x & MASK_SIGN) == MASK_SIGN);
767 BID_RETURN (res);
769 // OPPOSITE SIGN (CASE5)
770 // now, if the sign bits differ, x is less than if y is positive
771 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
772 res = ((y & MASK_SIGN) != MASK_SIGN);
773 BID_RETURN (res);
775 // REDUNDANT REPRESENTATIONS (CASE6)
776 // if both components are either bigger or smaller,
777 // it is clear what needs to be done
778 if (sig_x > sig_y && exp_x >= exp_y) {
779 res = ((x & MASK_SIGN) == MASK_SIGN);
780 BID_RETURN (res);
782 if (sig_x < sig_y && exp_x <= exp_y) {
783 res = ((x & MASK_SIGN) != MASK_SIGN);
784 BID_RETURN (res);
786 // if exp_x is 15 greater than exp_y, no need for compensation
787 if (exp_x - exp_y > 15) {
788 res = ((x & MASK_SIGN) == MASK_SIGN);
789 // difference cannot be greater than 10^15
790 BID_RETURN (res);
792 // if exp_x is 15 less than exp_y, no need for compensation
793 if (exp_y - exp_x > 15) {
794 res = ((x & MASK_SIGN) != MASK_SIGN);
795 BID_RETURN (res);
797 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
798 if (exp_x > exp_y) { // to simplify the loop below,
799 // otherwise adjust the x significand upwards
800 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
801 mult_factor[exp_x - exp_y]);
802 // return 0 if values are equal
803 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
804 res = 0;
805 BID_RETURN (res);
807 // if postitive, return whichever significand abs is smaller
808 // (converse if negative)
809 res = (((sig_n_prime.w[1] == 0)
810 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
811 MASK_SIGN));
812 BID_RETURN (res);
814 // adjust the y significand upwards
815 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
816 mult_factor[exp_y - exp_x]);
817 // return 0 if values are equal
818 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
819 res = 0;
820 BID_RETURN (res);
822 // if positive, return whichever significand abs is smaller
823 // (converse if negative)
824 res = (((sig_n_prime.w[1] > 0)
825 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
826 MASK_SIGN));
827 BID_RETURN (res);
830 #if DECIMAL_CALL_BY_REFERENCE
831 void
832 bid64_quiet_less_equal (int *pres, UINT64 * px,
833 UINT64 *
834 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
835 _EXC_INFO_PARAM) {
836 UINT64 x = *px;
837 UINT64 y = *py;
838 #else
840 bid64_quiet_less_equal (UINT64 x,
841 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
842 _EXC_INFO_PARAM) {
843 #endif
844 int res;
845 int exp_x, exp_y;
846 UINT64 sig_x, sig_y;
847 UINT128 sig_n_prime;
848 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
850 // NaN (CASE1)
851 // if either number is NAN, the comparison is unordered, rather than equal :
852 // return 0
853 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
854 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
855 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
857 res = 0;
858 BID_RETURN (res);
860 // SIMPLE (CASE2)
861 // if all the bits are the same, these numbers are equal (LESSEQUAL).
862 if (x == y) {
863 res = 1;
864 BID_RETURN (res);
866 // INFINITY (CASE3)
867 if ((x & MASK_INF) == MASK_INF) {
868 if (((x & MASK_SIGN) == MASK_SIGN)) {
869 // if x is neg infinity, it must be lessthan or equal to y return 1
870 res = 1;
871 BID_RETURN (res);
872 } else {
873 // x is pos infinity, it is greater, unless y is positive infinity =>
874 // return y==pos_infinity
875 res = !(((y & MASK_INF) != MASK_INF)
876 || ((y & MASK_SIGN) == MASK_SIGN));
877 BID_RETURN (res);
879 } else if ((y & MASK_INF) == MASK_INF) {
880 // x is finite, so if y is positive infinity, then x is less, return 1
881 // if y is negative infinity, then x is greater, return 0
882 res = ((y & MASK_SIGN) != MASK_SIGN);
883 BID_RETURN (res);
885 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
886 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
887 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
888 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
889 if (sig_x > 9999999999999999ull) {
890 non_canon_x = 1;
891 } else {
892 non_canon_x = 0;
894 } else {
895 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
896 sig_x = (x & MASK_BINARY_SIG1);
897 non_canon_x = 0;
899 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
900 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
901 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
902 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
903 if (sig_y > 9999999999999999ull) {
904 non_canon_y = 1;
905 } else {
906 non_canon_y = 0;
908 } else {
909 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
910 sig_y = (y & MASK_BINARY_SIG1);
911 non_canon_y = 0;
913 // ZERO (CASE4)
914 // some properties:
915 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
916 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
917 // therefore ignore the exponent field
918 // (Any non-canonical # is considered 0)
919 if (non_canon_x || sig_x == 0) {
920 x_is_zero = 1;
922 if (non_canon_y || sig_y == 0) {
923 y_is_zero = 1;
925 if (x_is_zero && y_is_zero) {
926 // if both numbers are zero, they are equal -> return 1
927 res = 1;
928 BID_RETURN (res);
929 } else if (x_is_zero) {
930 // if x is zero, it is lessthan if Y is positive
931 res = ((y & MASK_SIGN) != MASK_SIGN);
932 BID_RETURN (res);
933 } else if (y_is_zero) {
934 // if y is zero, X is less if it is negative
935 res = ((x & MASK_SIGN) == MASK_SIGN);
936 BID_RETURN (res);
938 // OPPOSITE SIGN (CASE5)
939 // now, if the sign bits differ, x is less than if y is positive
940 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
941 res = ((y & MASK_SIGN) != MASK_SIGN);
942 BID_RETURN (res);
944 // REDUNDANT REPRESENTATIONS (CASE6)
945 // if both components are either bigger or smaller
946 if (sig_x > sig_y && exp_x >= exp_y) {
947 res = ((x & MASK_SIGN) == MASK_SIGN);
948 BID_RETURN (res);
950 if (sig_x < sig_y && exp_x <= exp_y) {
951 res = ((x & MASK_SIGN) != MASK_SIGN);
952 BID_RETURN (res);
954 // if exp_x is 15 greater than exp_y, no need for compensation
955 if (exp_x - exp_y > 15) {
956 res = ((x & MASK_SIGN) == MASK_SIGN);
957 // difference cannot be greater than 10^15
958 BID_RETURN (res);
960 // if exp_x is 15 less than exp_y, no need for compensation
961 if (exp_y - exp_x > 15) {
962 res = ((x & MASK_SIGN) != MASK_SIGN);
963 BID_RETURN (res);
965 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
966 if (exp_x > exp_y) { // to simplify the loop below,
967 // otherwise adjust the x significand upwards
968 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
969 mult_factor[exp_x - exp_y]);
970 // return 1 if values are equal
971 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
972 res = 1;
973 BID_RETURN (res);
975 // if postitive, return whichever significand abs is smaller
976 // (converse if negative)
977 res = (((sig_n_prime.w[1] == 0)
978 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
979 MASK_SIGN));
980 BID_RETURN (res);
982 // adjust the y significand upwards
983 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
984 mult_factor[exp_y - exp_x]);
985 // return 1 if values are equal
986 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
987 res = 1;
988 BID_RETURN (res);
990 // if positive, return whichever significand abs is smaller
991 // (converse if negative)
992 res = (((sig_n_prime.w[1] > 0)
993 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
994 MASK_SIGN));
995 BID_RETURN (res);
998 #if DECIMAL_CALL_BY_REFERENCE
999 void
1000 bid64_quiet_less_unordered (int *pres, UINT64 * px,
1001 UINT64 *
1002 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1003 _EXC_INFO_PARAM) {
1004 UINT64 x = *px;
1005 UINT64 y = *py;
1006 #else
1008 bid64_quiet_less_unordered (UINT64 x,
1009 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1010 _EXC_INFO_PARAM) {
1011 #endif
1012 int res;
1013 int exp_x, exp_y;
1014 UINT64 sig_x, sig_y;
1015 UINT128 sig_n_prime;
1016 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1018 // NaN (CASE1)
1019 // if either number is NAN, the comparison is unordered : return 0
1020 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1021 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1022 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1024 res = 1;
1025 BID_RETURN (res);
1027 // SIMPLE (CASE2)
1028 // if all the bits are the same, these numbers are equal.
1029 if (x == y) {
1030 res = 0;
1031 BID_RETURN (res);
1033 // INFINITY (CASE3)
1034 if ((x & MASK_INF) == MASK_INF) {
1035 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
1036 if ((x & MASK_SIGN) == MASK_SIGN) {
1037 // x is -inf, so it is less than y unless y is -inf
1038 res = (((y & MASK_INF) != MASK_INF)
1039 || (y & MASK_SIGN) != MASK_SIGN);
1040 BID_RETURN (res);
1041 } else {
1042 // x is pos_inf, no way for it to be less than y
1043 res = 0;
1044 BID_RETURN (res);
1046 } else if ((y & MASK_INF) == MASK_INF) {
1047 // x is finite, so:
1048 // if y is +inf, x<y
1049 // if y is -inf, x>y
1050 res = ((y & MASK_SIGN) != MASK_SIGN);
1051 BID_RETURN (res);
1053 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1054 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1055 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1056 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1057 if (sig_x > 9999999999999999ull) {
1058 non_canon_x = 1;
1059 } else {
1060 non_canon_x = 0;
1062 } else {
1063 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1064 sig_x = (x & MASK_BINARY_SIG1);
1065 non_canon_x = 0;
1067 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1068 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1069 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1070 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1071 if (sig_y > 9999999999999999ull) {
1072 non_canon_y = 1;
1073 } else {
1074 non_canon_y = 0;
1076 } else {
1077 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1078 sig_y = (y & MASK_BINARY_SIG1);
1079 non_canon_y = 0;
1081 // ZERO (CASE4)
1082 // some properties:
1083 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1084 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1085 // therefore ignore the exponent field
1086 // (Any non-canonical # is considered 0)
1087 if (non_canon_x || sig_x == 0) {
1088 x_is_zero = 1;
1090 if (non_canon_y || sig_y == 0) {
1091 y_is_zero = 1;
1093 if (x_is_zero && y_is_zero) {
1094 // if both numbers are zero, they are equal
1095 res = 0;
1096 BID_RETURN (res);
1097 } else if (x_is_zero) {
1098 // if x is zero, it is lessthan if Y is positive
1099 res = ((y & MASK_SIGN) != MASK_SIGN);
1100 BID_RETURN (res);
1101 } else if (y_is_zero) {
1102 // if y is zero, X is less if it is negative
1103 res = ((x & MASK_SIGN) == MASK_SIGN);
1104 BID_RETURN (res);
1106 // OPPOSITE SIGN (CASE5)
1107 // now, if the sign bits differ, x is less than if y is positive
1108 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1109 res = ((y & MASK_SIGN) != MASK_SIGN);
1110 BID_RETURN (res);
1112 // REDUNDANT REPRESENTATIONS (CASE6)
1113 // if both components are either bigger or smaller
1114 if (sig_x > sig_y && exp_x >= exp_y) {
1115 res = ((x & MASK_SIGN) == MASK_SIGN);
1116 BID_RETURN (res);
1118 if (sig_x < sig_y && exp_x <= exp_y) {
1119 res = ((x & MASK_SIGN) != MASK_SIGN);
1120 BID_RETURN (res);
1122 // if exp_x is 15 greater than exp_y, no need for compensation
1123 if (exp_x - exp_y > 15) {
1124 res = ((x & MASK_SIGN) == MASK_SIGN);
1125 // difference cannot be greater than 10^15
1126 BID_RETURN (res);
1128 // if exp_x is 15 less than exp_y, no need for compensation
1129 if (exp_y - exp_x > 15) {
1130 res = ((x & MASK_SIGN) != MASK_SIGN);
1131 BID_RETURN (res);
1133 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1134 if (exp_x > exp_y) { // to simplify the loop below,
1135 // otherwise adjust the x significand upwards
1136 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1137 mult_factor[exp_x - exp_y]);
1138 // return 0 if values are equal
1139 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1140 res = 0;
1141 BID_RETURN (res);
1143 // if postitive, return whichever significand abs is smaller
1144 // (converse if negative)
1145 res = (((sig_n_prime.w[1] == 0)
1146 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
1147 MASK_SIGN));
1148 BID_RETURN (res);
1150 // adjust the y significand upwards
1151 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1152 mult_factor[exp_y - exp_x]);
1153 // return 0 if values are equal
1154 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1155 res = 0;
1156 BID_RETURN (res);
1158 // if positive, return whichever significand abs is smaller
1159 // (converse if negative)
1160 res = (((sig_n_prime.w[1] > 0)
1161 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
1162 MASK_SIGN));
1163 BID_RETURN (res);
1166 #if DECIMAL_CALL_BY_REFERENCE
1167 void
1168 bid64_quiet_not_equal (int *pres, UINT64 * px,
1169 UINT64 *
1170 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1171 _EXC_INFO_PARAM) {
1172 UINT64 x = *px;
1173 UINT64 y = *py;
1174 #else
1176 bid64_quiet_not_equal (UINT64 x,
1177 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1178 _EXC_INFO_PARAM) {
1179 #endif
1180 int res;
1181 int exp_x, exp_y, exp_t;
1182 UINT64 sig_x, sig_y, sig_t;
1183 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y, lcv;
1185 // NaN (CASE1)
1186 // if either number is NAN, the comparison is unordered,
1187 // rather than equal : return 1
1188 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1189 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1190 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1192 res = 1;
1193 BID_RETURN (res);
1195 // SIMPLE (CASE2)
1196 // if all the bits are the same, these numbers are equivalent.
1197 if (x == y) {
1198 res = 0;
1199 BID_RETURN (res);
1201 // INFINITY (CASE3)
1202 if (((x & MASK_INF) == MASK_INF) && ((y & MASK_INF) == MASK_INF)) {
1203 res = (((x ^ y) & MASK_SIGN) == MASK_SIGN);
1204 BID_RETURN (res);
1206 // ONE INFINITY (CASE3')
1207 if (((x & MASK_INF) == MASK_INF) || ((y & MASK_INF) == MASK_INF)) {
1208 res = 1;
1209 BID_RETURN (res);
1211 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1212 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1213 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1214 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1215 if (sig_x > 9999999999999999ull) {
1216 non_canon_x = 1;
1217 } else {
1218 non_canon_x = 0;
1220 } else {
1221 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1222 sig_x = (x & MASK_BINARY_SIG1);
1223 non_canon_x = 0;
1226 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1227 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1228 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1229 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1230 if (sig_y > 9999999999999999ull) {
1231 non_canon_y = 1;
1232 } else {
1233 non_canon_y = 0;
1235 } else {
1236 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1237 sig_y = (y & MASK_BINARY_SIG1);
1238 non_canon_y = 0;
1241 // ZERO (CASE4)
1242 // some properties:
1243 // (+ZERO==-ZERO) => therefore ignore the sign
1244 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1245 // therefore ignore the exponent field
1246 // (Any non-canonical # is considered 0)
1247 if (non_canon_x || sig_x == 0) {
1248 x_is_zero = 1;
1250 if (non_canon_y || sig_y == 0) {
1251 y_is_zero = 1;
1254 if (x_is_zero && y_is_zero) {
1255 res = 0;
1256 BID_RETURN (res);
1257 } else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
1258 res = 1;
1259 BID_RETURN (res);
1261 // OPPOSITE SIGN (CASE5)
1262 // now, if the sign bits differ => not equal : return 1
1263 if ((x ^ y) & MASK_SIGN) {
1264 res = 1;
1265 BID_RETURN (res);
1267 // REDUNDANT REPRESENTATIONS (CASE6)
1268 if (exp_x > exp_y) { // to simplify the loop below,
1269 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
1270 SWAP (sig_x, sig_y, sig_t); // and the smaller exp in x
1273 if (exp_y - exp_x > 15) {
1274 res = 1;
1275 BID_RETURN (res);
1277 // difference cannot be greater than 10^16
1279 for (lcv = 0; lcv < (exp_y - exp_x); lcv++) {
1281 // recalculate y's significand upwards
1282 sig_y = sig_y * 10;
1283 if (sig_y > 9999999999999999ull) {
1284 res = 1;
1285 BID_RETURN (res);
1290 res = sig_y != sig_x;
1291 BID_RETURN (res);
1296 #if DECIMAL_CALL_BY_REFERENCE
1297 void
1298 bid64_quiet_not_greater (int *pres, UINT64 * px,
1299 UINT64 *
1300 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1301 _EXC_INFO_PARAM) {
1302 UINT64 x = *px;
1303 UINT64 y = *py;
1304 #else
1306 bid64_quiet_not_greater (UINT64 x,
1307 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1308 _EXC_INFO_PARAM) {
1309 #endif
1310 int res;
1311 int exp_x, exp_y;
1312 UINT64 sig_x, sig_y;
1313 UINT128 sig_n_prime;
1314 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1316 // NaN (CASE1)
1317 // if either number is NAN, the comparison is unordered,
1318 // rather than equal : return 0
1319 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1320 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1321 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1323 res = 1;
1324 BID_RETURN (res);
1326 // SIMPLE (CASE2)
1327 // if all the bits are the same, these numbers are equal (LESSEQUAL).
1328 if (x == y) {
1329 res = 1;
1330 BID_RETURN (res);
1332 // INFINITY (CASE3)
1333 if ((x & MASK_INF) == MASK_INF) {
1334 // if x is neg infinity, it must be lessthan or equal to y return 1
1335 if (((x & MASK_SIGN) == MASK_SIGN)) {
1336 res = 1;
1337 BID_RETURN (res);
1339 // x is pos infinity, it is greater, unless y is positive
1340 // infinity => return y==pos_infinity
1341 else {
1342 res = !(((y & MASK_INF) != MASK_INF)
1343 || ((y & MASK_SIGN) == MASK_SIGN));
1344 BID_RETURN (res);
1346 } else if ((y & MASK_INF) == MASK_INF) {
1347 // x is finite, so if y is positive infinity, then x is less, return 1
1348 // if y is negative infinity, then x is greater, return 0
1350 res = ((y & MASK_SIGN) != MASK_SIGN);
1351 BID_RETURN (res);
1354 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1355 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1356 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1357 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1358 if (sig_x > 9999999999999999ull) {
1359 non_canon_x = 1;
1360 } else {
1361 non_canon_x = 0;
1363 } else {
1364 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1365 sig_x = (x & MASK_BINARY_SIG1);
1366 non_canon_x = 0;
1369 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1370 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1371 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1372 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1373 if (sig_y > 9999999999999999ull) {
1374 non_canon_y = 1;
1375 } else {
1376 non_canon_y = 0;
1378 } else {
1379 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1380 sig_y = (y & MASK_BINARY_SIG1);
1381 non_canon_y = 0;
1384 // ZERO (CASE4)
1385 // some properties:
1386 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1387 // number is greater
1388 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1389 // therefore ignore the exponent field
1390 // (Any non-canonical # is considered 0)
1391 if (non_canon_x || sig_x == 0) {
1392 x_is_zero = 1;
1394 if (non_canon_y || sig_y == 0) {
1395 y_is_zero = 1;
1397 // if both numbers are zero, they are equal -> return 1
1398 if (x_is_zero && y_is_zero) {
1399 res = 1;
1400 BID_RETURN (res);
1402 // if x is zero, it is lessthan if Y is positive
1403 else if (x_is_zero) {
1404 res = ((y & MASK_SIGN) != MASK_SIGN);
1405 BID_RETURN (res);
1407 // if y is zero, X is less if it is negative
1408 else if (y_is_zero) {
1409 res = ((x & MASK_SIGN) == MASK_SIGN);
1410 BID_RETURN (res);
1412 // OPPOSITE SIGN (CASE5)
1413 // now, if the sign bits differ, x is less than if y is positive
1414 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1415 res = ((y & MASK_SIGN) != MASK_SIGN);
1416 BID_RETURN (res);
1418 // REDUNDANT REPRESENTATIONS (CASE6)
1419 // if both components are either bigger or smaller
1420 if (sig_x > sig_y && exp_x >= exp_y) {
1421 res = ((x & MASK_SIGN) == MASK_SIGN);
1422 BID_RETURN (res);
1424 if (sig_x < sig_y && exp_x <= exp_y) {
1425 res = ((x & MASK_SIGN) != MASK_SIGN);
1426 BID_RETURN (res);
1428 // if exp_x is 15 greater than exp_y, no need for compensation
1429 if (exp_x - exp_y > 15) {
1430 res = ((x & MASK_SIGN) == MASK_SIGN);
1431 BID_RETURN (res);
1433 // difference cannot be greater than 10^15
1435 // if exp_x is 15 less than exp_y, no need for compensation
1436 if (exp_y - exp_x > 15) {
1437 res = ((x & MASK_SIGN) != MASK_SIGN);
1438 BID_RETURN (res);
1440 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1441 if (exp_x > exp_y) { // to simplify the loop below,
1443 // otherwise adjust the x significand upwards
1444 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1445 mult_factor[exp_x - exp_y]);
1447 // return 1 if values are equal
1448 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1449 res = 1;
1450 BID_RETURN (res);
1452 // if postitive, return whichever significand abs is smaller
1453 // (converse if negative)
1455 res = (((sig_n_prime.w[1] == 0)
1456 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
1457 MASK_SIGN));
1458 BID_RETURN (res);
1461 // adjust the y significand upwards
1462 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1463 mult_factor[exp_y - exp_x]);
1465 // return 1 if values are equal
1466 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1467 res = 1;
1468 BID_RETURN (res);
1470 // if positive, return whichever significand abs is smaller
1471 // (converse if negative)
1473 res = (((sig_n_prime.w[1] > 0)
1474 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
1475 MASK_SIGN));
1476 BID_RETURN (res);
1480 #if DECIMAL_CALL_BY_REFERENCE
1481 void
1482 bid64_quiet_not_less (int *pres, UINT64 * px,
1483 UINT64 *
1484 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1485 _EXC_INFO_PARAM) {
1486 UINT64 x = *px;
1487 UINT64 y = *py;
1488 #else
1490 bid64_quiet_not_less (UINT64 x,
1491 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1492 _EXC_INFO_PARAM) {
1493 #endif
1494 int res;
1495 int exp_x, exp_y;
1496 UINT64 sig_x, sig_y;
1497 UINT128 sig_n_prime;
1498 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1500 // NaN (CASE1)
1501 // if either number is NAN, the comparison is unordered : return 1
1502 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1503 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1504 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1506 res = 1;
1507 BID_RETURN (res);
1509 // SIMPLE (CASE2)
1510 // if all the bits are the same, these numbers are equal.
1511 if (x == y) {
1512 res = 1;
1513 BID_RETURN (res);
1515 // INFINITY (CASE3)
1516 if ((x & MASK_INF) == MASK_INF) {
1517 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1518 if ((x & MASK_SIGN) == MASK_SIGN)
1519 // x is -inf, so it is less than y unless y is -inf
1521 res = (((y & MASK_INF) == MASK_INF)
1522 && (y & MASK_SIGN) == MASK_SIGN);
1523 BID_RETURN (res);
1524 } else
1525 // x is pos_inf, no way for it to be less than y
1527 res = 1;
1528 BID_RETURN (res);
1530 } else if ((y & MASK_INF) == MASK_INF) {
1531 // x is finite, so:
1532 // if y is +inf, x<y
1533 // if y is -inf, x>y
1535 res = ((y & MASK_SIGN) == MASK_SIGN);
1536 BID_RETURN (res);
1539 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1540 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1541 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1542 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1543 if (sig_x > 9999999999999999ull) {
1544 non_canon_x = 1;
1545 } else {
1546 non_canon_x = 0;
1548 } else {
1549 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1550 sig_x = (x & MASK_BINARY_SIG1);
1551 non_canon_x = 0;
1554 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1555 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1556 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1557 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1558 if (sig_y > 9999999999999999ull) {
1559 non_canon_y = 1;
1560 } else {
1561 non_canon_y = 0;
1563 } else {
1564 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1565 sig_y = (y & MASK_BINARY_SIG1);
1566 non_canon_y = 0;
1569 // ZERO (CASE4)
1570 // some properties:
1571 // (+ZERO==-ZERO) => therefore ignore the sign, and neither
1572 // number is greater
1573 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1574 // therefore ignore the exponent field
1575 // (Any non-canonical # is considered 0)
1576 if (non_canon_x || sig_x == 0) {
1577 x_is_zero = 1;
1579 if (non_canon_y || sig_y == 0) {
1580 y_is_zero = 1;
1582 // if both numbers are zero, they are equal
1583 if (x_is_zero && y_is_zero) {
1584 res = 1;
1585 BID_RETURN (res);
1587 // if x is zero, it is lessthan if Y is positive
1588 else if (x_is_zero) {
1589 res = ((y & MASK_SIGN) == MASK_SIGN);
1590 BID_RETURN (res);
1592 // if y is zero, X is less if it is negative
1593 else if (y_is_zero) {
1594 res = ((x & MASK_SIGN) != MASK_SIGN);
1595 BID_RETURN (res);
1597 // OPPOSITE SIGN (CASE5)
1598 // now, if the sign bits differ, x is less than if y is positive
1599 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1600 res = ((y & MASK_SIGN) == MASK_SIGN);
1601 BID_RETURN (res);
1603 // REDUNDANT REPRESENTATIONS (CASE6)
1604 // if both components are either bigger or smaller
1605 if (sig_x > sig_y && exp_x >= exp_y) {
1606 res = ((x & MASK_SIGN) != MASK_SIGN);
1607 BID_RETURN (res);
1609 if (sig_x < sig_y && exp_x <= exp_y) {
1610 res = ((x & MASK_SIGN) == MASK_SIGN);
1611 BID_RETURN (res);
1613 // if exp_x is 15 greater than exp_y, no need for compensation
1614 if (exp_x - exp_y > 15) {
1615 res = ((x & MASK_SIGN) != MASK_SIGN);
1616 BID_RETURN (res);
1618 // difference cannot be greater than 10^15
1620 // if exp_x is 15 less than exp_y, no need for compensation
1621 if (exp_y - exp_x > 15) {
1622 res = ((x & MASK_SIGN) == MASK_SIGN);
1623 BID_RETURN (res);
1625 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1626 if (exp_x > exp_y) { // to simplify the loop below,
1628 // otherwise adjust the x significand upwards
1629 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1630 mult_factor[exp_x - exp_y]);
1632 // return 0 if values are equal
1633 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1634 res = 1;
1635 BID_RETURN (res);
1637 // if postitive, return whichever significand abs is smaller
1638 // (converse if negative)
1640 res = (((sig_n_prime.w[1] == 0)
1641 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
1642 MASK_SIGN));
1643 BID_RETURN (res);
1646 // adjust the y significand upwards
1647 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1648 mult_factor[exp_y - exp_x]);
1650 // return 0 if values are equal
1651 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1652 res = 1;
1653 BID_RETURN (res);
1655 // if positive, return whichever significand abs is smaller
1656 // (converse if negative)
1658 res = (((sig_n_prime.w[1] > 0)
1659 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
1660 MASK_SIGN));
1661 BID_RETURN (res);
1665 #if DECIMAL_CALL_BY_REFERENCE
1666 void
1667 bid64_quiet_ordered (int *pres, UINT64 * px,
1668 UINT64 *
1669 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1670 _EXC_INFO_PARAM) {
1671 UINT64 x = *px;
1672 UINT64 y = *py;
1673 #else
1675 bid64_quiet_ordered (UINT64 x,
1676 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1677 _EXC_INFO_PARAM) {
1678 #endif
1679 int res;
1681 // NaN (CASE1)
1682 // if either number is NAN, the comparison is ordered, rather than equal : return 0
1683 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1684 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1685 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1687 res = 0;
1688 BID_RETURN (res);
1689 } else {
1690 res = 1;
1691 BID_RETURN (res);
1695 #if DECIMAL_CALL_BY_REFERENCE
1696 void
1697 bid64_quiet_unordered (int *pres, UINT64 * px,
1698 UINT64 *
1699 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1700 _EXC_INFO_PARAM) {
1701 UINT64 x = *px;
1702 UINT64 y = *py;
1703 #else
1705 bid64_quiet_unordered (UINT64 x,
1706 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1707 _EXC_INFO_PARAM) {
1708 #endif
1709 int res;
1711 // NaN (CASE1)
1712 // if either number is NAN, the comparison is unordered,
1713 // rather than equal : return 0
1714 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1715 if ((x & MASK_SNAN) == MASK_SNAN || (y & MASK_SNAN) == MASK_SNAN) {
1716 *pfpsf |= INVALID_EXCEPTION; // set exception if sNaN
1718 res = 1;
1719 BID_RETURN (res);
1720 } else {
1721 res = 0;
1722 BID_RETURN (res);
1726 #if DECIMAL_CALL_BY_REFERENCE
1727 void
1728 bid64_signaling_greater (int *pres, UINT64 * px,
1729 UINT64 *
1730 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1731 _EXC_INFO_PARAM) {
1732 UINT64 x = *px;
1733 UINT64 y = *py;
1734 #else
1736 bid64_signaling_greater (UINT64 x,
1737 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1738 _EXC_INFO_PARAM) {
1739 #endif
1740 int res;
1741 int exp_x, exp_y;
1742 UINT64 sig_x, sig_y;
1743 UINT128 sig_n_prime;
1744 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1746 // NaN (CASE1)
1747 // if either number is NAN, the comparison is unordered,
1748 // rather than equal : return 0
1749 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1750 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
1751 res = 0;
1752 BID_RETURN (res);
1754 // SIMPLE (CASE2)
1755 // if all the bits are the same, these numbers are equal (not Greater).
1756 if (x == y) {
1757 res = 0;
1758 BID_RETURN (res);
1760 // INFINITY (CASE3)
1761 if ((x & MASK_INF) == MASK_INF) {
1762 // if x is neg infinity, there is no way it is greater than y, return 0
1763 if (((x & MASK_SIGN) == MASK_SIGN)) {
1764 res = 0;
1765 BID_RETURN (res);
1767 // x is pos infinity, it is greater,
1768 // unless y is positive infinity => return y!=pos_infinity
1769 else {
1770 res = (((y & MASK_INF) != MASK_INF)
1771 || ((y & MASK_SIGN) == MASK_SIGN));
1772 BID_RETURN (res);
1774 } else if ((y & MASK_INF) == MASK_INF) {
1775 // x is finite, so if y is positive infinity, then x is less, return 0
1776 // if y is negative infinity, then x is greater, return 1
1778 res = ((y & MASK_SIGN) == MASK_SIGN);
1779 BID_RETURN (res);
1782 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1783 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1784 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1785 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1786 if (sig_x > 9999999999999999ull) {
1787 non_canon_x = 1;
1788 } else {
1789 non_canon_x = 0;
1791 } else {
1792 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1793 sig_x = (x & MASK_BINARY_SIG1);
1794 non_canon_x = 0;
1797 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1798 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1799 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1800 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1801 if (sig_y > 9999999999999999ull) {
1802 non_canon_y = 1;
1803 } else {
1804 non_canon_y = 0;
1806 } else {
1807 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1808 sig_y = (y & MASK_BINARY_SIG1);
1809 non_canon_y = 0;
1812 // ZERO (CASE4)
1813 // some properties:
1814 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1815 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1816 // therefore ignore the exponent field
1817 // (Any non-canonical # is considered 0)
1818 if (non_canon_x || sig_x == 0) {
1819 x_is_zero = 1;
1821 if (non_canon_y || sig_y == 0) {
1822 y_is_zero = 1;
1824 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
1825 if (x_is_zero && y_is_zero) {
1826 res = 0;
1827 BID_RETURN (res);
1829 // is x is zero, it is greater if Y is negative
1830 else if (x_is_zero) {
1831 res = ((y & MASK_SIGN) == MASK_SIGN);
1832 BID_RETURN (res);
1834 // is y is zero, X is greater if it is positive
1835 else if (y_is_zero) {
1836 res = ((x & MASK_SIGN) != MASK_SIGN);
1837 BID_RETURN (res);
1839 // OPPOSITE SIGN (CASE5)
1840 // now, if the sign bits differ, x is greater if y is negative
1841 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
1842 res = ((y & MASK_SIGN) == MASK_SIGN);
1843 BID_RETURN (res);
1845 // REDUNDANT REPRESENTATIONS (CASE6)
1847 // if both components are either bigger or smaller
1848 if (sig_x > sig_y && exp_x >= exp_y) {
1849 res = ((x & MASK_SIGN) != MASK_SIGN);
1850 BID_RETURN (res);
1852 if (sig_x < sig_y && exp_x <= exp_y) {
1853 res = ((x & MASK_SIGN) == MASK_SIGN);
1854 BID_RETURN (res);
1856 // if exp_x is 15 greater than exp_y, no need for compensation
1857 if (exp_x - exp_y > 15) {
1858 res = ((x & MASK_SIGN) != MASK_SIGN);
1859 BID_RETURN (res);
1861 // difference cannot be greater than 10^15
1863 // if exp_x is 15 less than exp_y, no need for compensation
1864 if (exp_y - exp_x > 15) {
1865 res = ((x & MASK_SIGN) == MASK_SIGN);
1866 BID_RETURN (res);
1868 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
1869 if (exp_x > exp_y) { // to simplify the loop below,
1871 // otherwise adjust the x significand upwards
1872 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
1873 mult_factor[exp_x - exp_y]);
1876 // if postitive, return whichever significand is larger
1877 // (converse if negative)
1878 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
1879 res = 0;
1880 BID_RETURN (res);
1884 res = (((sig_n_prime.w[1] > 0)
1885 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
1886 MASK_SIGN));
1887 BID_RETURN (res);
1890 // adjust the y significand upwards
1891 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
1892 mult_factor[exp_y - exp_x]);
1894 // if postitive, return whichever significand is larger
1895 // (converse if negative)
1896 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
1897 res = 0;
1898 BID_RETURN (res);
1901 res = (((sig_n_prime.w[1] == 0)
1902 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
1903 MASK_SIGN));
1904 BID_RETURN (res);
1908 #if DECIMAL_CALL_BY_REFERENCE
1909 void
1910 bid64_signaling_greater_equal (int *pres, UINT64 * px,
1911 UINT64 *
1912 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
1913 _EXC_INFO_PARAM) {
1914 UINT64 x = *px;
1915 UINT64 y = *py;
1916 #else
1918 bid64_signaling_greater_equal (UINT64 x,
1919 UINT64 y _EXC_FLAGS_PARAM
1920 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
1921 #endif
1922 int res;
1923 int exp_x, exp_y;
1924 UINT64 sig_x, sig_y;
1925 UINT128 sig_n_prime;
1926 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1928 // NaN (CASE1)
1929 // if either number is NAN, the comparison is unordered : return 1
1930 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
1931 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
1932 res = 0;
1933 BID_RETURN (res);
1935 // SIMPLE (CASE2)
1936 // if all the bits are the same, these numbers are equal.
1937 if (x == y) {
1938 res = 1;
1939 BID_RETURN (res);
1941 // INFINITY (CASE3)
1942 if ((x & MASK_INF) == MASK_INF) {
1943 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1944 if ((x & MASK_SIGN) == MASK_SIGN)
1945 // x is -inf, so it is less than y unless y is -inf
1947 res = (((y & MASK_INF) == MASK_INF)
1948 && (y & MASK_SIGN) == MASK_SIGN);
1949 BID_RETURN (res);
1950 } else
1951 // x is pos_inf, no way for it to be less than y
1953 res = 1;
1954 BID_RETURN (res);
1956 } else if ((y & MASK_INF) == MASK_INF) {
1957 // x is finite, so:
1958 // if y is +inf, x<y
1959 // if y is -inf, x>y
1961 res = ((y & MASK_SIGN) == MASK_SIGN);
1962 BID_RETURN (res);
1965 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1966 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1967 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
1968 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1969 if (sig_x > 9999999999999999ull) {
1970 non_canon_x = 1;
1971 } else {
1972 non_canon_x = 0;
1974 } else {
1975 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
1976 sig_x = (x & MASK_BINARY_SIG1);
1977 non_canon_x = 0;
1980 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
1981 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
1982 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
1983 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
1984 if (sig_y > 9999999999999999ull) {
1985 non_canon_y = 1;
1986 } else {
1987 non_canon_y = 0;
1989 } else {
1990 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
1991 sig_y = (y & MASK_BINARY_SIG1);
1992 non_canon_y = 0;
1995 // ZERO (CASE4)
1996 // some properties:
1997 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
1998 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
1999 // therefore ignore the exponent field
2000 // (Any non-canonical # is considered 0)
2001 if (non_canon_x || sig_x == 0) {
2002 x_is_zero = 1;
2004 if (non_canon_y || sig_y == 0) {
2005 y_is_zero = 1;
2007 // if both numbers are zero, they are equal
2008 if (x_is_zero && y_is_zero) {
2009 res = 1;
2010 BID_RETURN (res);
2012 // if x is zero, it is lessthan if Y is positive
2013 else if (x_is_zero) {
2014 res = ((y & MASK_SIGN) == MASK_SIGN);
2015 BID_RETURN (res);
2017 // if y is zero, X is less if it is negative
2018 else if (y_is_zero) {
2019 res = ((x & MASK_SIGN) != MASK_SIGN);
2020 BID_RETURN (res);
2022 // OPPOSITE SIGN (CASE5)
2023 // now, if the sign bits differ, x is less than if y is positive
2024 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2025 res = ((y & MASK_SIGN) == MASK_SIGN);
2026 BID_RETURN (res);
2028 // REDUNDANT REPRESENTATIONS (CASE6)
2029 // if both components are either bigger or smaller
2030 if (sig_x > sig_y && exp_x >= exp_y) {
2031 res = ((x & MASK_SIGN) != MASK_SIGN);
2032 BID_RETURN (res);
2034 if (sig_x < sig_y && exp_x <= exp_y) {
2035 res = ((x & MASK_SIGN) == MASK_SIGN);
2036 BID_RETURN (res);
2038 // if exp_x is 15 greater than exp_y, no need for compensation
2039 if (exp_x - exp_y > 15) {
2040 res = ((x & MASK_SIGN) != MASK_SIGN);
2041 BID_RETURN (res);
2043 // difference cannot be greater than 10^15
2045 // if exp_x is 15 less than exp_y, no need for compensation
2046 if (exp_y - exp_x > 15) {
2047 res = ((x & MASK_SIGN) == MASK_SIGN);
2048 BID_RETURN (res);
2050 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2051 if (exp_x > exp_y) { // to simplify the loop below,
2053 // otherwise adjust the x significand upwards
2054 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2055 mult_factor[exp_x - exp_y]);
2057 // return 1 if values are equal
2058 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2059 res = 1;
2060 BID_RETURN (res);
2062 // if postitive, return whichever significand abs is smaller
2063 // (converse if negative)
2065 res = (((sig_n_prime.w[1] == 0)
2066 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
2067 MASK_SIGN));
2068 BID_RETURN (res);
2071 // adjust the y significand upwards
2072 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2073 mult_factor[exp_y - exp_x]);
2075 // return 0 if values are equal
2076 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2077 res = 1;
2078 BID_RETURN (res);
2080 // if positive, return whichever significand abs is smaller
2081 // (converse if negative)
2083 res = (((sig_n_prime.w[1] > 0)
2084 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
2085 MASK_SIGN));
2086 BID_RETURN (res);
2090 #if DECIMAL_CALL_BY_REFERENCE
2091 void
2092 bid64_signaling_greater_unordered (int *pres, UINT64 * px,
2093 UINT64 *
2094 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2095 _EXC_INFO_PARAM) {
2096 UINT64 x = *px;
2097 UINT64 y = *py;
2098 #else
2100 bid64_signaling_greater_unordered (UINT64 x,
2101 UINT64 y _EXC_FLAGS_PARAM
2102 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
2103 #endif
2104 int res;
2105 int exp_x, exp_y;
2106 UINT64 sig_x, sig_y;
2107 UINT128 sig_n_prime;
2108 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2110 // NaN (CASE1)
2111 // if either number is NAN, the comparison is unordered,
2112 // rather than equal : return 0
2113 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2114 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2115 res = 1;
2116 BID_RETURN (res);
2118 // SIMPLE (CASE2)
2119 // if all the bits are the same, these numbers are equal (not Greater).
2120 if (x == y) {
2121 res = 0;
2122 BID_RETURN (res);
2124 // INFINITY (CASE3)
2125 if ((x & MASK_INF) == MASK_INF) {
2126 // if x is neg infinity, there is no way it is greater than y, return 0
2127 if (((x & MASK_SIGN) == MASK_SIGN)) {
2128 res = 0;
2129 BID_RETURN (res);
2131 // x is pos infinity, it is greater,
2132 // unless y is positive infinity => return y!=pos_infinity
2133 else {
2134 res = (((y & MASK_INF) != MASK_INF)
2135 || ((y & MASK_SIGN) == MASK_SIGN));
2136 BID_RETURN (res);
2138 } else if ((y & MASK_INF) == MASK_INF) {
2139 // x is finite, so if y is positive infinity, then x is less, return 0
2140 // if y is negative infinity, then x is greater, return 1
2142 res = ((y & MASK_SIGN) == MASK_SIGN);
2143 BID_RETURN (res);
2146 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2147 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2148 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2149 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2150 if (sig_x > 9999999999999999ull) {
2151 non_canon_x = 1;
2152 } else {
2153 non_canon_x = 0;
2155 } else {
2156 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2157 sig_x = (x & MASK_BINARY_SIG1);
2158 non_canon_x = 0;
2161 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2162 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2163 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2164 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2165 if (sig_y > 9999999999999999ull) {
2166 non_canon_y = 1;
2167 } else {
2168 non_canon_y = 0;
2170 } else {
2171 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2172 sig_y = (y & MASK_BINARY_SIG1);
2173 non_canon_y = 0;
2176 // ZERO (CASE4)
2177 // some properties:
2178 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2179 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2180 // therefore ignore the exponent field
2181 // (Any non-canonical # is considered 0)
2182 if (non_canon_x || sig_x == 0) {
2183 x_is_zero = 1;
2185 if (non_canon_y || sig_y == 0) {
2186 y_is_zero = 1;
2188 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
2189 if (x_is_zero && y_is_zero) {
2190 res = 0;
2191 BID_RETURN (res);
2193 // is x is zero, it is greater if Y is negative
2194 else if (x_is_zero) {
2195 res = ((y & MASK_SIGN) == MASK_SIGN);
2196 BID_RETURN (res);
2198 // is y is zero, X is greater if it is positive
2199 else if (y_is_zero) {
2200 res = ((x & MASK_SIGN) != MASK_SIGN);
2201 BID_RETURN (res);
2203 // OPPOSITE SIGN (CASE5)
2204 // now, if the sign bits differ, x is greater if y is negative
2205 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2206 res = ((y & MASK_SIGN) == MASK_SIGN);
2207 BID_RETURN (res);
2209 // REDUNDANT REPRESENTATIONS (CASE6)
2211 // if both components are either bigger or smaller
2212 if (sig_x > sig_y && exp_x >= exp_y) {
2213 res = ((x & MASK_SIGN) != MASK_SIGN);
2214 BID_RETURN (res);
2216 if (sig_x < sig_y && exp_x <= exp_y) {
2217 res = ((x & MASK_SIGN) == MASK_SIGN);
2218 BID_RETURN (res);
2220 // if exp_x is 15 greater than exp_y, no need for compensation
2221 if (exp_x - exp_y > 15) {
2222 res = ((x & MASK_SIGN) != MASK_SIGN);
2223 BID_RETURN (res);
2225 // difference cannot be greater than 10^15
2227 // if exp_x is 15 less than exp_y, no need for compensation
2228 if (exp_y - exp_x > 15) {
2229 res = ((x & MASK_SIGN) == MASK_SIGN);
2230 BID_RETURN (res);
2232 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2233 if (exp_x > exp_y) { // to simplify the loop below,
2235 // otherwise adjust the x significand upwards
2236 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2237 mult_factor[exp_x - exp_y]);
2239 // if postitive, return whichever significand is larger
2240 // (converse if negative)
2241 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2242 res = 0;
2243 BID_RETURN (res);
2247 res = (((sig_n_prime.w[1] > 0)
2248 || sig_n_prime.w[0] > sig_y) ^ ((x & MASK_SIGN) ==
2249 MASK_SIGN));
2250 BID_RETURN (res);
2253 // adjust the y significand upwards
2254 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2255 mult_factor[exp_y - exp_x]);
2257 // if postitive, return whichever significand is larger
2258 // (converse if negative)
2259 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2260 res = 0;
2261 BID_RETURN (res);
2264 res = (((sig_n_prime.w[1] == 0)
2265 && (sig_x > sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2266 MASK_SIGN));
2267 BID_RETURN (res);
2271 #if DECIMAL_CALL_BY_REFERENCE
2272 void
2273 bid64_signaling_less (int *pres, UINT64 * px,
2274 UINT64 *
2275 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2276 _EXC_INFO_PARAM) {
2277 UINT64 x = *px;
2278 UINT64 y = *py;
2279 #else
2281 bid64_signaling_less (UINT64 x,
2282 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2283 _EXC_INFO_PARAM) {
2284 #endif
2285 int res;
2286 int exp_x, exp_y;
2287 UINT64 sig_x, sig_y;
2288 UINT128 sig_n_prime;
2289 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2291 // NaN (CASE1)
2292 // if either number is NAN, the comparison is unordered : return 0
2293 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2294 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2295 res = 0;
2296 BID_RETURN (res);
2298 // SIMPLE (CASE2)
2299 // if all the bits are the same, these numbers are equal.
2300 if (x == y) {
2301 res = 0;
2302 BID_RETURN (res);
2304 // INFINITY (CASE3)
2305 if ((x & MASK_INF) == MASK_INF) {
2306 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2307 if ((x & MASK_SIGN) == MASK_SIGN)
2308 // x is -inf, so it is less than y unless y is -inf
2310 res = (((y & MASK_INF) != MASK_INF)
2311 || (y & MASK_SIGN) != MASK_SIGN);
2312 BID_RETURN (res);
2313 } else
2314 // x is pos_inf, no way for it to be less than y
2316 res = 0;
2317 BID_RETURN (res);
2319 } else if ((y & MASK_INF) == MASK_INF) {
2320 // x is finite, so:
2321 // if y is +inf, x<y
2322 // if y is -inf, x>y
2324 res = ((y & MASK_SIGN) != MASK_SIGN);
2325 BID_RETURN (res);
2328 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2329 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2330 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2331 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2332 if (sig_x > 9999999999999999ull) {
2333 non_canon_x = 1;
2334 } else {
2335 non_canon_x = 0;
2337 } else {
2338 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2339 sig_x = (x & MASK_BINARY_SIG1);
2340 non_canon_x = 0;
2343 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2344 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2345 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2346 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2347 if (sig_y > 9999999999999999ull) {
2348 non_canon_y = 1;
2349 } else {
2350 non_canon_y = 0;
2352 } else {
2353 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2354 sig_y = (y & MASK_BINARY_SIG1);
2355 non_canon_y = 0;
2358 // ZERO (CASE4)
2359 // some properties:
2360 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2361 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2362 // therefore ignore the exponent field
2363 // (Any non-canonical # is considered 0)
2364 if (non_canon_x || sig_x == 0) {
2365 x_is_zero = 1;
2367 if (non_canon_y || sig_y == 0) {
2368 y_is_zero = 1;
2370 // if both numbers are zero, they are equal
2371 if (x_is_zero && y_is_zero) {
2372 res = 0;
2373 BID_RETURN (res);
2375 // if x is zero, it is lessthan if Y is positive
2376 else if (x_is_zero) {
2377 res = ((y & MASK_SIGN) != MASK_SIGN);
2378 BID_RETURN (res);
2380 // if y is zero, X is less if it is negative
2381 else if (y_is_zero) {
2382 res = ((x & MASK_SIGN) == MASK_SIGN);
2383 BID_RETURN (res);
2385 // OPPOSITE SIGN (CASE5)
2386 // now, if the sign bits differ, x is less than if y is positive
2387 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2388 res = ((y & MASK_SIGN) != MASK_SIGN);
2389 BID_RETURN (res);
2391 // REDUNDANT REPRESENTATIONS (CASE6)
2392 // if both components are either bigger or smaller
2393 if (sig_x > sig_y && exp_x >= exp_y) {
2394 res = ((x & MASK_SIGN) == MASK_SIGN);
2395 BID_RETURN (res);
2397 if (sig_x < sig_y && exp_x <= exp_y) {
2398 res = ((x & MASK_SIGN) != MASK_SIGN);
2399 BID_RETURN (res);
2401 // if exp_x is 15 greater than exp_y, no need for compensation
2402 if (exp_x - exp_y > 15) {
2403 res = ((x & MASK_SIGN) == MASK_SIGN);
2404 BID_RETURN (res);
2406 // difference cannot be greater than 10^15
2408 // if exp_x is 15 less than exp_y, no need for compensation
2409 if (exp_y - exp_x > 15) {
2410 res = ((x & MASK_SIGN) != MASK_SIGN);
2411 BID_RETURN (res);
2413 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2414 if (exp_x > exp_y) { // to simplify the loop below,
2416 // otherwise adjust the x significand upwards
2417 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2418 mult_factor[exp_x - exp_y]);
2420 // return 0 if values are equal
2421 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2422 res = 0;
2423 BID_RETURN (res);
2425 // if postitive, return whichever significand abs is smaller
2426 // (converse if negative)
2428 res = (((sig_n_prime.w[1] == 0)
2429 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2430 MASK_SIGN));
2431 BID_RETURN (res);
2434 // adjust the y significand upwards
2435 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2436 mult_factor[exp_y - exp_x]);
2438 // return 0 if values are equal
2439 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2440 res = 0;
2441 BID_RETURN (res);
2443 // if positive, return whichever significand abs is smaller
2444 // (converse if negative)
2446 res = (((sig_n_prime.w[1] > 0)
2447 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2448 MASK_SIGN));
2449 BID_RETURN (res);
2453 #if DECIMAL_CALL_BY_REFERENCE
2454 void
2455 bid64_signaling_less_equal (int *pres, UINT64 * px,
2456 UINT64 *
2457 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2458 _EXC_INFO_PARAM) {
2459 UINT64 x = *px;
2460 UINT64 y = *py;
2461 #else
2463 bid64_signaling_less_equal (UINT64 x,
2464 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2465 _EXC_INFO_PARAM) {
2466 #endif
2467 int res;
2468 int exp_x, exp_y;
2469 UINT64 sig_x, sig_y;
2470 UINT128 sig_n_prime;
2471 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2473 // NaN (CASE1)
2474 // if either number is NAN, the comparison is unordered,
2475 // rather than equal : return 0
2476 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2477 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2478 res = 0;
2479 BID_RETURN (res);
2481 // SIMPLE (CASE2)
2482 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2483 if (x == y) {
2484 res = 1;
2485 BID_RETURN (res);
2487 // INFINITY (CASE3)
2488 if ((x & MASK_INF) == MASK_INF) {
2489 // if x is neg infinity, it must be lessthan or equal to y return 1
2490 if (((x & MASK_SIGN) == MASK_SIGN)) {
2491 res = 1;
2492 BID_RETURN (res);
2494 // x is pos infinity, it is greater,
2495 // unless y is positive infinity => return y==pos_infinity
2496 else {
2497 res = !(((y & MASK_INF) != MASK_INF)
2498 || ((y & MASK_SIGN) == MASK_SIGN));
2499 BID_RETURN (res);
2501 } else if ((y & MASK_INF) == MASK_INF) {
2502 // x is finite, so if y is positive infinity, then x is less, return 1
2503 // if y is negative infinity, then x is greater, return 0
2505 res = ((y & MASK_SIGN) != MASK_SIGN);
2506 BID_RETURN (res);
2509 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2510 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2511 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2512 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2513 if (sig_x > 9999999999999999ull) {
2514 non_canon_x = 1;
2515 } else {
2516 non_canon_x = 0;
2518 } else {
2519 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2520 sig_x = (x & MASK_BINARY_SIG1);
2521 non_canon_x = 0;
2524 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2525 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2526 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2527 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2528 if (sig_y > 9999999999999999ull) {
2529 non_canon_y = 1;
2530 } else {
2531 non_canon_y = 0;
2533 } else {
2534 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2535 sig_y = (y & MASK_BINARY_SIG1);
2536 non_canon_y = 0;
2539 // ZERO (CASE4)
2540 // some properties:
2541 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2542 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2543 // therefore ignore the exponent field
2544 // (Any non-canonical # is considered 0)
2545 if (non_canon_x || sig_x == 0) {
2546 x_is_zero = 1;
2548 if (non_canon_y || sig_y == 0) {
2549 y_is_zero = 1;
2551 // if both numbers are zero, they are equal -> return 1
2552 if (x_is_zero && y_is_zero) {
2553 res = 1;
2554 BID_RETURN (res);
2556 // if x is zero, it is lessthan if Y is positive
2557 else if (x_is_zero) {
2558 res = ((y & MASK_SIGN) != MASK_SIGN);
2559 BID_RETURN (res);
2561 // if y is zero, X is less if it is negative
2562 else if (y_is_zero) {
2563 res = ((x & MASK_SIGN) == MASK_SIGN);
2564 BID_RETURN (res);
2566 // OPPOSITE SIGN (CASE5)
2567 // now, if the sign bits differ, x is less than if y is positive
2568 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2569 res = ((y & MASK_SIGN) != MASK_SIGN);
2570 BID_RETURN (res);
2572 // REDUNDANT REPRESENTATIONS (CASE6)
2573 // if both components are either bigger or smaller
2574 if (sig_x > sig_y && exp_x >= exp_y) {
2575 res = ((x & MASK_SIGN) == MASK_SIGN);
2576 BID_RETURN (res);
2578 if (sig_x < sig_y && exp_x <= exp_y) {
2579 res = ((x & MASK_SIGN) != MASK_SIGN);
2580 BID_RETURN (res);
2582 // if exp_x is 15 greater than exp_y, no need for compensation
2583 if (exp_x - exp_y > 15) {
2584 res = ((x & MASK_SIGN) == MASK_SIGN);
2585 BID_RETURN (res);
2587 // difference cannot be greater than 10^15
2589 // if exp_x is 15 less than exp_y, no need for compensation
2590 if (exp_y - exp_x > 15) {
2591 res = ((x & MASK_SIGN) != MASK_SIGN);
2592 BID_RETURN (res);
2594 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2595 if (exp_x > exp_y) { // to simplify the loop below,
2597 // otherwise adjust the x significand upwards
2598 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2599 mult_factor[exp_x - exp_y]);
2601 // return 1 if values are equal
2602 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2603 res = 1;
2604 BID_RETURN (res);
2606 // if postitive, return whichever significand abs is smaller
2607 // (converse if negative)
2609 res = (((sig_n_prime.w[1] == 0)
2610 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2611 MASK_SIGN));
2612 BID_RETURN (res);
2615 // adjust the y significand upwards
2616 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2617 mult_factor[exp_y - exp_x]);
2619 // return 1 if values are equal
2620 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2621 res = 1;
2622 BID_RETURN (res);
2624 // if positive, return whichever significand abs is smaller
2625 // (converse if negative)
2627 res = (((sig_n_prime.w[1] > 0)
2628 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2629 MASK_SIGN));
2630 BID_RETURN (res);
2634 #if DECIMAL_CALL_BY_REFERENCE
2635 void
2636 bid64_signaling_less_unordered (int *pres, UINT64 * px,
2637 UINT64 *
2638 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2639 _EXC_INFO_PARAM) {
2640 UINT64 x = *px;
2641 UINT64 y = *py;
2642 #else
2644 bid64_signaling_less_unordered (UINT64 x,
2645 UINT64 y _EXC_FLAGS_PARAM
2646 _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
2647 #endif
2648 int res;
2649 int exp_x, exp_y;
2650 UINT64 sig_x, sig_y;
2651 UINT128 sig_n_prime;
2652 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2654 // NaN (CASE1)
2655 // if either number is NAN, the comparison is unordered : return 0
2656 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2657 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2658 res = 1;
2659 BID_RETURN (res);
2661 // SIMPLE (CASE2)
2662 // if all the bits are the same, these numbers are equal.
2663 if (x == y) {
2664 res = 0;
2665 BID_RETURN (res);
2667 // INFINITY (CASE3)
2668 if ((x & MASK_INF) == MASK_INF) {
2669 // if x==neg_inf, { res = (y == neg_inf)?0:1; BID_RETURN (res) }
2670 if ((x & MASK_SIGN) == MASK_SIGN)
2671 // x is -inf, so it is less than y unless y is -inf
2673 res = (((y & MASK_INF) != MASK_INF)
2674 || (y & MASK_SIGN) != MASK_SIGN);
2675 BID_RETURN (res);
2676 } else
2677 // x is pos_inf, no way for it to be less than y
2679 res = 0;
2680 BID_RETURN (res);
2682 } else if ((y & MASK_INF) == MASK_INF) {
2683 // x is finite, so:
2684 // if y is +inf, x<y
2685 // if y is -inf, x>y
2687 res = ((y & MASK_SIGN) != MASK_SIGN);
2688 BID_RETURN (res);
2691 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2692 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2693 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2694 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2695 if (sig_x > 9999999999999999ull) {
2696 non_canon_x = 1;
2697 } else {
2698 non_canon_x = 0;
2700 } else {
2701 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2702 sig_x = (x & MASK_BINARY_SIG1);
2703 non_canon_x = 0;
2706 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2707 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2708 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2709 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2710 if (sig_y > 9999999999999999ull) {
2711 non_canon_y = 1;
2712 } else {
2713 non_canon_y = 0;
2715 } else {
2716 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2717 sig_y = (y & MASK_BINARY_SIG1);
2718 non_canon_y = 0;
2721 // ZERO (CASE4)
2722 // some properties:
2723 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2724 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2725 // therefore ignore the exponent field
2726 // (Any non-canonical # is considered 0)
2727 if (non_canon_x || sig_x == 0) {
2728 x_is_zero = 1;
2730 if (non_canon_y || sig_y == 0) {
2731 y_is_zero = 1;
2733 // if both numbers are zero, they are equal
2734 if (x_is_zero && y_is_zero) {
2735 res = 0;
2736 BID_RETURN (res);
2738 // if x is zero, it is lessthan if Y is positive
2739 else if (x_is_zero) {
2740 res = ((y & MASK_SIGN) != MASK_SIGN);
2741 BID_RETURN (res);
2743 // if y is zero, X is less if it is negative
2744 else if (y_is_zero) {
2745 res = ((x & MASK_SIGN) == MASK_SIGN);
2746 BID_RETURN (res);
2748 // OPPOSITE SIGN (CASE5)
2749 // now, if the sign bits differ, x is less than if y is positive
2750 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2751 res = ((y & MASK_SIGN) != MASK_SIGN);
2752 BID_RETURN (res);
2754 // REDUNDANT REPRESENTATIONS (CASE6)
2755 // if both components are either bigger or smaller
2756 if (sig_x > sig_y && exp_x >= exp_y) {
2757 res = ((x & MASK_SIGN) == MASK_SIGN);
2758 BID_RETURN (res);
2760 if (sig_x < sig_y && exp_x <= exp_y) {
2761 res = ((x & MASK_SIGN) != MASK_SIGN);
2762 BID_RETURN (res);
2764 // if exp_x is 15 greater than exp_y, no need for compensation
2765 if (exp_x - exp_y > 15) {
2766 res = ((x & MASK_SIGN) == MASK_SIGN);
2767 BID_RETURN (res);
2769 // difference cannot be greater than 10^15
2771 // if exp_x is 15 less than exp_y, no need for compensation
2772 if (exp_y - exp_x > 15) {
2773 res = ((x & MASK_SIGN) != MASK_SIGN);
2774 BID_RETURN (res);
2776 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2777 if (exp_x > exp_y) { // to simplify the loop below,
2779 // otherwise adjust the x significand upwards
2780 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2781 mult_factor[exp_x - exp_y]);
2783 // return 0 if values are equal
2784 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2785 res = 0;
2786 BID_RETURN (res);
2788 // if postitive, return whichever significand abs is smaller
2789 // (converse if negative)
2791 res = (((sig_n_prime.w[1] == 0)
2792 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2793 MASK_SIGN));
2794 BID_RETURN (res);
2797 // adjust the y significand upwards
2798 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2799 mult_factor[exp_y - exp_x]);
2801 // return 0 if values are equal
2802 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2803 res = 0;
2804 BID_RETURN (res);
2806 // if positive, return whichever significand abs is smaller
2807 // (converse if negative)
2809 res = (((sig_n_prime.w[1] > 0)
2810 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2811 MASK_SIGN));
2812 BID_RETURN (res);
2816 #if DECIMAL_CALL_BY_REFERENCE
2817 void
2818 bid64_signaling_not_greater (int *pres, UINT64 * px,
2819 UINT64 *
2820 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2821 _EXC_INFO_PARAM) {
2822 UINT64 x = *px;
2823 UINT64 y = *py;
2824 #else
2826 bid64_signaling_not_greater (UINT64 x,
2827 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
2828 _EXC_INFO_PARAM) {
2829 #endif
2830 int res;
2831 int exp_x, exp_y;
2832 UINT64 sig_x, sig_y;
2833 UINT128 sig_n_prime;
2834 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
2836 // NaN (CASE1)
2837 // if either number is NAN, the comparison is unordered,
2838 // rather than equal : return 0
2839 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
2840 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
2841 res = 1;
2842 BID_RETURN (res);
2844 // SIMPLE (CASE2)
2845 // if all the bits are the same, these numbers are equal (LESSEQUAL).
2846 if (x == y) {
2847 res = 1;
2848 BID_RETURN (res);
2850 // INFINITY (CASE3)
2851 if ((x & MASK_INF) == MASK_INF) {
2852 // if x is neg infinity, it must be lessthan or equal to y return 1
2853 if (((x & MASK_SIGN) == MASK_SIGN)) {
2854 res = 1;
2855 BID_RETURN (res);
2857 // x is pos infinity, it is greater,
2858 // unless y is positive infinity => return y==pos_infinity
2859 else {
2860 res = !(((y & MASK_INF) != MASK_INF)
2861 || ((y & MASK_SIGN) == MASK_SIGN));
2862 BID_RETURN (res);
2864 } else if ((y & MASK_INF) == MASK_INF) {
2865 // x is finite, so if y is positive infinity, then x is less, return 1
2866 // if y is negative infinity, then x is greater, return 0
2868 res = ((y & MASK_SIGN) != MASK_SIGN);
2869 BID_RETURN (res);
2872 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2873 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2874 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
2875 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2876 if (sig_x > 9999999999999999ull) {
2877 non_canon_x = 1;
2878 } else {
2879 non_canon_x = 0;
2881 } else {
2882 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
2883 sig_x = (x & MASK_BINARY_SIG1);
2884 non_canon_x = 0;
2887 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
2888 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
2889 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
2890 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
2891 if (sig_y > 9999999999999999ull) {
2892 non_canon_y = 1;
2893 } else {
2894 non_canon_y = 0;
2896 } else {
2897 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
2898 sig_y = (y & MASK_BINARY_SIG1);
2899 non_canon_y = 0;
2902 // ZERO (CASE4)
2903 // some properties:
2904 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
2905 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
2906 // therefore ignore the exponent field
2907 // (Any non-canonical # is considered 0)
2908 if (non_canon_x || sig_x == 0) {
2909 x_is_zero = 1;
2911 if (non_canon_y || sig_y == 0) {
2912 y_is_zero = 1;
2914 // if both numbers are zero, they are equal -> return 1
2915 if (x_is_zero && y_is_zero) {
2916 res = 1;
2917 BID_RETURN (res);
2919 // if x is zero, it is lessthan if Y is positive
2920 else if (x_is_zero) {
2921 res = ((y & MASK_SIGN) != MASK_SIGN);
2922 BID_RETURN (res);
2924 // if y is zero, X is less if it is negative
2925 else if (y_is_zero) {
2926 res = ((x & MASK_SIGN) == MASK_SIGN);
2927 BID_RETURN (res);
2929 // OPPOSITE SIGN (CASE5)
2930 // now, if the sign bits differ, x is less than if y is positive
2931 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
2932 res = ((y & MASK_SIGN) != MASK_SIGN);
2933 BID_RETURN (res);
2935 // REDUNDANT REPRESENTATIONS (CASE6)
2936 // if both components are either bigger or smaller
2937 if (sig_x > sig_y && exp_x >= exp_y) {
2938 res = ((x & MASK_SIGN) == MASK_SIGN);
2939 BID_RETURN (res);
2941 if (sig_x < sig_y && exp_x <= exp_y) {
2942 res = ((x & MASK_SIGN) != MASK_SIGN);
2943 BID_RETURN (res);
2945 // if exp_x is 15 greater than exp_y, no need for compensation
2946 if (exp_x - exp_y > 15) {
2947 res = ((x & MASK_SIGN) == MASK_SIGN);
2948 BID_RETURN (res);
2950 // difference cannot be greater than 10^15
2952 // if exp_x is 15 less than exp_y, no need for compensation
2953 if (exp_y - exp_x > 15) {
2954 res = ((x & MASK_SIGN) != MASK_SIGN);
2955 BID_RETURN (res);
2957 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
2958 if (exp_x > exp_y) { // to simplify the loop below,
2960 // otherwise adjust the x significand upwards
2961 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
2962 mult_factor[exp_x - exp_y]);
2964 // return 1 if values are equal
2965 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
2966 res = 1;
2967 BID_RETURN (res);
2969 // if postitive, return whichever significand abs is smaller
2970 // (converse if negative)
2972 res = (((sig_n_prime.w[1] == 0)
2973 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
2974 MASK_SIGN));
2975 BID_RETURN (res);
2978 // adjust the y significand upwards
2979 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
2980 mult_factor[exp_y - exp_x]);
2982 // return 1 if values are equal
2983 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
2984 res = 1;
2985 BID_RETURN (res);
2987 // if positive, return whichever significand abs is smaller
2988 // (converse if negative)
2990 res = (((sig_n_prime.w[1] > 0)
2991 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
2992 MASK_SIGN));
2993 BID_RETURN (res);
2997 #if DECIMAL_CALL_BY_REFERENCE
2998 void
2999 bid64_signaling_not_less (int *pres, UINT64 * px,
3000 UINT64 *
3001 py _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3002 _EXC_INFO_PARAM) {
3003 UINT64 x = *px;
3004 UINT64 y = *py;
3005 #else
3007 bid64_signaling_not_less (UINT64 x,
3008 UINT64 y _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
3009 _EXC_INFO_PARAM) {
3010 #endif
3011 int res;
3012 int exp_x, exp_y;
3013 UINT64 sig_x, sig_y;
3014 UINT128 sig_n_prime;
3015 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
3017 // NaN (CASE1)
3018 // if either number is NAN, the comparison is unordered : return 1
3019 if (((x & MASK_NAN) == MASK_NAN) || ((y & MASK_NAN) == MASK_NAN)) {
3020 *pfpsf |= INVALID_EXCEPTION; // set invalid exception if NaN
3021 res = 1;
3022 BID_RETURN (res);
3024 // SIMPLE (CASE2)
3025 // if all the bits are the same, these numbers are equal.
3026 if (x == y) {
3027 res = 1;
3028 BID_RETURN (res);
3030 // INFINITY (CASE3)
3031 if ((x & MASK_INF) == MASK_INF) {
3032 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
3033 if ((x & MASK_SIGN) == MASK_SIGN)
3034 // x is -inf, so it is less than y unless y is -inf
3036 res = (((y & MASK_INF) == MASK_INF)
3037 && (y & MASK_SIGN) == MASK_SIGN);
3038 BID_RETURN (res);
3039 } else
3040 // x is pos_inf, no way for it to be less than y
3042 res = 1;
3043 BID_RETURN (res);
3045 } else if ((y & MASK_INF) == MASK_INF) {
3046 // x is finite, so:
3047 // if y is +inf, x<y
3048 // if y is -inf, x>y
3050 res = ((y & MASK_SIGN) == MASK_SIGN);
3051 BID_RETURN (res);
3054 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3055 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
3056 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
3057 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
3058 if (sig_x > 9999999999999999ull) {
3059 non_canon_x = 1;
3060 } else {
3061 non_canon_x = 0;
3063 } else {
3064 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
3065 sig_x = (x & MASK_BINARY_SIG1);
3066 non_canon_x = 0;
3069 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
3070 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
3071 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
3072 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
3073 if (sig_y > 9999999999999999ull) {
3074 non_canon_y = 1;
3075 } else {
3076 non_canon_y = 0;
3078 } else {
3079 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
3080 sig_y = (y & MASK_BINARY_SIG1);
3081 non_canon_y = 0;
3084 // ZERO (CASE4)
3085 // some properties:
3086 // (+ZERO==-ZERO) => therefore ignore the sign, and neither number is greater
3087 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B =>
3088 // therefore ignore the exponent field
3089 // (Any non-canonical # is considered 0)
3090 if (non_canon_x || sig_x == 0) {
3091 x_is_zero = 1;
3093 if (non_canon_y || sig_y == 0) {
3094 y_is_zero = 1;
3096 // if both numbers are zero, they are equal
3097 if (x_is_zero && y_is_zero) {
3098 res = 1;
3099 BID_RETURN (res);
3101 // if x is zero, it is lessthan if Y is positive
3102 else if (x_is_zero) {
3103 res = ((y & MASK_SIGN) == MASK_SIGN);
3104 BID_RETURN (res);
3106 // if y is zero, X is less if it is negative
3107 else if (y_is_zero) {
3108 res = ((x & MASK_SIGN) != MASK_SIGN);
3109 BID_RETURN (res);
3111 // OPPOSITE SIGN (CASE5)
3112 // now, if the sign bits differ, x is less than if y is positive
3113 if (((x ^ y) & MASK_SIGN) == MASK_SIGN) {
3114 res = ((y & MASK_SIGN) == MASK_SIGN);
3115 BID_RETURN (res);
3117 // REDUNDANT REPRESENTATIONS (CASE6)
3118 // if both components are either bigger or smaller
3119 if (sig_x > sig_y && exp_x >= exp_y) {
3120 res = ((x & MASK_SIGN) != MASK_SIGN);
3121 BID_RETURN (res);
3123 if (sig_x < sig_y && exp_x <= exp_y) {
3124 res = ((x & MASK_SIGN) == MASK_SIGN);
3125 BID_RETURN (res);
3127 // if exp_x is 15 greater than exp_y, no need for compensation
3128 if (exp_x - exp_y > 15) {
3129 res = ((x & MASK_SIGN) != MASK_SIGN);
3130 BID_RETURN (res);
3132 // difference cannot be greater than 10^15
3134 // if exp_x is 15 less than exp_y, no need for compensation
3135 if (exp_y - exp_x > 15) {
3136 res = ((x & MASK_SIGN) == MASK_SIGN);
3137 BID_RETURN (res);
3139 // if |exp_x - exp_y| < 15, it comes down to the compensated significand
3140 if (exp_x > exp_y) { // to simplify the loop below,
3142 // otherwise adjust the x significand upwards
3143 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
3144 mult_factor[exp_x - exp_y]);
3146 // return 0 if values are equal
3147 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
3148 res = 1;
3149 BID_RETURN (res);
3151 // if postitive, return whichever significand abs is smaller
3152 // (converse if negative)
3154 res = (((sig_n_prime.w[1] == 0)
3155 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) !=
3156 MASK_SIGN));
3157 BID_RETURN (res);
3160 // adjust the y significand upwards
3161 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
3162 mult_factor[exp_y - exp_x]);
3164 // return 0 if values are equal
3165 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
3166 res = 1;
3167 BID_RETURN (res);
3169 // if positive, return whichever significand abs is smaller
3170 // (converse if negative)
3172 res = (((sig_n_prime.w[1] > 0)
3173 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) !=
3174 MASK_SIGN));
3175 BID_RETURN (res);