]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/libbid/bid128_compare.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / libbid / bid128_compare.c
CommitLineData
8d9254fc 1/* Copyright (C) 2007-2020 Free Software Foundation, Inc.
200359e8
L
2
3This file is part of GCC.
4
5GCC is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
748086b7 7Software Foundation; either version 3, or (at your option) any later
200359e8
L
8version.
9
200359e8
L
10GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13for more details.
14
748086b7
JJ
15Under Section 7 of GPL version 3, you are granted additional
16permissions described in the GCC Runtime Library Exception, version
173.1, as published by the Free Software Foundation.
18
19You should have received a copy of the GNU General Public License and
20a copy of the GCC Runtime Library Exception along with this program;
21see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22<http://www.gnu.org/licenses/>. */
200359e8
L
23
24#include "bid_internal.h"
25
b2a00c89 26BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_equal, x, y)
200359e8 27
b2a00c89
L
28 int res;
29 int exp_x, exp_y, exp_t;
30 UINT128 sig_x, sig_y, sig_t;
31 UINT192 sig_n_prime192;
32 UINT256 sig_n_prime256;
33 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
34
35 // NaN (CASE1)
36 // if either number is NAN, the comparison is unordered,
37 // rather than equal : return 0
b2a00c89
L
38if (((x.w[1] & MASK_NAN) == MASK_NAN)
39 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
40if ((x.w[1] & MASK_SNAN) == MASK_SNAN
41 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
42 *pfpsf |= INVALID_EXCEPTION;
43}
44{
45 res = 0;
46 BID_RETURN (res);
47}
48}
200359e8
L
49 // SIMPLE (CASE2)
50 // if all the bits are the same, these numbers are equivalent.
b2a00c89
L
51if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
52 res = 1;
53 BID_RETURN (res);
54}
200359e8 55 // INFINITY (CASE3)
b2a00c89 56if ((x.w[1] & MASK_INF) == MASK_INF) {
200359e8 57 if ((y.w[1] & MASK_INF) == MASK_INF) {
b2a00c89
L
58 res = (((x.w[1] ^ y.w[1]) & MASK_SIGN) != MASK_SIGN);
59 BID_RETURN (res);
60 } else {
200359e8
L
61 res = 0;
62 BID_RETURN (res);
63 }
b2a00c89
L
64}
65if ((y.w[1] & MASK_INF) == MASK_INF) {
66 res = 0;
67 BID_RETURN (res);
68}
200359e8 69 // CONVERT X
b2a00c89
L
70sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
71sig_x.w[0] = x.w[0];
72exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
73
74 // CHECK IF X IS CANONICAL
75 // 9999999999999999999999999999999999(decimal) =
76 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
77 // [0, 10^34) is the 754r supported canonical range.
78 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
79if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
80 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
81 && (sig_x.w[0] > 0x378d8e63ffffffffull))
82 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
83 non_canon_x = 1;
84else
85 non_canon_x = 0;
200359e8
L
86
87 // CONVERT Y
b2a00c89
L
88exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
89sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
90sig_y.w[0] = y.w[0];
200359e8
L
91
92 // CHECK IF Y IS CANONICAL
93 // 9999999999999999999999999999999999(decimal) =
94 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
95 // [0, 10^34) is the 754r supported canonical range.
96 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
97if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
98 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
99 && (sig_y.w[0] > 0x378d8e63ffffffffull))
100 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
101 non_canon_y = 1;
102else
103 non_canon_y = 0;
200359e8
L
104
105 // some properties:
106 // (+ZERO == -ZERO) => therefore ignore the sign
107 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
108 // ignore the exponent field
109 // (Any non-canonical # is considered 0)
b2a00c89
L
110if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
111 x_is_zero = 1;
112}
113if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
114 y_is_zero = 1;
115}
200359e8 116
b2a00c89
L
117if (x_is_zero && y_is_zero) {
118 res = 1;
119 BID_RETURN (res);
120} else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
121 res = 0;
122 BID_RETURN (res);
123}
200359e8
L
124 // OPPOSITE SIGN (CASE5)
125 // now, if the sign bits differ => not equal : return 0
b2a00c89
L
126if ((x.w[1] ^ y.w[1]) & MASK_SIGN) {
127 res = 0;
128 BID_RETURN (res);
129}
200359e8 130 // REDUNDANT REPRESENTATIONS (CASE6)
b2a00c89
L
131if (exp_x > exp_y) { // to simplify the loop below,
132 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
133 SWAP (sig_x.w[1], sig_y.w[1], sig_t.w[1]); // and the smaller exp in x
134 SWAP (sig_x.w[0], sig_y.w[0], sig_t.w[0]); // and the smaller exp in x
135}
200359e8 136
200359e8 137
b2a00c89
L
138if (exp_y - exp_x > 33) {
139 res = 0;
140 BID_RETURN (res);
141} // difference cannot be greater than 10^33
200359e8 142
b2a00c89 143if (exp_y - exp_x > 19) {
200359e8 144 // recalculate y's significand upwards
b2a00c89
L
145 __mul_128x128_to_256 (sig_n_prime256, sig_y,
146 ten2k128[exp_y - exp_x - 20]);
200359e8 147 {
b2a00c89
L
148 res = ((sig_n_prime256.w[3] == 0) && (sig_n_prime256.w[2] == 0)
149 && (sig_n_prime256.w[1] == sig_x.w[1])
150 && (sig_n_prime256.w[0] == sig_x.w[0]));
200359e8
L
151 BID_RETURN (res);
152 }
b2a00c89
L
153
154}
155 //else{
156 // recalculate y's significand upwards
157__mul_64x128_to_192 (sig_n_prime192, ten2k64[exp_y - exp_x], sig_y);
158{
159 res = ((sig_n_prime192.w[2] == 0)
160 && (sig_n_prime192.w[1] == sig_x.w[1])
161 && (sig_n_prime192.w[0] == sig_x.w[0]));
162 BID_RETURN (res);
163}
200359e8
L
164}
165
b2a00c89
L
166BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_greater, x,
167 y)
200359e8 168
b2a00c89
L
169 int res;
170 int exp_x, exp_y;
171 int diff;
172 UINT128 sig_x, sig_y;
173 UINT192 sig_n_prime192;
174 UINT256 sig_n_prime256;
175 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
176
177 // NaN (CASE1)
178 // if either number is NAN, the comparison is unordered, rather than
179 // equal : return 0
b2a00c89
L
180if (((x.w[1] & MASK_NAN) == MASK_NAN)
181 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
182if ((x.w[1] & MASK_SNAN) == MASK_SNAN
183 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
184 *pfpsf |= INVALID_EXCEPTION;
185}
186{
187 res = 0;
188 BID_RETURN (res);
189}
190}
200359e8
L
191 // SIMPLE (CASE2)
192 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
193if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
194 res = 0;
195 BID_RETURN (res);
196}
197 // INFINITY (CASE3)
198if ((x.w[1] & MASK_INF) == MASK_INF) {
199 // if x is neg infinity, there is no way it is greater than y, return 0
200 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
201 res = 0;
202 BID_RETURN (res);
203 }
b2a00c89
L
204 // x is pos infinity, it is greater, unless y is positive infinity =>
205 // return y!=pos_infinity
206 else {
207 res = (((y.w[1] & MASK_INF) != MASK_INF)
208 || ((y.w[1] & MASK_SIGN) == MASK_SIGN));
209 BID_RETURN (res);
200359e8 210 }
b2a00c89
L
211} else if ((y.w[1] & MASK_INF) == MASK_INF) {
212 // x is finite, so if y is positive infinity, then x is less, return 0
213 // if y is negative infinity, then x is greater, return 1
214 {
215 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
216 BID_RETURN (res);
217 }
218}
200359e8 219 // CONVERT X
b2a00c89
L
220sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
221sig_x.w[0] = x.w[0];
222exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
223
224 // CHECK IF X IS CANONICAL
225 // 9999999999999999999999999999999999(decimal) =
226 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
227 // [0, 10^34) is the 754r supported canonical range.
228 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
229if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
230 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
231 && (sig_x.w[0] > 0x378d8e63ffffffffull))
232 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
233 non_canon_x = 1;
234else
235 non_canon_x = 0;
200359e8
L
236
237 // CONVERT Y
b2a00c89
L
238exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
239sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
240sig_y.w[0] = y.w[0];
200359e8
L
241
242 // CHECK IF Y IS CANONICAL
243 // 9999999999999999999999999999999999(decimal) =
244 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
245 // [0, 10^34) is the 754r supported canonical range.
246 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
247if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
248 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
249 && (sig_y.w[0] > 0x378d8e63ffffffffull))
250 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
251 non_canon_y = 1;
252else
253 non_canon_y = 0;
200359e8
L
254
255 // ZERO (CASE4)
256 // some properties:
257 // (+ZERO == -ZERO) => therefore ignore the sign
258 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
259 // ignore the exponent field
260 // (Any non-canonical # is considered 0)
b2a00c89
L
261if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
262 x_is_zero = 1;
263}
264if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
265 y_is_zero = 1;
266}
200359e8 267 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
268if (x_is_zero && y_is_zero) {
269 res = 0;
270 BID_RETURN (res);
271}
200359e8 272 // is x is zero, it is greater if Y is negative
b2a00c89
L
273else if (x_is_zero) {
274 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
275 BID_RETURN (res);
276}
200359e8 277 // is y is zero, X is greater if it is positive
b2a00c89
L
278else if (y_is_zero) {
279 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
280 BID_RETURN (res);
281}
200359e8
L
282 // OPPOSITE SIGN (CASE5)
283 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
284if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
285 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
286 BID_RETURN (res);
287}
200359e8
L
288 // REDUNDANT REPRESENTATIONS (CASE6)
289 // if exponents are the same, then we have a simple comparison
290 // of the significands
b2a00c89
L
291if (exp_y == exp_x) {
292 res = (((sig_x.w[1] > sig_y.w[1])
293 || (sig_x.w[1] == sig_y.w[1]
294 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
295 MASK_SIGN));
296 BID_RETURN (res);
297}
200359e8
L
298 // if both components are either bigger or smaller,
299 // it is clear what needs to be done
b2a00c89
L
300if ((sig_x.w[1] > sig_y.w[1]
301 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
302 && exp_x >= exp_y) {
303 {
304 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
305 BID_RETURN (res);
200359e8 306 }
b2a00c89
L
307}
308if ((sig_x.w[1] < sig_y.w[1]
309 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
310 && exp_x <= exp_y) {
311 {
312 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
313 BID_RETURN (res);
200359e8 314 }
b2a00c89 315}
200359e8 316
b2a00c89 317diff = exp_x - exp_y;
200359e8
L
318
319 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 320if (diff > 0) { // to simplify the loop below,
200359e8 321
b2a00c89
L
322 // if exp_x is 33 greater than exp_y, no need for compensation
323 if (diff > 33) {
324 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
325 BID_RETURN (res);
326 } // difference cannot be greater than 10^33
200359e8 327
b2a00c89
L
328 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
329 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8
L
330
331 // if postitive, return whichever significand is larger
332 // (converse if negative)
b2a00c89
L
333 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
334 && sig_n_prime256.w[1] == sig_y.w[1]
335 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
336 res = 0;
337 BID_RETURN (res);
b2a00c89 338 } // if equal, return 0
200359e8 339 {
b2a00c89
L
340 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
341 || (sig_n_prime256.w[1] > sig_y.w[1])
342 || (sig_n_prime256.w[1] == sig_y.w[1]
343 && sig_n_prime256.w[0] >
344 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
345 BID_RETURN (res);
346 }
347 }
b2a00c89
L
348 //else { //128 by 64 bit multiply -> 192 bits
349 __mul_64x128_to_192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 350
b2a00c89
L
351 // if postitive, return whichever significand is larger
352 // (converse if negative)
353 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
354 && (sig_n_prime192.w[0] == sig_y.w[0])) {
355 res = 0;
356 BID_RETURN (res);
357 } // if equal, return 0
358 {
359 res = (((sig_n_prime192.w[2] > 0) ||
360 (sig_n_prime192.w[1] > sig_y.w[1]) ||
361 (sig_n_prime192.w[1] == sig_y.w[1] &&
362 sig_n_prime192.w[0] > sig_y.w[0])) ^
363 ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
364 BID_RETURN (res);
365 }
b2a00c89 366}
200359e8 367
b2a00c89 368diff = exp_y - exp_x;
200359e8 369
b2a00c89
L
370 // if exp_x is 33 less than exp_y, no need for compensation
371if (diff > 33) {
372 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
373 BID_RETURN (res);
374}
375
376if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 377 // adjust the y significand upwards
b2a00c89 378 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8
L
379
380 // if postitive, return whichever significand is larger
381 // (converse if negative)
b2a00c89
L
382 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
383 && sig_n_prime256.w[1] == sig_x.w[1]
384 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
385 res = 0;
386 BID_RETURN (res);
b2a00c89 387 } // if equal, return 0
200359e8 388 {
b2a00c89
L
389 res = ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0 ||
390 (sig_n_prime256.w[1] > sig_x.w[1] ||
391 (sig_n_prime256.w[1] == sig_x.w[1] &&
392 sig_n_prime256.w[0] > sig_x.w[0]))) ^
393 ((x.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
394 BID_RETURN (res);
395 }
b2a00c89
L
396}
397 //else { //128 by 64 bit multiply -> 192 bits
398 // adjust the y significand upwards
399__mul_64x128_to_192 (sig_n_prime192, ten2k64[diff], sig_y);
400
401 // if postitive, return whichever significand is larger
402 // (converse if negative)
403if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
404 && (sig_n_prime192.w[0] == sig_x.w[0])) {
405 res = 0;
406 BID_RETURN (res);
407} // if equal, return 0
408{
409 res = (sig_n_prime192.w[2] != 0
410 || (sig_n_prime192.w[1] > sig_x.w[1]
411 || (sig_n_prime192.w[1] == sig_x.w[1]
412 && sig_n_prime192.w[0] >
413 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN);
414 BID_RETURN (res);
415}
200359e8
L
416}
417
b2a00c89
L
418BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
419 bid128_quiet_greater_equal, x,
420 y)
200359e8 421
b2a00c89
L
422 int res;
423 int exp_x, exp_y;
424 int diff;
425 UINT128 sig_x, sig_y;
426 UINT192 sig_n_prime192;
427 UINT256 sig_n_prime256;
428 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
429
430 // NaN (CASE1)
431 // if either number is NAN, the comparison is unordered,
432 // rather than equal : return 1
b2a00c89
L
433if (((x.w[1] & MASK_NAN) == MASK_NAN)
434 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
435if ((x.w[1] & MASK_SNAN) == MASK_SNAN
436 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
437 *pfpsf |= INVALID_EXCEPTION;
438}
439{
440 res = 0;
441 BID_RETURN (res);
442}
443}
200359e8
L
444 // SIMPLE (CASE2)
445 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
446if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
447 res = 1;
448 BID_RETURN (res);
449}
450 // INFINITY (CASE3)
451if ((x.w[1] & MASK_INF) == MASK_INF) {
452 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
453 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
454 // x is -inf, so it is less than y unless y is -inf
455 {
456 res = (((y.w[1] & MASK_INF) == MASK_INF)
457 && (y.w[1] & MASK_SIGN) == MASK_SIGN);
458 BID_RETURN (res);
459 } else
460 // x is pos_inf, no way for it to be less than y
461 {
200359e8
L
462 res = 1;
463 BID_RETURN (res);
464 }
b2a00c89
L
465} else if ((y.w[1] & MASK_INF) == MASK_INF) {
466 // x is finite, so if y is positive infinity, then x is less, return 0
467 // if y is negative infinity, then x is greater, return 1
468 {
469 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
470 BID_RETURN (res);
200359e8 471 }
b2a00c89 472}
200359e8 473 // CONVERT X
b2a00c89
L
474sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
475sig_x.w[0] = x.w[0];
476exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
477
478 // CHECK IF X IS CANONICAL
479 // 9999999999999999999999999999999999(decimal) =
480 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
481 // [0, 10^34) is the 754r supported canonical range.
482 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
483if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
484 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
485 && (sig_x.w[0] > 0x378d8e63ffffffffull))
486 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
487 non_canon_x = 1;
488else
489 non_canon_x = 0;
200359e8
L
490
491 // CONVERT Y
b2a00c89
L
492exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
493sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
494sig_y.w[0] = y.w[0];
200359e8
L
495
496 // CHECK IF Y IS CANONICAL
497 // 9999999999999999999999999999999999(decimal) =
498 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
499 // [0, 10^34) is the 754r supported canonical range.
500 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
501if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
502 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
503 && (sig_y.w[0] > 0x378d8e63ffffffffull))
504 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
505 non_canon_y = 1;
506else
507 non_canon_y = 0;
200359e8
L
508
509 // ZERO (CASE4)
510 // some properties:
511 // (+ZERO == -ZERO) => therefore ignore the sign
512 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
513 // ignore the exponent field
514 // (Any non-canonical # is considered 0)
b2a00c89
L
515if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
516 x_is_zero = 1;
517}
518if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
519 y_is_zero = 1;
520}
200359e8 521 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
522if (x_is_zero && y_is_zero) {
523 res = 1;
524 BID_RETURN (res);
525}
200359e8 526 // is x is zero, it is greater if Y is negative
b2a00c89
L
527else if (x_is_zero) {
528 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
529 BID_RETURN (res);
530}
200359e8 531 // is y is zero, X is greater if it is positive
b2a00c89
L
532else if (y_is_zero) {
533 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
534 BID_RETURN (res);
535}
200359e8
L
536 // OPPOSITE SIGN (CASE5)
537 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
538if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
539 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
540 BID_RETURN (res);
541}
200359e8
L
542 // REDUNDANT REPRESENTATIONS (CASE6)
543 // if exponents are the same, then we have a simple comparison of the
544 // significands
b2a00c89
L
545if (exp_y == exp_x) {
546 res = (((sig_x.w[1] > sig_y.w[1])
547 || (sig_x.w[1] == sig_y.w[1]
548 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
549 MASK_SIGN));
550 BID_RETURN (res);
551}
200359e8
L
552 // if both components are either bigger or smaller,
553 // it is clear what needs to be done
b2a00c89
L
554if (sig_x.w[1] >= sig_y.w[1] && sig_x.w[0] >= sig_y.w[0]
555 && exp_x > exp_y) {
556 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
557 BID_RETURN (res);
558}
559if (sig_x.w[1] <= sig_y.w[1] && sig_x.w[0] <= sig_y.w[0]
560 && exp_x < exp_y) {
561 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
562 BID_RETURN (res);
563}
200359e8 564
b2a00c89 565diff = exp_x - exp_y;
200359e8
L
566
567 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 568if (diff > 0) { // to simplify the loop below,
200359e8 569
b2a00c89
L
570 // if exp_x is 33 greater than exp_y, no need for compensation
571 if (diff > 33) {
572 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
573 BID_RETURN (res);
574 } // difference cannot be greater than 10^33
200359e8 575
b2a00c89
L
576 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
577 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 578
200359e8
L
579
580 // if postitive, return whichever significand is larger
581 // (converse if negative)
b2a00c89
L
582 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
583 && sig_n_prime256.w[1] == sig_y.w[1]
584 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
585 res = 1;
586 BID_RETURN (res);
b2a00c89 587 } // if equal, return 1
200359e8 588 {
b2a00c89
L
589 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
590 || (sig_n_prime256.w[1] > sig_y.w[1])
591 || (sig_n_prime256.w[1] == sig_y.w[1]
592 && sig_n_prime256.w[0] >
593 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
594 BID_RETURN (res);
595 }
596 }
b2a00c89
L
597 //else { //128 by 64 bit multiply -> 192 bits
598 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 599
b2a00c89
L
600 // if postitive, return whichever significand is larger
601 // (converse if negative)
602 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
603 && (sig_n_prime192.w[0] == sig_y.w[0])) {
604 res = 1;
605 BID_RETURN (res);
606 } // if equal, return 1
607 {
608 res = (((sig_n_prime192.w[2] > 0)
609 || (sig_n_prime192.w[1] > sig_y.w[1])
610 || (sig_n_prime192.w[1] == sig_y.w[1]
611 && sig_n_prime192.w[0] >
612 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
613 BID_RETURN (res);
614 }
b2a00c89 615}
200359e8 616
b2a00c89 617diff = exp_y - exp_x;
200359e8 618
b2a00c89
L
619 // if exp_x is 33 less than exp_y, no need for compensation
620if (diff > 33) {
621 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
622 BID_RETURN (res);
623}
200359e8 624
b2a00c89 625if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 626 // adjust the y significand upwards
b2a00c89
L
627 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
628
200359e8
L
629
630 // if postitive, return whichever significand is larger
631 // (converse if negative)
b2a00c89
L
632 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
633 && sig_n_prime256.w[1] == sig_x.w[1]
634 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
635 res = 1;
636 BID_RETURN (res);
b2a00c89 637 } // if equal, return 1
200359e8 638 {
b2a00c89
L
639 res = ((sig_n_prime256.w[3] == 0 && sig_n_prime256.w[2] == 0
640 && (sig_n_prime256.w[1] < sig_x.w[1]
641 || (sig_n_prime256.w[1] == sig_x.w[1]
642 && sig_n_prime256.w[0] <
643 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) ==
644 MASK_SIGN));
200359e8
L
645 BID_RETURN (res);
646 }
b2a00c89
L
647}
648 //else { //128 by 64 bit multiply -> 192 bits
649 // adjust the y significand upwards
650__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
651
652 // if postitive, return whichever significand is larger
653 // (converse if negative)
654if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
655 && (sig_n_prime192.w[0] == sig_x.w[0])) {
656 res = 1;
657 BID_RETURN (res);
658} // if equal, return 1
659{
660 res = (sig_n_prime192.w[2] == 0
661 && (sig_n_prime192.w[1] < sig_x.w[1]
662 || (sig_n_prime192.w[1] == sig_x.w[1]
663 && sig_n_prime192.w[0] <
664 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
665 BID_RETURN (res);
666}
200359e8
L
667}
668
b2a00c89
L
669BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
670 bid128_quiet_greater_unordered,
671 x, y)
200359e8 672
b2a00c89
L
673 int res;
674 int exp_x, exp_y;
675 int diff;
676 UINT128 sig_x, sig_y;
677 UINT192 sig_n_prime192;
678 UINT256 sig_n_prime256;
679 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
680
681 // NaN (CASE1)
682 // if either number is NAN, the comparison is unordered,
683 // rather than
684 // equal : return 1
b2a00c89
L
685if (((x.w[1] & MASK_NAN) == MASK_NAN)
686 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
687if ((x.w[1] & MASK_SNAN) == MASK_SNAN
688 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
689 *pfpsf |= INVALID_EXCEPTION;
690}
691{
692 res = 1;
693 BID_RETURN (res);
694}
695}
200359e8
L
696 // SIMPLE (CASE2)
697 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
698if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
699 res = 0;
700 BID_RETURN (res);
701}
702 // INFINITY (CASE3)
703if ((x.w[1] & MASK_INF) == MASK_INF) {
704 // if x is neg infinity, there is no way it is greater than y, return 0
705 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
706 res = 0;
707 BID_RETURN (res);
708 }
b2a00c89
L
709 // x is pos infinity, it is greater, unless y is positive infinity =>
710 // return y!=pos_infinity
711 else {
712 res = (((y.w[1] & MASK_INF) != MASK_INF)
713 || ((y.w[1] & MASK_SIGN) == MASK_SIGN));
714 BID_RETURN (res);
715 }
716} else if ((y.w[1] & MASK_INF) == MASK_INF) {
717 // x is finite, so if y is positive infinity, then x is less, return 0
718 // if y is negative infinity, then x is greater, return 1
719 {
720 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
721 BID_RETURN (res);
200359e8 722 }
b2a00c89 723}
200359e8 724 // CONVERT X
b2a00c89
L
725sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
726sig_x.w[0] = x.w[0];
727exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
728
729 // CHECK IF X IS CANONICAL
730 // 9999999999999999999999999999999999(decimal) =
731 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
732 // [0, 10^34) is the 754r supported canonical range.
733 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
734if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
735 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
736 && (sig_x.w[0] > 0x378d8e63ffffffffull))
737 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
738 non_canon_x = 1;
739else
740 non_canon_x = 0;
200359e8
L
741
742 // CONVERT Y
b2a00c89
L
743exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
744sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
745sig_y.w[0] = y.w[0];
200359e8
L
746
747 // CHECK IF Y IS CANONICAL
748 // 9999999999999999999999999999999999(decimal) =
749 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
750 // [0, 10^34) is the 754r supported canonical range.
751 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
752if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
753 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
754 && (sig_y.w[0] > 0x378d8e63ffffffffull))
755 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
756 non_canon_y = 1;
757else
758 non_canon_y = 0;
200359e8
L
759
760 // ZERO (CASE4)
761 // some properties:
762 // (+ZERO == -ZERO) => therefore ignore the sign
763 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
764 // ignore the exponent field
765 // (Any non-canonical # is considered 0)
b2a00c89
L
766if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
767 x_is_zero = 1;
768}
769if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
770 y_is_zero = 1;
771}
200359e8 772 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
773if (x_is_zero && y_is_zero) {
774 res = 0;
775 BID_RETURN (res);
776}
200359e8 777 // is x is zero, it is greater if Y is negative
b2a00c89
L
778else if (x_is_zero) {
779 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
780 BID_RETURN (res);
781}
200359e8 782 // is y is zero, X is greater if it is positive
b2a00c89
L
783else if (y_is_zero) {
784 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
785 BID_RETURN (res);
786}
200359e8
L
787 // OPPOSITE SIGN (CASE5)
788 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
789if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
790 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
791 BID_RETURN (res);
792}
200359e8
L
793 // REDUNDANT REPRESENTATIONS (CASE6)
794 // if exponents are the same, then we have a simple comparison of the
795 // significands
b2a00c89
L
796if (exp_y == exp_x) {
797 res = (((sig_x.w[1] > sig_y.w[1])
798 || (sig_x.w[1] == sig_y.w[1]
799 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
800 MASK_SIGN));
801 BID_RETURN (res);
802}
200359e8
L
803 // if both components are either bigger or smaller,
804 // it is clear what needs to be done
b2a00c89
L
805if (sig_x.w[1] >= sig_y.w[1] && sig_x.w[0] >= sig_y.w[0]
806 && exp_x > exp_y) {
807 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
808 BID_RETURN (res);
809}
810if (sig_x.w[1] <= sig_y.w[1] && sig_x.w[0] <= sig_y.w[0]
811 && exp_x < exp_y) {
812 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
813 BID_RETURN (res);
814}
200359e8 815
b2a00c89 816diff = exp_x - exp_y;
200359e8
L
817
818 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 819if (diff > 0) { // to simplify the loop below,
200359e8 820
b2a00c89
L
821 // if exp_x is 33 greater than exp_y, no need for compensation
822 if (diff > 33) {
823 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
824 BID_RETURN (res);
825 } // difference cannot be greater than 10^33
200359e8 826
b2a00c89
L
827 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
828 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 829
200359e8
L
830
831 // if postitive, return whichever significand is larger
832 // (converse if negative)
b2a00c89
L
833 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
834 && sig_n_prime256.w[1] == sig_y.w[1]
835 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
836 res = 0;
837 BID_RETURN (res);
b2a00c89 838 } // if equal, return 0
200359e8 839 {
b2a00c89
L
840 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
841 || (sig_n_prime256.w[1] > sig_y.w[1])
842 || (sig_n_prime256.w[1] == sig_y.w[1]
843 && sig_n_prime256.w[0] >
844 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
845 BID_RETURN (res);
846 }
847 }
b2a00c89
L
848 //else { //128 by 64 bit multiply -> 192 bits
849 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 850
b2a00c89
L
851 // if postitive, return whichever significand is larger
852 // (converse if negative)
853 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
854 && (sig_n_prime192.w[0] == sig_y.w[0])) {
855 res = 0;
856 BID_RETURN (res);
857 } // if equal, return 0
858 {
859 res = (((sig_n_prime192.w[2] > 0)
860 || (sig_n_prime192.w[1] > sig_y.w[1])
861 || (sig_n_prime192.w[1] == sig_y.w[1]
862 && sig_n_prime192.w[0] >
863 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
864 BID_RETURN (res);
865 }
b2a00c89 866}
200359e8 867
b2a00c89 868diff = exp_y - exp_x;
200359e8 869
b2a00c89
L
870 // if exp_x is 33 less than exp_y, no need for compensation
871if (diff > 33) {
872 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
873 BID_RETURN (res);
874}
200359e8 875
b2a00c89 876if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 877 // adjust the y significand upwards
b2a00c89
L
878 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
879
200359e8
L
880
881 // if postitive, return whichever significand is larger
882 // (converse if negative)
b2a00c89
L
883 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
884 && sig_n_prime256.w[1] == sig_x.w[1]
885 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
886 res = 0;
887 BID_RETURN (res);
b2a00c89 888 } // if equal, return 0
200359e8 889 {
b2a00c89
L
890 res = ((sig_n_prime256.w[3] == 0 && sig_n_prime256.w[2] == 0
891 && (sig_n_prime256.w[1] < sig_x.w[1]
892 || (sig_n_prime256.w[1] == sig_x.w[1]
893 && sig_n_prime256.w[0] <
894 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) ==
895 MASK_SIGN));
200359e8
L
896 BID_RETURN (res);
897 }
b2a00c89
L
898}
899 //else { //128 by 64 bit multiply -> 192 bits
900 // adjust the y significand upwards
901__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
902
903 // if postitive, return whichever significand is larger
904 // (converse if negative)
905if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
906 && (sig_n_prime192.w[0] == sig_x.w[0])) {
907 res = 0;
908 BID_RETURN (res);
909} // if equal, return 0
910{
911 res = (sig_n_prime192.w[2] == 0
912 && (sig_n_prime192.w[1] < sig_x.w[1]
913 || (sig_n_prime192.w[1] == sig_x.w[1]
914 && sig_n_prime192.w[0] <
915 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
916 BID_RETURN (res);
917}
200359e8
L
918}
919
b2a00c89 920BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_less, x, y)
200359e8 921
b2a00c89
L
922 int res;
923 int exp_x, exp_y;
924 int diff;
925 UINT128 sig_x, sig_y;
926 UINT192 sig_n_prime192;
927 UINT256 sig_n_prime256;
928 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
929
930 // NaN (CASE1)
931 // if either number is NAN, the comparison is unordered,
932 // rather than equal : return 0
b2a00c89
L
933if (((x.w[1] & MASK_NAN) == MASK_NAN)
934 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
935if ((x.w[1] & MASK_SNAN) == MASK_SNAN
936 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
937 *pfpsf |= INVALID_EXCEPTION;
938}
939{
940 res = 0;
941 BID_RETURN (res);
942}
943}
200359e8
L
944 // SIMPLE (CASE2)
945 // if all the bits are the same, these numbers are equal.
b2a00c89
L
946if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
947 res = 0;
948 BID_RETURN (res);
949}
950 // INFINITY (CASE3)
951if ((x.w[1] & MASK_INF) == MASK_INF) {
952 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
953 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
954 // x is -inf, so it is less than y unless y is -inf
955 {
956 res = (((y.w[1] & MASK_INF) != MASK_INF)
957 || (y.w[1] & MASK_SIGN) != MASK_SIGN);
958 BID_RETURN (res);
959 } else
960 // x is pos_inf, no way for it to be less than y
961 {
200359e8
L
962 res = 0;
963 BID_RETURN (res);
964 }
b2a00c89
L
965} else if ((y.w[1] & MASK_INF) == MASK_INF) {
966 // x is finite, so if y is positive infinity, then x is less, return 0
967 // if y is negative infinity, then x is greater, return 1
968 {
969 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
970 BID_RETURN (res);
200359e8 971 }
b2a00c89 972}
200359e8 973 // CONVERT X
b2a00c89
L
974sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
975sig_x.w[0] = x.w[0];
976exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
977
978 // CHECK IF X IS CANONICAL
979 // 9999999999999999999999999999999999(decimal) =
980 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
981 // [0, 10^34) is the 754r supported canonical range.
982 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
983if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
984 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
985 && (sig_x.w[0] > 0x378d8e63ffffffffull))
986 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
987 non_canon_x = 1;
988else
989 non_canon_x = 0;
200359e8
L
990
991 // CONVERT Y
b2a00c89
L
992exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
993sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
994sig_y.w[0] = y.w[0];
200359e8
L
995
996 // CHECK IF Y IS CANONICAL
997 // 9999999999999999999999999999999999(decimal) =
998 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
999 // [0, 10^34) is the 754r supported canonical range.
1000 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1001if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
1002 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
1003 && (sig_y.w[0] > 0x378d8e63ffffffffull))
1004 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1005 non_canon_y = 1;
1006else
1007 non_canon_y = 0;
200359e8
L
1008
1009 // ZERO (CASE4)
1010 // some properties:
1011 // (+ZERO == -ZERO) => therefore ignore the sign
1012 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
1013 // ignore the exponent field
1014 // (Any non-canonical # is considered 0)
b2a00c89
L
1015if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
1016 x_is_zero = 1;
1017}
1018if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
1019 y_is_zero = 1;
1020}
200359e8 1021 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
1022if (x_is_zero && y_is_zero) {
1023 res = 0;
1024 BID_RETURN (res);
1025}
200359e8 1026 // is x is zero, it is greater if Y is negative
b2a00c89
L
1027else if (x_is_zero) {
1028 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1029 BID_RETURN (res);
1030}
200359e8 1031 // is y is zero, X is greater if it is positive
b2a00c89
L
1032else if (y_is_zero) {
1033 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1034 BID_RETURN (res);
1035}
200359e8
L
1036 // OPPOSITE SIGN (CASE5)
1037 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
1038if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
1039 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1040 BID_RETURN (res);
1041}
200359e8
L
1042 // REDUNDANT REPRESENTATIONS (CASE6)
1043 // if exponents are the same, then we have a simple comparison of the
1044 // significands
b2a00c89
L
1045if (exp_y == exp_x) {
1046 res = (((sig_x.w[1] > sig_y.w[1])
1047 || (sig_x.w[1] == sig_y.w[1]
1048 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
1049 MASK_SIGN));
1050 BID_RETURN (res);
1051}
200359e8
L
1052 // if both components are either bigger or smaller,
1053 // it is clear what needs to be done
b2a00c89
L
1054if ((sig_x.w[1] > sig_y.w[1]
1055 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
1056 && exp_x >= exp_y) {
1057 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1058 BID_RETURN (res);
1059}
1060if ((sig_x.w[1] < sig_y.w[1]
1061 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
1062 && exp_x <= exp_y) {
1063 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1064 BID_RETURN (res);
1065}
200359e8 1066
b2a00c89 1067diff = exp_x - exp_y;
200359e8
L
1068
1069 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 1070if (diff > 0) { // to simplify the loop below,
200359e8 1071
b2a00c89
L
1072 // if exp_x is 33 greater than exp_y, no need for compensation
1073 if (diff > 33) {
1074 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1075 BID_RETURN (res);
1076 } // difference cannot be greater than 10^33
200359e8 1077
b2a00c89
L
1078 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
1079 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 1080
200359e8
L
1081
1082 // if postitive, return whichever significand is larger
1083 // (converse if negative)
b2a00c89
L
1084 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1085 && sig_n_prime256.w[1] == sig_y.w[1]
1086 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
1087 res = 0;
1088 BID_RETURN (res);
b2a00c89 1089 } // if equal, return 0
200359e8 1090 {
b2a00c89
L
1091 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
1092 || (sig_n_prime256.w[1] > sig_y.w[1])
1093 || (sig_n_prime256.w[1] == sig_y.w[1]
1094 && sig_n_prime256.w[0] >
1095 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1096 BID_RETURN (res);
1097 }
1098 }
b2a00c89
L
1099 //else { //128 by 64 bit multiply -> 192 bits
1100 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 1101
b2a00c89
L
1102 // if postitive, return whichever significand is larger
1103 // (converse if negative)
1104 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
1105 && (sig_n_prime192.w[0] == sig_y.w[0])) {
1106 res = 0;
1107 BID_RETURN (res);
1108 } // if equal, return 0
1109 {
1110 res = (((sig_n_prime192.w[2] > 0)
1111 || (sig_n_prime192.w[1] > sig_y.w[1])
1112 || (sig_n_prime192.w[1] == sig_y.w[1]
1113 && sig_n_prime192.w[0] >
1114 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1115 BID_RETURN (res);
1116 }
b2a00c89 1117}
200359e8 1118
b2a00c89 1119diff = exp_y - exp_x;
200359e8 1120
b2a00c89
L
1121 // if exp_x is 33 less than exp_y, no need for compensation
1122if (diff > 33) {
1123 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1124 BID_RETURN (res);
1125}
1126
1127if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 1128 // adjust the y significand upwards
b2a00c89 1129 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8
L
1130
1131 // if postitive, return whichever significand is larger
1132 // (converse if negative)
b2a00c89
L
1133 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1134 && sig_n_prime256.w[1] == sig_x.w[1]
1135 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
1136 res = 0;
1137 BID_RETURN (res);
b2a00c89 1138 } // if equal, return 1
200359e8 1139 {
b2a00c89
L
1140 res = ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
1141 || (sig_n_prime256.w[1] > sig_x.w[1]
1142 || (sig_n_prime256.w[1] == sig_x.w[1]
1143 && sig_n_prime256.w[0] >
1144 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) ==
1145 MASK_SIGN));
200359e8
L
1146 BID_RETURN (res);
1147 }
1148}
b2a00c89
L
1149 //else { //128 by 64 bit multiply -> 192 bits
1150 // adjust the y significand upwards
1151__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
200359e8 1152
b2a00c89
L
1153 // if postitive, return whichever significand is larger
1154 // (converse if negative)
1155if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
1156 && (sig_n_prime192.w[0] == sig_x.w[0])) {
1157 res = 0;
1158 BID_RETURN (res);
1159} // if equal, return 0
1160{
1161 res = (sig_n_prime192.w[2] != 0
1162 || (sig_n_prime192.w[1] > sig_x.w[1]
1163 || (sig_n_prime192.w[1] == sig_x.w[1]
1164 && sig_n_prime192.w[0] >
1165 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
1166 BID_RETURN (res);
1167}
1168}
1169
1170BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_less_equal,
1171 x, y)
1172
1173 int res;
1174 int exp_x, exp_y;
1175 int diff;
1176 UINT128 sig_x, sig_y;
1177 UINT192 sig_n_prime192;
1178 UINT256 sig_n_prime256;
1179 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
1180
1181 // NaN (CASE1)
1182 // if either number is NAN, the comparison is unordered,
1183 // rather than equal : return 0
1184if (((x.w[1] & MASK_NAN) == MASK_NAN)
1185 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
1186if ((x.w[1] & MASK_SNAN) == MASK_SNAN
1187 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
1188 *pfpsf |= INVALID_EXCEPTION;
1189}
1190{
1191 res = 0;
1192 BID_RETURN (res);
1193}
1194}
200359e8
L
1195 // SIMPLE (CASE2)
1196 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
1197if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
1198 res = 1;
1199 BID_RETURN (res);
1200}
1201 // INFINITY (CASE3)
1202if ((x.w[1] & MASK_INF) == MASK_INF) {
1203 // if x is neg infinity, there is no way it is greater than y, return 1
1204 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
1205 res = 1;
1206 BID_RETURN (res);
1207 }
b2a00c89
L
1208 // x is pos infinity, it is greater, unless y is positive infinity =>
1209 // return y!=pos_infinity
1210 else {
1211 res = (((y.w[1] & MASK_INF) == MASK_INF)
1212 && ((y.w[1] & MASK_SIGN) != MASK_SIGN));
1213 BID_RETURN (res);
1214 }
1215} else if ((y.w[1] & MASK_INF) == MASK_INF) {
1216 // x is finite, so if y is positive infinity, then x is less, return 0
1217 // if y is negative infinity, then x is greater, return 1
1218 {
1219 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1220 BID_RETURN (res);
200359e8 1221 }
b2a00c89 1222}
200359e8 1223 // CONVERT X
b2a00c89
L
1224sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
1225sig_x.w[0] = x.w[0];
1226exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
1227
1228 // CHECK IF X IS CANONICAL
1229 // 9999999999999999999999999999999999(decimal) =
1230 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1231 // [0, 10^34) is the 754r supported canonical range.
1232 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1233if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
1234 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
1235 && (sig_x.w[0] > 0x378d8e63ffffffffull))
1236 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1237 non_canon_x = 1;
1238else
1239 non_canon_x = 0;
200359e8
L
1240
1241 // CONVERT Y
b2a00c89
L
1242exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
1243sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
1244sig_y.w[0] = y.w[0];
200359e8
L
1245
1246 // CHECK IF Y IS CANONICAL
1247 // 9999999999999999999999999999999999(decimal) =
1248 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1249 // [0, 10^34) is the 754r supported canonical range.
1250 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1251if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
1252 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
1253 && (sig_y.w[0] > 0x378d8e63ffffffffull))
1254 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1255 non_canon_y = 1;
1256else
1257 non_canon_y = 0;
200359e8
L
1258
1259 // ZERO (CASE4)
1260 // some properties:
1261 // (+ZERO == -ZERO) => therefore ignore the sign
1262 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
1263 // ignore the exponent field
1264 // (Any non-canonical # is considered 0)
b2a00c89
L
1265if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
1266 x_is_zero = 1;
1267}
1268if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
1269 y_is_zero = 1;
1270}
200359e8 1271 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
1272if (x_is_zero && y_is_zero) {
1273 res = 1;
1274 BID_RETURN (res);
1275}
200359e8 1276 // is x is zero, it is greater if Y is negative
b2a00c89
L
1277else if (x_is_zero) {
1278 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1279 BID_RETURN (res);
1280}
200359e8 1281 // is y is zero, X is greater if it is positive
b2a00c89
L
1282else if (y_is_zero) {
1283 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1284 BID_RETURN (res);
1285}
200359e8
L
1286 // OPPOSITE SIGN (CASE5)
1287 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
1288if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
1289 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1290 BID_RETURN (res);
1291}
200359e8
L
1292 // REDUNDANT REPRESENTATIONS (CASE6)
1293 // if exponents are the same, then we have a simple comparison of the
1294 // significands
b2a00c89
L
1295if (exp_y == exp_x) {
1296 res = (((sig_x.w[1] > sig_y.w[1]) || (sig_x.w[1] == sig_y.w[1] &&
1297 sig_x.w[0] >=
1298 sig_y.w[0])) ^ ((x.
1299 w[1] &
1300 MASK_SIGN) !=
1301 MASK_SIGN));
1302 BID_RETURN (res);
1303}
200359e8
L
1304 // if both components are either bigger or smaller,
1305 // it is clear what needs to be done
b2a00c89
L
1306if ((sig_x.w[1] > sig_y.w[1]
1307 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
1308 && exp_x >= exp_y) {
1309 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1310 BID_RETURN (res);
1311}
1312if ((sig_x.w[1] < sig_y.w[1]
1313 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
1314 && exp_x <= exp_y) {
1315 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1316 BID_RETURN (res);
1317}
200359e8 1318
b2a00c89 1319diff = exp_x - exp_y;
200359e8
L
1320
1321 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 1322if (diff > 0) { // to simplify the loop below,
200359e8 1323
b2a00c89
L
1324 // if exp_x is 33 greater than exp_y, no need for compensation
1325 if (diff > 33) {
1326 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1327 BID_RETURN (res);
1328 } // difference cannot be greater than 10^33
200359e8 1329
b2a00c89
L
1330 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
1331 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 1332
200359e8
L
1333
1334 // if postitive, return whichever significand is larger
b2a00c89
L
1335 // (converse if negative)
1336 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1337 && sig_n_prime256.w[1] == sig_y.w[1]
1338 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
1339 res = 1;
1340 BID_RETURN (res);
b2a00c89 1341 } // if equal, return 0
200359e8 1342 {
b2a00c89
L
1343 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
1344 || (sig_n_prime256.w[1] > sig_y.w[1])
1345 || (sig_n_prime256.w[1] == sig_y.w[1]
1346 && sig_n_prime256.w[0] >
1347 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1348 BID_RETURN (res);
1349 }
1350 }
b2a00c89
L
1351 //else { //128 by 64 bit multiply -> 192 bits
1352 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 1353
b2a00c89
L
1354 // if postitive, return whichever significand is larger
1355 // (converse if negative)
1356 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
1357 && (sig_n_prime192.w[0] == sig_y.w[0])) {
1358 res = 1;
1359 BID_RETURN (res);
1360 } // if equal, return 0
1361 {
1362 res = (((sig_n_prime192.w[2] > 0)
1363 || (sig_n_prime192.w[1] > sig_y.w[1])
1364 || (sig_n_prime192.w[1] == sig_y.w[1]
1365 && sig_n_prime192.w[0] >
1366 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1367 BID_RETURN (res);
1368 }
b2a00c89 1369}
200359e8 1370
b2a00c89 1371diff = exp_y - exp_x;
200359e8 1372
b2a00c89
L
1373 // if exp_x is 33 less than exp_y, no need for compensation
1374if (diff > 33) {
1375 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1376 BID_RETURN (res);
1377}
200359e8 1378
b2a00c89 1379if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 1380 // adjust the y significand upwards
b2a00c89
L
1381 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
1382
200359e8
L
1383
1384 // if postitive, return whichever significand is larger
b2a00c89
L
1385 // (converse if negative)
1386 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1387 && sig_n_prime256.w[1] == sig_x.w[1]
1388 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
1389 res = 1;
1390 BID_RETURN (res);
b2a00c89 1391 } // if equal, return 0
200359e8 1392 {
b2a00c89
L
1393 res =
1394 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
1395 || (sig_n_prime256.w[1] > sig_x.w[1]
1396 || (sig_n_prime256.w[1] == sig_x.w[1]
1397 && sig_n_prime256.w[0] >
1398 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
1399 BID_RETURN (res);
1400 }
b2a00c89
L
1401}
1402 //else { //128 by 64 bit multiply -> 192 bits
1403 // adjust the y significand upwards
1404__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
1405
1406 // if postitive, return whichever significand is larger
1407 // (converse if negative)
1408if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
1409 && (sig_n_prime192.w[0] == sig_x.w[0])) {
1410 res = 1;
1411 BID_RETURN (res);
1412} // if equal, return 0
1413{
1414 res = (sig_n_prime192.w[2] != 0
1415 || (sig_n_prime192.w[1] > sig_x.w[1]
1416 || (sig_n_prime192.w[1] == sig_x.w[1]
1417 && sig_n_prime192.w[0] >
1418 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
1419 BID_RETURN (res);
1420}
200359e8
L
1421}
1422
b2a00c89
L
1423BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
1424 bid128_quiet_less_unordered,
1425 x, y)
200359e8 1426
b2a00c89
L
1427 int res;
1428 int exp_x, exp_y;
1429 int diff;
1430 UINT128 sig_x, sig_y;
1431 UINT192 sig_n_prime192;
1432 UINT256 sig_n_prime256;
1433 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
1434
1435 // NaN (CASE1)
1436 // if either number is NAN, the comparison is unordered
b2a00c89
L
1437if (((x.w[1] & MASK_NAN) == MASK_NAN)
1438 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
1439if ((x.w[1] & MASK_SNAN) == MASK_SNAN
1440 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
1441 *pfpsf |= INVALID_EXCEPTION;
1442}
1443{
1444 res = 1;
1445 BID_RETURN (res);
1446}
1447}
200359e8
L
1448 // SIMPLE (CASE2)
1449 // if all the bits are the same, these numbers are equal.
b2a00c89
L
1450if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
1451 res = 0;
1452 BID_RETURN (res);
1453}
1454 // INFINITY (CASE3)
1455if ((x.w[1] & MASK_INF) == MASK_INF) {
1456 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
1457 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
1458 // x is -inf, so it is less than y unless y is -inf
1459 {
1460 res = (((y.w[1] & MASK_INF) != MASK_INF)
1461 || (y.w[1] & MASK_SIGN) != MASK_SIGN);
1462 BID_RETURN (res);
1463 } else
1464 // x is pos_inf, no way for it to be less than y
1465 {
200359e8
L
1466 res = 0;
1467 BID_RETURN (res);
1468 }
b2a00c89
L
1469} else if ((y.w[1] & MASK_INF) == MASK_INF) {
1470 // x is finite, so if y is positive infinity, then x is less, return 0
1471 // if y is negative infinity, then x is greater, return 1
1472 {
1473 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1474 BID_RETURN (res);
200359e8 1475 }
b2a00c89 1476}
200359e8 1477 // CONVERT X
b2a00c89
L
1478sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
1479sig_x.w[0] = x.w[0];
1480exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
1481
1482 // CHECK IF X IS CANONICAL
1483 // 9999999999999999999999999999999999(decimal) =
1484 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1485 // [0, 10^34) is the 754r supported canonical range.
1486 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1487if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
1488 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
1489 && (sig_x.w[0] > 0x378d8e63ffffffffull))
1490 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1491 non_canon_x = 1;
1492else
1493 non_canon_x = 0;
200359e8
L
1494
1495 // CONVERT Y
b2a00c89
L
1496exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
1497sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
1498sig_y.w[0] = y.w[0];
200359e8
L
1499
1500 // CHECK IF Y IS CANONICAL
1501 // 9999999999999999999999999999999999(decimal) =
1502 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1503 // [0, 10^34) is the 754r supported canonical range.
1504 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1505if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
1506 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
1507 && (sig_y.w[0] > 0x378d8e63ffffffffull))
1508 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1509 non_canon_y = 1;
1510else
1511 non_canon_y = 0;
200359e8
L
1512
1513 // ZERO (CASE4)
1514 // some properties:
1515 // (+ZERO == -ZERO) => therefore ignore the sign
1516 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
1517 // ignore the exponent field
1518 // (Any non-canonical # is considered 0)
b2a00c89
L
1519if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
1520 x_is_zero = 1;
1521}
1522if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
1523 y_is_zero = 1;
1524}
200359e8 1525 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
1526if (x_is_zero && y_is_zero) {
1527 res = 0;
1528 BID_RETURN (res);
1529}
200359e8 1530 // is x is zero, it is greater if Y is negative
b2a00c89
L
1531else if (x_is_zero) {
1532 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1533 BID_RETURN (res);
1534}
200359e8 1535 // is y is zero, X is greater if it is positive
b2a00c89
L
1536else if (y_is_zero) {
1537 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1538 BID_RETURN (res);
1539}
200359e8
L
1540 // OPPOSITE SIGN (CASE5)
1541 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
1542if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
1543 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1544 BID_RETURN (res);
1545}
200359e8
L
1546 // REDUNDANT REPRESENTATIONS (CASE6)
1547 // if exponents are the same, then we have a simple comparison
1548 // of the significands
b2a00c89
L
1549if (exp_y == exp_x) {
1550 res = (((sig_x.w[1] > sig_y.w[1])
1551 || (sig_x.w[1] == sig_y.w[1]
1552 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
1553 MASK_SIGN));
1554 BID_RETURN (res);
1555}
200359e8
L
1556 // if both components are either bigger or smaller,
1557 // it is clear what needs to be done
b2a00c89
L
1558if ((sig_x.w[1] > sig_y.w[1]
1559 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
1560 && exp_x >= exp_y) {
1561 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1562 BID_RETURN (res);
1563}
1564if ((sig_x.w[1] < sig_y.w[1]
1565 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
1566 && exp_x <= exp_y) {
1567 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1568 BID_RETURN (res);
1569}
200359e8 1570
b2a00c89 1571diff = exp_x - exp_y;
200359e8
L
1572
1573 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 1574if (diff > 0) { // to simplify the loop below,
200359e8 1575
b2a00c89
L
1576 // if exp_x is 33 greater than exp_y, no need for compensation
1577 if (diff > 33) {
1578 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1579 BID_RETURN (res);
1580 } // difference cannot be greater than 10^33
200359e8 1581
b2a00c89
L
1582 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
1583 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 1584
200359e8
L
1585
1586 // if postitive, return whichever significand is larger
1587 // (converse if negative)
b2a00c89
L
1588 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1589 && sig_n_prime256.w[1] == sig_y.w[1]
1590 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
1591 res = 0;
1592 BID_RETURN (res);
b2a00c89 1593 } // if equal, return 0
200359e8 1594 {
b2a00c89
L
1595 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
1596 || (sig_n_prime256.w[1] > sig_y.w[1])
1597 || (sig_n_prime256.w[1] == sig_y.w[1]
1598 && sig_n_prime256.w[0] >
1599 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1600 BID_RETURN (res);
1601 }
1602 }
b2a00c89
L
1603 //else { //128 by 64 bit multiply -> 192 bits
1604 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 1605
b2a00c89
L
1606 // if postitive, return whichever significand is larger
1607 // (converse if negative)
1608 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
1609 && (sig_n_prime192.w[0] == sig_y.w[0])) {
1610 res = 0;
1611 BID_RETURN (res);
1612 } // if equal, return 0
1613 {
1614 res = (((sig_n_prime192.w[2] > 0)
1615 || (sig_n_prime192.w[1] > sig_y.w[1])
1616 || (sig_n_prime192.w[1] == sig_y.w[1]
1617 && sig_n_prime192.w[0] >
1618 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1619 BID_RETURN (res);
1620 }
b2a00c89 1621}
200359e8 1622
b2a00c89 1623diff = exp_y - exp_x;
200359e8 1624
b2a00c89
L
1625 // if exp_x is 33 less than exp_y, no need for compensation
1626if (diff > 33) {
1627 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1628 BID_RETURN (res);
1629}
200359e8 1630
b2a00c89 1631if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 1632 // adjust the y significand upwards
b2a00c89
L
1633 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
1634
200359e8
L
1635
1636 // if postitive, return whichever significand is larger
1637 // (converse if negative)
b2a00c89
L
1638 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1639 && sig_n_prime256.w[1] == sig_x.w[1]
1640 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
1641 res = 0;
1642 BID_RETURN (res);
b2a00c89 1643 } // if equal, return 1
200359e8 1644 {
b2a00c89
L
1645 res =
1646 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
1647 || (sig_n_prime256.w[1] > sig_x.w[1]
1648 || (sig_n_prime256.w[1] == sig_x.w[1]
1649 && sig_n_prime256.w[0] >
1650 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
1651 BID_RETURN (res);
1652 }
b2a00c89
L
1653}
1654 //else { //128 by 64 bit multiply -> 192 bits
1655 // adjust the y significand upwards
1656__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
1657
1658 // if postitive, return whichever significand is larger
1659 // (converse if negative)
1660if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
1661 && (sig_n_prime192.w[0] == sig_x.w[0])) {
1662 res = 0;
1663 BID_RETURN (res);
1664} // if equal, return 0
1665{
1666 res = (sig_n_prime192.w[2] != 0
1667 || (sig_n_prime192.w[1] > sig_x.w[1]
1668 || (sig_n_prime192.w[1] == sig_x.w[1]
1669 && sig_n_prime192.w[0] >
1670 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
1671 BID_RETURN (res);
1672}
200359e8
L
1673}
1674
b2a00c89
L
1675BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_not_equal,
1676 x, y)
200359e8 1677
b2a00c89
L
1678 int res;
1679 int exp_x, exp_y, exp_t;
1680 UINT128 sig_x, sig_y, sig_t;
1681 UINT192 sig_n_prime192;
1682 UINT256 sig_n_prime256;
1683 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
1684
1685 // NaN (CASE1)
1686 // if either number is NAN, the comparison is unordered,
1687 // rather than equal : return 0
b2a00c89
L
1688if (((x.w[1] & MASK_NAN) == MASK_NAN)
1689 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
1690if ((x.w[1] & MASK_SNAN) == MASK_SNAN
1691 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
1692 *pfpsf |= INVALID_EXCEPTION;
1693}
1694{
1695 res = 1;
1696 BID_RETURN (res);
1697}
1698}
200359e8
L
1699 // SIMPLE (CASE2)
1700 // if all the bits are the same, these numbers are equivalent.
b2a00c89
L
1701if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
1702 res = 0;
1703 BID_RETURN (res);
1704}
200359e8 1705 // INFINITY (CASE3)
b2a00c89 1706if ((x.w[1] & MASK_INF) == MASK_INF) {
200359e8 1707 if ((y.w[1] & MASK_INF) == MASK_INF) {
b2a00c89
L
1708 res = (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN);
1709 BID_RETURN (res);
1710 } else {
200359e8
L
1711 res = 1;
1712 BID_RETURN (res);
1713 }
b2a00c89
L
1714}
1715if ((y.w[1] & MASK_INF) == MASK_INF) {
1716 res = 1;
1717 BID_RETURN (res);
1718}
200359e8 1719 // CONVERT X
b2a00c89
L
1720sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
1721sig_x.w[0] = x.w[0];
1722exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
1723
1724 // CHECK IF X IS CANONICAL
1725 // 9999999999999999999999999999999999(decimal) =
1726 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1727 // [0, 10^34) is the 754r supported canonical range.
1728 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1729if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
1730 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
1731 && (sig_x.w[0] > 0x378d8e63ffffffffull))
1732 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1733 non_canon_x = 1;
1734else
1735 non_canon_x = 0;
200359e8
L
1736
1737 // CONVERT Y
b2a00c89
L
1738exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
1739sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
1740sig_y.w[0] = y.w[0];
200359e8
L
1741
1742 // CHECK IF Y IS CANONICAL
1743 // 9999999999999999999999999999999999(decimal) =
1744 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1745 // [0, 10^34) is the 754r supported canonical range.
1746 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1747if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
1748 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
1749 && (sig_y.w[0] > 0x378d8e63ffffffffull))
1750 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1751 non_canon_y = 1;
1752else
1753 non_canon_y = 0;
200359e8
L
1754
1755 // some properties:
1756 // (+ZERO == -ZERO) => therefore ignore the sign
1757 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
1758 // ignore the exponent field
1759 // (Any non-canonical # is considered 0)
b2a00c89
L
1760if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
1761 x_is_zero = 1;
1762}
1763if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
1764 y_is_zero = 1;
1765}
200359e8 1766
b2a00c89
L
1767if (x_is_zero && y_is_zero) {
1768 res = 0;
1769 BID_RETURN (res);
1770} else if ((x_is_zero && !y_is_zero) || (!x_is_zero && y_is_zero)) {
1771 res = 1;
1772 BID_RETURN (res);
1773}
200359e8
L
1774 // OPPOSITE SIGN (CASE5)
1775 // now, if the sign bits differ => not equal : return 0
b2a00c89
L
1776if ((x.w[1] ^ y.w[1]) & MASK_SIGN) {
1777 res = 1;
1778 BID_RETURN (res);
1779}
200359e8 1780 // REDUNDANT REPRESENTATIONS (CASE6)
b2a00c89
L
1781if (exp_x > exp_y) { // to simplify the loop below,
1782 SWAP (exp_x, exp_y, exp_t); // put the larger exp in y,
1783 SWAP (sig_x.w[1], sig_y.w[1], sig_t.w[1]); // and the smaller exp in x
1784 SWAP (sig_x.w[0], sig_y.w[0], sig_t.w[0]); // and the smaller exp in x
1785}
200359e8 1786
200359e8 1787
b2a00c89
L
1788if (exp_y - exp_x > 33) {
1789 res = 1;
1790 BID_RETURN (res);
1791} // difference cannot be greater than 10^33
200359e8 1792
b2a00c89 1793if (exp_y - exp_x > 19) {
200359e8 1794 // recalculate y's significand upwards
b2a00c89
L
1795 __mul_128x128_to_256 (sig_n_prime256, sig_y,
1796 ten2k128[exp_y - exp_x - 20]);
200359e8 1797 {
b2a00c89
L
1798 res = ((sig_n_prime256.w[3] != 0) || (sig_n_prime256.w[2] != 0)
1799 || (sig_n_prime256.w[1] != sig_x.w[1])
1800 || (sig_n_prime256.w[0] != sig_x.w[0]));
200359e8
L
1801 BID_RETURN (res);
1802 }
b2a00c89
L
1803
1804}
1805 //else{
1806 // recalculate y's significand upwards
1807__mul_64x128_to192 (sig_n_prime192, ten2k64[exp_y - exp_x], sig_y);
1808{
1809 res = ((sig_n_prime192.w[2] != 0)
1810 || (sig_n_prime192.w[1] != sig_x.w[1])
1811 || (sig_n_prime192.w[0] != sig_x.w[0]));
1812 BID_RETURN (res);
1813}
200359e8
L
1814}
1815
b2a00c89
L
1816BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_not_greater,
1817 x, y)
200359e8 1818
b2a00c89
L
1819 int res;
1820 int exp_x, exp_y;
1821 int diff;
1822 UINT128 sig_x, sig_y;
1823 UINT192 sig_n_prime192;
1824 UINT256 sig_n_prime256;
1825 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
1826
1827 // NaN (CASE1)
1828 // if either number is NAN, the comparison is unordered,
1829 // rather than equal : return 0
b2a00c89
L
1830if (((x.w[1] & MASK_NAN) == MASK_NAN)
1831 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
1832if ((x.w[1] & MASK_SNAN) == MASK_SNAN
1833 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
1834 *pfpsf |= INVALID_EXCEPTION;
1835}
1836{
1837 res = 1;
1838 BID_RETURN (res);
1839}
1840}
200359e8
L
1841 // SIMPLE (CASE2)
1842 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
1843if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
1844 res = 1;
1845 BID_RETURN (res);
1846}
1847 // INFINITY (CASE3)
1848if ((x.w[1] & MASK_INF) == MASK_INF) {
1849 // if x is neg infinity, there is no way it is greater than y, return 1
1850 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
1851 res = 1;
1852 BID_RETURN (res);
1853 }
b2a00c89
L
1854 // x is pos infinity, it is greater, unless y is positive infinity => return y!=pos_infinity
1855 else {
1856 res = (((y.w[1] & MASK_INF) == MASK_INF)
1857 && ((y.w[1] & MASK_SIGN) != MASK_SIGN));
1858 BID_RETURN (res);
1859 }
1860} else if ((y.w[1] & MASK_INF) == MASK_INF) {
1861 // x is finite, so if y is positive infinity, then x is less, return 0
1862 // if y is negative infinity, then x is greater, return 1
1863 {
1864 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1865 BID_RETURN (res);
200359e8 1866 }
b2a00c89 1867}
200359e8 1868 // CONVERT X
b2a00c89
L
1869sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
1870sig_x.w[0] = x.w[0];
1871exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
1872
1873 // CHECK IF X IS CANONICAL
1874 // 9999999999999999999999999999999999(decimal) =
1875 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1876 // [0, 10^34) is the 754r supported canonical range.
1877 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1878if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
1879 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
1880 && (sig_x.w[0] > 0x378d8e63ffffffffull))
1881 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1882 non_canon_x = 1;
1883else
1884 non_canon_x = 0;
200359e8
L
1885
1886 // CONVERT Y
b2a00c89
L
1887exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
1888sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
1889sig_y.w[0] = y.w[0];
200359e8
L
1890
1891 // CHECK IF Y IS CANONICAL
1892 // 9999999999999999999999999999999999(decimal) =
1893 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
1894 // [0, 10^34) is the 754r supported canonical range.
1895 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
1896if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
1897 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
1898 && (sig_y.w[0] > 0x378d8e63ffffffffull))
1899 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
1900 non_canon_y = 1;
1901else
1902 non_canon_y = 0;
200359e8
L
1903
1904 // ZERO (CASE4)
1905 // some properties:
1906 // (+ZERO == -ZERO) => therefore ignore the sign
1907 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
1908 // ignore the exponent field
1909 // (Any non-canonical # is considered 0)
b2a00c89
L
1910if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
1911 x_is_zero = 1;
1912}
1913if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
1914 y_is_zero = 1;
1915}
200359e8 1916 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
1917if (x_is_zero && y_is_zero) {
1918 res = 1;
1919 BID_RETURN (res);
1920}
200359e8 1921 // is x is zero, it is greater if Y is negative
b2a00c89
L
1922else if (x_is_zero) {
1923 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1924 BID_RETURN (res);
1925}
200359e8 1926 // is y is zero, X is greater if it is positive
b2a00c89
L
1927else if (y_is_zero) {
1928 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1929 BID_RETURN (res);
1930}
200359e8
L
1931 // OPPOSITE SIGN (CASE5)
1932 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
1933if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
1934 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
1935 BID_RETURN (res);
1936}
200359e8
L
1937 // REDUNDANT REPRESENTATIONS (CASE6)
1938 // if exponents are the same, then we have a simple comparison
1939 // of the significands
b2a00c89
L
1940if (exp_y == exp_x) {
1941 res = (((sig_x.w[1] > sig_y.w[1])
1942 || (sig_x.w[1] == sig_y.w[1]
1943 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
1944 MASK_SIGN));
1945 BID_RETURN (res);
1946}
200359e8
L
1947 // if both components are either bigger or smaller,
1948 // it is clear what needs to be done
b2a00c89
L
1949if ((sig_x.w[1] > sig_y.w[1]
1950 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
1951 && exp_x >= exp_y) {
1952 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1953 BID_RETURN (res);
1954}
1955if ((sig_x.w[1] < sig_y.w[1]
1956 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
1957 && exp_x <= exp_y) {
1958 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
1959 BID_RETURN (res);
1960}
200359e8 1961
b2a00c89 1962diff = exp_x - exp_y;
200359e8
L
1963
1964 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 1965if (diff > 0) { // to simplify the loop below,
200359e8 1966
b2a00c89
L
1967 // if exp_x is 33 greater than exp_y, no need for compensation
1968 if (diff > 33) {
1969 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
1970 BID_RETURN (res);
1971 } // difference cannot be greater than 10^33
200359e8 1972
b2a00c89
L
1973 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
1974 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 1975
200359e8
L
1976
1977 // if postitive, return whichever significand is larger
1978 // (converse if negative)
b2a00c89
L
1979 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
1980 && sig_n_prime256.w[1] == sig_y.w[1]
1981 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
1982 res = 1;
1983 BID_RETURN (res);
b2a00c89 1984 } // if equal, return 0
200359e8 1985 {
b2a00c89
L
1986 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
1987 || (sig_n_prime256.w[1] > sig_y.w[1])
1988 || (sig_n_prime256.w[1] == sig_y.w[1]
1989 && sig_n_prime256.w[0] >
1990 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
1991 BID_RETURN (res);
1992 }
1993 }
b2a00c89
L
1994 //else { //128 by 64 bit multiply -> 192 bits
1995 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 1996
b2a00c89
L
1997 // if postitive, return whichever significand is larger
1998 // (converse if negative)
1999 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
2000 && (sig_n_prime192.w[0] == sig_y.w[0])) {
2001 res = 1;
2002 BID_RETURN (res);
2003 } // if equal, return 0
2004 {
2005 res = (((sig_n_prime192.w[2] > 0)
2006 || (sig_n_prime192.w[1] > sig_y.w[1])
2007 || (sig_n_prime192.w[1] == sig_y.w[1]
2008 && sig_n_prime192.w[0] >
2009 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
2010 BID_RETURN (res);
2011 }
b2a00c89 2012}
200359e8 2013
b2a00c89 2014diff = exp_y - exp_x;
200359e8 2015
b2a00c89
L
2016 // if exp_x is 33 less than exp_y, no need for compensation
2017if (diff > 33) {
2018 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2019 BID_RETURN (res);
2020}
200359e8 2021
b2a00c89 2022if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 2023 // adjust the y significand upwards
b2a00c89
L
2024 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
2025
200359e8
L
2026
2027 // if postitive, return whichever significand is larger
2028 // (converse if negative)
b2a00c89
L
2029 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
2030 && sig_n_prime256.w[1] == sig_x.w[1]
2031 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
2032 res = 1;
2033 BID_RETURN (res);
b2a00c89 2034 } // if equal, return 0
200359e8 2035 {
b2a00c89
L
2036 res =
2037 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
2038 || (sig_n_prime256.w[1] > sig_x.w[1]
2039 || (sig_n_prime256.w[1] == sig_x.w[1]
2040 && sig_n_prime256.w[0] >
2041 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2042 BID_RETURN (res);
2043 }
b2a00c89
L
2044}
2045 //else { //128 by 64 bit multiply -> 192 bits
2046 // adjust the y significand upwards
2047__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
2048
2049 // if postitive, return whichever significand is larger
2050 // (converse if negative)
2051if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
2052 && (sig_n_prime192.w[0] == sig_x.w[0])) {
2053 res = 1;
2054 BID_RETURN (res);
2055} // if equal, return 0
2056{
2057 res = (sig_n_prime192.w[2] != 0
2058 || (sig_n_prime192.w[1] > sig_x.w[1]
2059 || (sig_n_prime192.w[1] == sig_x.w[1]
2060 && sig_n_prime192.w[0] >
2061 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2062 BID_RETURN (res);
2063}
200359e8
L
2064}
2065
b2a00c89
L
2066BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_not_less, x,
2067 y)
200359e8 2068
b2a00c89
L
2069 int res;
2070 int exp_x, exp_y;
2071 int diff;
2072 UINT128 sig_x, sig_y;
2073 UINT192 sig_n_prime192;
2074 UINT256 sig_n_prime256;
2075 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
2076
2077 // NaN (CASE1)
2078 // if either number is NAN, the comparison is unordered,
2079 // rather than equal : return 1
b2a00c89
L
2080if (((x.w[1] & MASK_NAN) == MASK_NAN)
2081 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
2082if ((x.w[1] & MASK_SNAN) == MASK_SNAN
2083 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
2084 *pfpsf |= INVALID_EXCEPTION;
2085}
2086{
2087 res = 1;
2088 BID_RETURN (res);
2089}
2090}
200359e8
L
2091 // SIMPLE (CASE2)
2092 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
2093if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
2094 res = 1;
2095 BID_RETURN (res);
2096}
2097 // INFINITY (CASE3)
2098if ((x.w[1] & MASK_INF) == MASK_INF) {
2099 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
2100 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
2101 // x is -inf, so it is less than y unless y is -inf
2102 {
2103 res = (((y.w[1] & MASK_INF) == MASK_INF)
2104 && (y.w[1] & MASK_SIGN) == MASK_SIGN);
2105 BID_RETURN (res);
2106 } else
2107 // x is pos_inf, no way for it to be less than y
2108 {
200359e8
L
2109 res = 1;
2110 BID_RETURN (res);
2111 }
b2a00c89
L
2112} else if ((y.w[1] & MASK_INF) == MASK_INF) {
2113 // x is finite, so if y is positive infinity, then x is less, return 0
2114 // if y is negative infinity, then x is greater, return 1
2115 {
2116 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2117 BID_RETURN (res);
200359e8 2118 }
b2a00c89 2119}
200359e8 2120 // CONVERT X
b2a00c89
L
2121sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
2122sig_x.w[0] = x.w[0];
2123exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
2124
2125 // CHECK IF X IS CANONICAL
2126 // 9999999999999999999999999999999999(decimal) =
2127 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2128 // [0, 10^34) is the 754r supported canonical range.
2129 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2130if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
2131 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
2132 && (sig_x.w[0] > 0x378d8e63ffffffffull))
2133 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2134 non_canon_x = 1;
2135else
2136 non_canon_x = 0;
200359e8
L
2137
2138 // CONVERT Y
b2a00c89
L
2139exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
2140sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
2141sig_y.w[0] = y.w[0];
200359e8
L
2142
2143 // CHECK IF Y IS CANONICAL
2144 // 9999999999999999999999999999999999(decimal) =
2145 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2146 // [0, 10^34) is the 754r supported canonical range.
2147 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2148if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
2149 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
2150 && (sig_y.w[0] > 0x378d8e63ffffffffull))
2151 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2152 non_canon_y = 1;
2153else
2154 non_canon_y = 0;
200359e8
L
2155
2156 // ZERO (CASE4)
2157 // some properties:
2158 // (+ZERO == -ZERO) => therefore ignore the sign
2159 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
2160 // ignore the exponent field
2161 // (Any non-canonical # is considered 0)
b2a00c89
L
2162if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
2163 x_is_zero = 1;
2164}
2165if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
2166 y_is_zero = 1;
2167}
200359e8 2168 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
2169if (x_is_zero && y_is_zero) {
2170 res = 1;
2171 BID_RETURN (res);
2172}
200359e8 2173 // is x is zero, it is greater if Y is negative
b2a00c89
L
2174else if (x_is_zero) {
2175 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2176 BID_RETURN (res);
2177}
200359e8 2178 // is y is zero, X is greater if it is positive
b2a00c89
L
2179else if (y_is_zero) {
2180 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2181 BID_RETURN (res);
2182}
200359e8
L
2183 // OPPOSITE SIGN (CASE5)
2184 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
2185if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
2186 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2187 BID_RETURN (res);
2188}
200359e8
L
2189 // REDUNDANT REPRESENTATIONS (CASE6)
2190
2191 // if exponents are the same, then we have a simple comparison
2192 // of the significands
b2a00c89
L
2193if (exp_y == exp_x) {
2194 res = (((sig_x.w[1] > sig_y.w[1])
2195 || (sig_x.w[1] == sig_y.w[1]
2196 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
2197 MASK_SIGN));
2198 BID_RETURN (res);
2199}
200359e8
L
2200 // if both components are either bigger or smaller,
2201 // it is clear what needs to be done
b2a00c89
L
2202if (sig_x.w[1] >= sig_y.w[1] && sig_x.w[0] >= sig_y.w[0]
2203 && exp_x > exp_y) {
2204 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2205 BID_RETURN (res);
2206}
2207if (sig_x.w[1] <= sig_y.w[1] && sig_x.w[0] <= sig_y.w[0]
2208 && exp_x < exp_y) {
2209 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
2210 BID_RETURN (res);
2211}
200359e8 2212
b2a00c89 2213diff = exp_x - exp_y;
200359e8
L
2214
2215 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 2216if (diff > 0) { // to simplify the loop below,
200359e8 2217
b2a00c89 2218 // if exp_x is 33 greater than exp_y, no need for compensation
200359e8 2219 if (diff > 33) {
b2a00c89 2220 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
200359e8 2221 BID_RETURN (res);
b2a00c89 2222 } // difference cannot be greater than 10^33
200359e8 2223
b2a00c89
L
2224 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
2225 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8
L
2226
2227
2228 // if postitive, return whichever significand is larger
2229 // (converse if negative)
2230 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
b2a00c89
L
2231 && sig_n_prime256.w[1] == sig_y.w[1]
2232 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
2233 res = 1;
2234 BID_RETURN (res);
b2a00c89 2235 } // if equal, return 1
200359e8 2236 {
b2a00c89
L
2237 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
2238 || (sig_n_prime256.w[1] > sig_y.w[1])
2239 || (sig_n_prime256.w[1] == sig_y.w[1]
2240 && sig_n_prime256.w[0] >
2241 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2242 BID_RETURN (res);
2243 }
2244 }
2245 //else { //128 by 64 bit multiply -> 192 bits
b2a00c89 2246 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8
L
2247
2248 // if postitive, return whichever significand is larger
2249 // (converse if negative)
b2a00c89
L
2250 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
2251 && (sig_n_prime192.w[0] == sig_y.w[0])) {
200359e8
L
2252 res = 1;
2253 BID_RETURN (res);
b2a00c89 2254 } // if equal, return 1
200359e8 2255 {
b2a00c89
L
2256 res = (((sig_n_prime192.w[2] > 0)
2257 || (sig_n_prime192.w[1] > sig_y.w[1])
2258 || (sig_n_prime192.w[1] == sig_y.w[1]
2259 && sig_n_prime192.w[0] >
2260 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2261 BID_RETURN (res);
2262 }
2263}
2264
b2a00c89 2265diff = exp_y - exp_x;
200359e8 2266
b2a00c89
L
2267 // if exp_x is 33 less than exp_y, no need for compensation
2268if (diff > 33) {
2269 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
2270 BID_RETURN (res);
200359e8
L
2271}
2272
b2a00c89
L
2273if (diff > 19) { //128 by 128 bit multiply -> 256 bits
2274 // adjust the y significand upwards
2275 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8 2276
200359e8 2277
b2a00c89
L
2278 // if postitive, return whichever significand is larger
2279 // (converse if negative)
2280 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
2281 && sig_n_prime256.w[1] == sig_x.w[1]
2282 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
2283 res = 1;
2284 BID_RETURN (res);
b2a00c89
L
2285 } // if equal, return 1
2286 {
2287 res =
2288 ((sig_n_prime256.w[3] == 0 && sig_n_prime256.w[2] == 0
2289 && (sig_n_prime256.w[1] < sig_x.w[1]
2290 || (sig_n_prime256.w[1] == sig_x.w[1]
2291 && sig_n_prime256.w[0] <
2292 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2293 BID_RETURN (res);
2294 }
b2a00c89
L
2295}
2296 //else { //128 by 64 bit multiply -> 192 bits
2297 // adjust the y significand upwards
2298__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
200359e8 2299
b2a00c89
L
2300 // if postitive, return whichever significand is larger
2301 // (converse if negative)
2302if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
2303 && (sig_n_prime192.w[0] == sig_x.w[0])) {
2304 res = 1;
2305 BID_RETURN (res);
2306} // if equal, return 1
2307{
2308 res = (sig_n_prime192.w[2] == 0
2309 && (sig_n_prime192.w[1] < sig_x.w[1]
2310 || (sig_n_prime192.w[1] == sig_x.w[1]
2311 && sig_n_prime192.w[0] <
2312 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2313 BID_RETURN (res);
2314}
2315}
200359e8 2316
b2a00c89
L
2317BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_ordered, x,
2318 y)
200359e8 2319
b2a00c89 2320 int res;
200359e8 2321
b2a00c89
L
2322 // NaN (CASE1)
2323 // if either number is NAN, the comparison is ordered : return 1
2324if (((x.w[1] & MASK_NAN) == MASK_NAN)
2325 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
2326if ((x.w[1] & MASK_SNAN) == MASK_SNAN
2327 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
2328 *pfpsf |= INVALID_EXCEPTION;
2329}
2330{
2331 res = 0;
2332 BID_RETURN (res);
2333}
2334}
2335{
2336 res = 1;
2337 BID_RETURN (res);
2338}
2339}
200359e8 2340
b2a00c89
L
2341BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_quiet_unordered,
2342 x, y)
200359e8 2343
b2a00c89 2344 int res;
200359e8 2345
b2a00c89
L
2346 // NaN (CASE1)
2347 // if either number is NAN, the comparison is unordered : return 1
2348if (((x.w[1] & MASK_NAN) == MASK_NAN)
2349 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
2350if ((x.w[1] & MASK_SNAN) == MASK_SNAN
2351 || (y.w[1] & MASK_SNAN) == MASK_SNAN) {
2352 *pfpsf |= INVALID_EXCEPTION;
2353}
2354{
2355 res = 1;
2356 BID_RETURN (res);
2357}
2358}
2359{
2360 res = 0;
2361 BID_RETURN (res);
2362}
200359e8
L
2363}
2364
b2a00c89
L
2365BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_signaling_greater,
2366 x, y)
200359e8 2367
b2a00c89
L
2368 int res;
2369 int exp_x, exp_y;
2370 int diff;
2371 UINT128 sig_x, sig_y;
2372 UINT192 sig_n_prime192;
2373 UINT256 sig_n_prime256;
2374 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
2375
2376 // NaN (CASE1)
2377 // if either number is NAN, the comparison is unordered,
2378 // rather than equal : return 0
b2a00c89
L
2379if (((x.w[1] & MASK_NAN) == MASK_NAN)
2380 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
2381*pfpsf |= INVALID_EXCEPTION;
2382{
2383 res = 0;
2384 BID_RETURN (res);
2385}
2386}
200359e8
L
2387 // SIMPLE (CASE2)
2388 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
2389if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
2390 res = 0;
2391 BID_RETURN (res);
2392}
2393 // INFINITY (CASE3)
2394if ((x.w[1] & MASK_INF) == MASK_INF) {
2395 // if x is neg infinity, there is no way it is greater than y, return 0
2396 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
2397 res = 0;
2398 BID_RETURN (res);
2399 }
b2a00c89
L
2400 // x is pos infinity, it is greater, unless y is positive infinity => return y!=pos_infinity
2401 else {
2402 res = (((y.w[1] & MASK_INF) != MASK_INF)
2403 || ((y.w[1] & MASK_SIGN) == MASK_SIGN));
2404 BID_RETURN (res);
2405 }
2406} else if ((y.w[1] & MASK_INF) == MASK_INF) {
2407 // x is finite, so if y is positive infinity, then x is less, return 0
2408 // if y is negative infinity, then x is greater, return 1
2409 {
2410 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2411 BID_RETURN (res);
200359e8 2412 }
b2a00c89 2413}
200359e8 2414 // CONVERT X
b2a00c89
L
2415sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
2416sig_x.w[0] = x.w[0];
2417exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
2418
2419 // CHECK IF X IS CANONICAL
2420 // 9999999999999999999999999999999999(decimal) =
2421 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2422 // [0, 10^34) is the 754r supported canonical range.
2423 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2424if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
2425 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
2426 && (sig_x.w[0] > 0x378d8e63ffffffffull))
2427 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2428 non_canon_x = 1;
2429else
2430 non_canon_x = 0;
200359e8
L
2431
2432 // CONVERT Y
b2a00c89
L
2433exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
2434sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
2435sig_y.w[0] = y.w[0];
200359e8
L
2436
2437 // CHECK IF Y IS CANONICAL
2438 // 9999999999999999999999999999999999(decimal) =
2439 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2440 // [0, 10^34) is the 754r supported canonical range.
2441 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2442if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
2443 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
2444 && (sig_y.w[0] > 0x378d8e63ffffffffull))
2445 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2446 non_canon_y = 1;
2447else
2448 non_canon_y = 0;
200359e8
L
2449
2450 // ZERO (CASE4)
2451 // some properties:
2452 // (+ZERO == -ZERO) => therefore ignore the sign
2453 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
2454 // ignore the exponent field
2455 // (Any non-canonical # is considered 0)
b2a00c89
L
2456if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
2457 x_is_zero = 1;
2458}
2459if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
2460 y_is_zero = 1;
2461}
200359e8 2462 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
2463if (x_is_zero && y_is_zero) {
2464 res = 0;
2465 BID_RETURN (res);
2466}
200359e8 2467 // is x is zero, it is greater if Y is negative
b2a00c89
L
2468else if (x_is_zero) {
2469 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2470 BID_RETURN (res);
2471}
200359e8 2472 // is y is zero, X is greater if it is positive
b2a00c89
L
2473else if (y_is_zero) {
2474 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2475 BID_RETURN (res);
2476}
200359e8
L
2477 // OPPOSITE SIGN (CASE5)
2478 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
2479if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
2480 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2481 BID_RETURN (res);
2482}
200359e8
L
2483 // REDUNDANT REPRESENTATIONS (CASE6)
2484 // if exponents are the same, then we have a simple comparison
2485 // of the significands
b2a00c89
L
2486if (exp_y == exp_x) {
2487 res = (((sig_x.w[1] > sig_y.w[1])
2488 || (sig_x.w[1] == sig_y.w[1]
2489 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
2490 MASK_SIGN));
2491 BID_RETURN (res);
2492}
200359e8
L
2493 // if both components are either bigger or smaller,
2494 // it is clear what needs to be done
b2a00c89
L
2495if ((sig_x.w[1] > sig_y.w[1]
2496 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
2497 && exp_x >= exp_y) {
2498 {
2499 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2500 BID_RETURN (res);
200359e8 2501 }
b2a00c89
L
2502}
2503if ((sig_x.w[1] < sig_y.w[1]
2504 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
2505 && exp_x <= exp_y) {
2506 {
2507 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
2508 BID_RETURN (res);
200359e8 2509 }
b2a00c89 2510}
200359e8 2511
b2a00c89 2512diff = exp_x - exp_y;
200359e8
L
2513
2514 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 2515if (diff > 0) { // to simplify the loop below,
200359e8 2516
b2a00c89
L
2517 // if exp_x is 33 greater than exp_y, no need for compensation
2518 if (diff > 33) {
2519 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2520 BID_RETURN (res);
2521 } // difference cannot be greater than 10^33
200359e8 2522
b2a00c89
L
2523 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
2524 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8
L
2525
2526 // if postitive, return whichever significand is larger
2527 // (converse if negative)
b2a00c89
L
2528 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
2529 && sig_n_prime256.w[1] == sig_y.w[1]
2530 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
2531 res = 0;
2532 BID_RETURN (res);
b2a00c89 2533 } // if equal, return 0
200359e8 2534 {
b2a00c89
L
2535 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
2536 || (sig_n_prime256.w[1] > sig_y.w[1])
2537 || (sig_n_prime256.w[1] == sig_y.w[1]
2538 && sig_n_prime256.w[0] >
2539 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2540 BID_RETURN (res);
2541 }
2542 }
b2a00c89
L
2543 //else { //128 by 64 bit multiply -> 192 bits
2544 __mul_64x128_to_192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 2545
b2a00c89
L
2546 // if postitive, return whichever significand is larger
2547 // (converse if negative)
2548 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
2549 && (sig_n_prime192.w[0] == sig_y.w[0])) {
2550 res = 0;
2551 BID_RETURN (res);
2552 } // if equal, return 0
2553 {
2554 res = (((sig_n_prime192.w[2] > 0)
2555 || (sig_n_prime192.w[1] > sig_y.w[1])
2556 || (sig_n_prime192.w[1] == sig_y.w[1]
2557 && sig_n_prime192.w[0] >
2558 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2559 BID_RETURN (res);
2560 }
b2a00c89 2561}
200359e8 2562
b2a00c89 2563diff = exp_y - exp_x;
200359e8 2564
b2a00c89
L
2565 // if exp_x is 33 less than exp_y, no need for compensation
2566if (diff > 33) {
2567 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
2568 BID_RETURN (res);
2569}
2570
2571if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 2572 // adjust the y significand upwards
b2a00c89 2573 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8
L
2574
2575 // if postitive, return whichever significand is larger
2576 // (converse if negative)
b2a00c89
L
2577 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
2578 && sig_n_prime256.w[1] == sig_x.w[1]
2579 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
2580 res = 0;
2581 BID_RETURN (res);
b2a00c89 2582 } // if equal, return 0
200359e8 2583 {
b2a00c89
L
2584 res =
2585 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
2586 || (sig_n_prime256.w[1] > sig_x.w[1]
2587 || (sig_n_prime256.w[1] == sig_x.w[1]
2588 && sig_n_prime256.w[0] >
2589 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
2590 BID_RETURN (res);
2591 }
2592}
b2a00c89
L
2593 //else { //128 by 64 bit multiply -> 192 bits
2594 // adjust the y significand upwards
2595__mul_64x128_to_192 (sig_n_prime192, ten2k64[diff], sig_y);
200359e8 2596
b2a00c89
L
2597 // if postitive, return whichever significand is larger
2598 // (converse if negative)
2599if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
2600 && (sig_n_prime192.w[0] == sig_x.w[0])) {
2601 res = 0;
2602 BID_RETURN (res);
2603} // if equal, return 0
2604{
2605 res = (sig_n_prime192.w[2] != 0
2606 || (sig_n_prime192.w[1] > sig_x.w[1]
2607 || (sig_n_prime192.w[1] == sig_x.w[1]
2608 && sig_n_prime192.w[0] >
2609 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN);
2610 BID_RETURN (res);
2611}
2612}
2613
2614BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
2615 bid128_signaling_greater_equal,
2616 x, y)
200359e8 2617
b2a00c89
L
2618 int res;
2619 int exp_x, exp_y;
2620 int diff;
2621 UINT128 sig_x, sig_y;
2622 UINT192 sig_n_prime192;
2623 UINT256 sig_n_prime256;
2624 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
2625
2626 // NaN (CASE1)
2627 // if either number is NAN, the comparison is unordered,
2628 // rather than equal : return 1
b2a00c89
L
2629if (((x.w[1] & MASK_NAN) == MASK_NAN)
2630 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
2631*pfpsf |= INVALID_EXCEPTION;
2632{
2633 res = 0;
2634 BID_RETURN (res);
2635}
2636}
200359e8
L
2637 // SIMPLE (CASE2)
2638 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
2639if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
2640 res = 1;
2641 BID_RETURN (res);
2642}
2643 // INFINITY (CASE3)
2644if ((x.w[1] & MASK_INF) == MASK_INF) {
2645 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
2646 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
2647 // x is -inf, so it is less than y unless y is -inf
2648 {
2649 res = (((y.w[1] & MASK_INF) == MASK_INF)
2650 && (y.w[1] & MASK_SIGN) == MASK_SIGN);
2651 BID_RETURN (res);
2652 } else
2653 // x is pos_inf, no way for it to be less than y
2654 {
200359e8
L
2655 res = 1;
2656 BID_RETURN (res);
2657 }
b2a00c89
L
2658} else if ((y.w[1] & MASK_INF) == MASK_INF) {
2659 // x is finite, so if y is positive infinity, then x is less, return 0
2660 // if y is negative infinity, then x is greater, return 1
2661 {
2662 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2663 BID_RETURN (res);
200359e8 2664 }
b2a00c89 2665}
200359e8 2666 // CONVERT X
b2a00c89
L
2667sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
2668sig_x.w[0] = x.w[0];
2669exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
2670
2671 // CHECK IF X IS CANONICAL
2672 // 9999999999999999999999999999999999(decimal) =
2673 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2674 // [0, 10^34) is the 754r supported canonical range.
2675 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2676if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
2677 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
2678 && (sig_x.w[0] > 0x378d8e63ffffffffull))
2679 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2680 non_canon_x = 1;
2681else
2682 non_canon_x = 0;
200359e8
L
2683
2684 // CONVERT Y
b2a00c89
L
2685exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
2686sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
2687sig_y.w[0] = y.w[0];
200359e8
L
2688
2689 // CHECK IF Y IS CANONICAL
2690 // 9999999999999999999999999999999999(decimal) =
2691 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2692 // [0, 10^34) is the 754r supported canonical range.
2693 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2694if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
2695 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
2696 && (sig_y.w[0] > 0x378d8e63ffffffffull))
2697 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2698 non_canon_y = 1;
2699else
2700 non_canon_y = 0;
200359e8
L
2701
2702 // ZERO (CASE4)
2703 // some properties:
2704 // (+ZERO == -ZERO) => therefore ignore the sign
2705 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
2706 // ignore the exponent field
2707 // (Any non-canonical # is considered 0)
b2a00c89
L
2708if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
2709 x_is_zero = 1;
2710}
2711if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
2712 y_is_zero = 1;
2713}
200359e8 2714 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
2715if (x_is_zero && y_is_zero) {
2716 res = 1;
2717 BID_RETURN (res);
2718}
200359e8 2719 // is x is zero, it is greater if Y is negative
b2a00c89
L
2720else if (x_is_zero) {
2721 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2722 BID_RETURN (res);
2723}
200359e8 2724 // is y is zero, X is greater if it is positive
b2a00c89
L
2725else if (y_is_zero) {
2726 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2727 BID_RETURN (res);
2728}
200359e8
L
2729 // OPPOSITE SIGN (CASE5)
2730 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
2731if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
2732 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2733 BID_RETURN (res);
2734}
200359e8
L
2735 // REDUNDANT REPRESENTATIONS (CASE6)
2736 // if exponents are the same, then we have a simple comparison
2737 // of the significands
b2a00c89
L
2738if (exp_y == exp_x) {
2739 res = (((sig_x.w[1] > sig_y.w[1])
2740 || (sig_x.w[1] == sig_y.w[1]
2741 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
2742 MASK_SIGN));
2743 BID_RETURN (res);
2744}
200359e8
L
2745 // if both components are either bigger or smaller,
2746 // it is clear what needs to be done
b2a00c89
L
2747if (sig_x.w[1] >= sig_y.w[1] && sig_x.w[0] >= sig_y.w[0]
2748 && exp_x > exp_y) {
2749 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2750 BID_RETURN (res);
2751}
2752if (sig_x.w[1] <= sig_y.w[1] && sig_x.w[0] <= sig_y.w[0]
2753 && exp_x < exp_y) {
2754 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
2755 BID_RETURN (res);
2756}
200359e8 2757
b2a00c89 2758diff = exp_x - exp_y;
200359e8
L
2759
2760 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 2761if (diff > 0) { // to simplify the loop below,
200359e8 2762
b2a00c89 2763 // if exp_x is 33 greater than exp_y, no need for compensation
200359e8 2764 if (diff > 33) {
b2a00c89 2765 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
200359e8 2766 BID_RETURN (res);
b2a00c89 2767 } // difference cannot be greater than 10^33
200359e8 2768
b2a00c89
L
2769 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
2770 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8
L
2771
2772
2773 // if postitive, return whichever significand is larger
2774 // (converse if negative)
2775 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
b2a00c89
L
2776 && sig_n_prime256.w[1] == sig_y.w[1]
2777 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
2778 res = 1;
2779 BID_RETURN (res);
b2a00c89 2780 } // if equal, return 1
200359e8 2781 {
b2a00c89
L
2782 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
2783 || (sig_n_prime256.w[1] > sig_y.w[1])
2784 || (sig_n_prime256.w[1] == sig_y.w[1]
2785 && sig_n_prime256.w[0] >
2786 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2787 BID_RETURN (res);
2788 }
2789 }
2790 //else { //128 by 64 bit multiply -> 192 bits
b2a00c89
L
2791 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
2792
2793 // if postitive, return whichever significand is larger
2794 // (converse if negative)
2795 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
2796 && (sig_n_prime192.w[0] == sig_y.w[0])) {
2797 res = 1;
2798 BID_RETURN (res);
2799 } // if equal, return 1
2800 {
2801 res = (((sig_n_prime192.w[2] > 0)
2802 || (sig_n_prime192.w[1] > sig_y.w[1])
2803 || (sig_n_prime192.w[1] == sig_y.w[1]
2804 && sig_n_prime192.w[0] >
2805 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
2806 BID_RETURN (res);
2807 }
2808}
2809
2810diff = exp_y - exp_x;
2811
2812 // if exp_x is 33 less than exp_y, no need for compensation
2813if (diff > 33) {
2814 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
2815 BID_RETURN (res);
2816}
2817
2818if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 2819 // adjust the y significand upwards
b2a00c89
L
2820 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
2821
200359e8
L
2822
2823 // if postitive, return whichever significand is larger
2824 // (converse if negative)
b2a00c89
L
2825 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
2826 && sig_n_prime256.w[1] == sig_x.w[1]
2827 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
2828 res = 1;
2829 BID_RETURN (res);
b2a00c89 2830 } // if equal, return 1
200359e8 2831 {
b2a00c89
L
2832 res =
2833 ((sig_n_prime256.w[3] == 0 && sig_n_prime256.w[2] == 0
2834 && (sig_n_prime256.w[1] < sig_x.w[1]
2835 || (sig_n_prime256.w[1] == sig_x.w[1]
2836 && sig_n_prime256.w[0] <
2837 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
2838 BID_RETURN (res);
2839 }
b2a00c89
L
2840}
2841 //else { //128 by 64 bit multiply -> 192 bits
2842 // adjust the y significand upwards
2843__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
2844
2845 // if postitive, return whichever significand is larger
2846 // (converse if negative)
2847if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
2848 && (sig_n_prime192.w[0] == sig_x.w[0])) {
2849 res = 1;
2850 BID_RETURN (res);
2851} // if equal, return 1
2852{
2853 res = (sig_n_prime192.w[2] == 0
2854 && (sig_n_prime192.w[1] < sig_x.w[1]
2855 || (sig_n_prime192.w[1] == sig_x.w[1]
2856 && sig_n_prime192.w[0] <
2857 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2858 BID_RETURN (res);
2859}
200359e8
L
2860}
2861
b2a00c89
L
2862BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
2863 bid128_signaling_greater_unordered,
2864 x, y)
200359e8 2865
b2a00c89
L
2866 int res;
2867 int exp_x, exp_y;
2868 int diff;
2869 UINT128 sig_x, sig_y;
2870 UINT192 sig_n_prime192;
2871 UINT256 sig_n_prime256;
2872 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
2873
2874 // NaN (CASE1)
2875 // if either number is NAN, the comparison is unordered,
2876 // rather than equal : return 1
b2a00c89
L
2877if (((x.w[1] & MASK_NAN) == MASK_NAN)
2878 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
2879*pfpsf |= INVALID_EXCEPTION;
2880{
2881 res = 1;
2882 BID_RETURN (res);
2883}
2884}
200359e8
L
2885 // SIMPLE (CASE2)
2886 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
2887if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
2888 res = 0;
2889 BID_RETURN (res);
2890}
2891 // INFINITY (CASE3)
2892if ((x.w[1] & MASK_INF) == MASK_INF) {
2893 // if x is neg infinity, there is no way it is greater than y, return 0
2894 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
2895 res = 0;
2896 BID_RETURN (res);
2897 }
b2a00c89
L
2898 // x is pos infinity, it is greater, unless y is positive infinity => return y!=pos_infinity
2899 else {
2900 res = (((y.w[1] & MASK_INF) != MASK_INF)
2901 || ((y.w[1] & MASK_SIGN) == MASK_SIGN));
2902 BID_RETURN (res);
2903 }
2904} else if ((y.w[1] & MASK_INF) == MASK_INF) {
2905 // x is finite, so if y is positive infinity, then x is less, return 0
2906 // if y is negative infinity, then x is greater, return 1
2907 {
2908 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2909 BID_RETURN (res);
200359e8 2910 }
b2a00c89 2911}
200359e8 2912 // CONVERT X
b2a00c89
L
2913sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
2914sig_x.w[0] = x.w[0];
2915exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
2916
2917 // CHECK IF X IS CANONICAL
2918 // 9999999999999999999999999999999999(decimal) =
2919 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2920 // [0, 10^34) is the 754r supported canonical range.
2921 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2922if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
2923 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
2924 && (sig_x.w[0] > 0x378d8e63ffffffffull))
2925 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2926 non_canon_x = 1;
2927else
2928 non_canon_x = 0;
200359e8
L
2929
2930 // CONVERT Y
b2a00c89
L
2931exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
2932sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
2933sig_y.w[0] = y.w[0];
200359e8
L
2934
2935 // CHECK IF Y IS CANONICAL
2936 // 9999999999999999999999999999999999(decimal) =
2937 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
2938 // [0, 10^34) is the 754r supported canonical range.
2939 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
2940if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
2941 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
2942 && (sig_y.w[0] > 0x378d8e63ffffffffull))
2943 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
2944 non_canon_y = 1;
2945else
2946 non_canon_y = 0;
200359e8
L
2947
2948 // ZERO (CASE4)
2949 // some properties:
2950 // (+ZERO == -ZERO) => therefore ignore the sign
2951 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
2952 // ignore the exponent field
2953 // (Any non-canonical # is considered 0)
b2a00c89
L
2954if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
2955 x_is_zero = 1;
2956}
2957if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
2958 y_is_zero = 1;
2959}
200359e8 2960 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
2961if (x_is_zero && y_is_zero) {
2962 res = 0;
2963 BID_RETURN (res);
2964}
200359e8 2965 // is x is zero, it is greater if Y is negative
b2a00c89
L
2966else if (x_is_zero) {
2967 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2968 BID_RETURN (res);
2969}
200359e8 2970 // is y is zero, X is greater if it is positive
b2a00c89
L
2971else if (y_is_zero) {
2972 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2973 BID_RETURN (res);
2974}
200359e8
L
2975 // OPPOSITE SIGN (CASE5)
2976 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
2977if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
2978 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
2979 BID_RETURN (res);
2980}
200359e8
L
2981 // REDUNDANT REPRESENTATIONS (CASE6)
2982 // if exponents are the same, then we have a simple comparison
2983 // of the significands
b2a00c89
L
2984if (exp_y == exp_x) {
2985 res = (((sig_x.w[1] > sig_y.w[1])
2986 || (sig_x.w[1] == sig_y.w[1]
2987 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
2988 MASK_SIGN));
2989 BID_RETURN (res);
2990}
200359e8
L
2991 // if both components are either bigger or smaller,
2992 // it is clear what needs to be done
b2a00c89
L
2993if (sig_x.w[1] >= sig_y.w[1] && sig_x.w[0] >= sig_y.w[0]
2994 && exp_x > exp_y) {
2995 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
2996 BID_RETURN (res);
2997}
2998if (sig_x.w[1] <= sig_y.w[1] && sig_x.w[0] <= sig_y.w[0]
2999 && exp_x < exp_y) {
3000 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3001 BID_RETURN (res);
3002}
200359e8 3003
b2a00c89 3004diff = exp_x - exp_y;
200359e8
L
3005
3006 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 3007if (diff > 0) { // to simplify the loop below,
200359e8 3008
b2a00c89
L
3009 // if exp_x is 33 greater than exp_y, no need for compensation
3010 if (diff > 33) {
3011 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3012 BID_RETURN (res);
3013 } // difference cannot be greater than 10^33
200359e8 3014
b2a00c89
L
3015 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
3016 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 3017
200359e8
L
3018
3019 // if postitive, return whichever significand is larger
3020 // (converse if negative)
b2a00c89
L
3021 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3022 && sig_n_prime256.w[1] == sig_y.w[1]
3023 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
3024 res = 0;
3025 BID_RETURN (res);
b2a00c89 3026 } // if equal, return 0
200359e8 3027 {
b2a00c89
L
3028 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
3029 || (sig_n_prime256.w[1] > sig_y.w[1])
3030 || (sig_n_prime256.w[1] == sig_y.w[1]
3031 && sig_n_prime256.w[0] >
3032 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
3033 BID_RETURN (res);
3034 }
3035 }
b2a00c89
L
3036 //else { //128 by 64 bit multiply -> 192 bits
3037 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 3038
b2a00c89
L
3039 // if postitive, return whichever significand is larger
3040 // (converse if negative)
3041 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
3042 && (sig_n_prime192.w[0] == sig_y.w[0])) {
3043 res = 0;
3044 BID_RETURN (res);
3045 } // if equal, return 0
3046 {
3047 res = (((sig_n_prime192.w[2] > 0)
3048 || (sig_n_prime192.w[1] > sig_y.w[1])
3049 || (sig_n_prime192.w[1] == sig_y.w[1]
3050 && sig_n_prime192.w[0] >
3051 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
3052 BID_RETURN (res);
3053 }
b2a00c89 3054}
200359e8 3055
b2a00c89 3056diff = exp_y - exp_x;
200359e8 3057
b2a00c89
L
3058 // if exp_x is 33 less than exp_y, no need for compensation
3059if (diff > 33) {
3060 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3061 BID_RETURN (res);
3062}
200359e8 3063
b2a00c89 3064if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 3065 // adjust the y significand upwards
b2a00c89
L
3066 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
3067
200359e8
L
3068
3069 // if postitive, return whichever significand is larger
3070 // (converse if negative)
b2a00c89
L
3071 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3072 && sig_n_prime256.w[1] == sig_x.w[1]
3073 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
3074 res = 0;
3075 BID_RETURN (res);
b2a00c89 3076 } // if equal, return 0
200359e8 3077 {
b2a00c89
L
3078 res =
3079 ((sig_n_prime256.w[3] == 0 && sig_n_prime256.w[2] == 0
3080 && (sig_n_prime256.w[1] < sig_x.w[1]
3081 || (sig_n_prime256.w[1] == sig_x.w[1]
3082 && sig_n_prime256.w[0] <
3083 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
3084 BID_RETURN (res);
3085 }
b2a00c89
L
3086}
3087 //else { //128 by 64 bit multiply -> 192 bits
3088 // adjust the y significand upwards
3089__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
3090
3091 // if postitive, return whichever significand is larger
3092 // (converse if negative)
3093if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
3094 && (sig_n_prime192.w[0] == sig_x.w[0])) {
3095 res = 0;
3096 BID_RETURN (res);
3097} // if equal, return 0
3098{
3099 res = (sig_n_prime192.w[2] == 0
3100 && (sig_n_prime192.w[1] < sig_x.w[1]
3101 || (sig_n_prime192.w[1] == sig_x.w[1]
3102 && sig_n_prime192.w[0] <
3103 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
3104 BID_RETURN (res);
3105}
200359e8
L
3106}
3107
b2a00c89
L
3108BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int, bid128_signaling_less, x,
3109 y)
200359e8 3110
b2a00c89
L
3111 int res;
3112 int exp_x, exp_y;
3113 int diff;
3114 UINT128 sig_x, sig_y;
3115 UINT192 sig_n_prime192;
3116 UINT256 sig_n_prime256;
3117 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
3118
3119 // NaN (CASE1)
3120 // if either number is NAN, the comparison is unordered,
3121 // rather than equal : return 0
b2a00c89
L
3122if (((x.w[1] & MASK_NAN) == MASK_NAN)
3123 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
3124*pfpsf |= INVALID_EXCEPTION;
3125{
3126 res = 0;
3127 BID_RETURN (res);
3128}
3129}
200359e8
L
3130 // SIMPLE (CASE2)
3131 // if all the bits are the same, these numbers are equal.
b2a00c89
L
3132if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
3133 res = 0;
3134 BID_RETURN (res);
3135}
3136 // INFINITY (CASE3)
3137if ((x.w[1] & MASK_INF) == MASK_INF) {
3138 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
3139 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
3140 // x is -inf, so it is less than y unless y is -inf
3141 {
3142 res = (((y.w[1] & MASK_INF) != MASK_INF)
3143 || (y.w[1] & MASK_SIGN) != MASK_SIGN);
3144 BID_RETURN (res);
3145 } else
3146 // x is pos_inf, no way for it to be less than y
3147 {
200359e8
L
3148 res = 0;
3149 BID_RETURN (res);
3150 }
b2a00c89
L
3151} else if ((y.w[1] & MASK_INF) == MASK_INF) {
3152 // x is finite, so if y is positive infinity, then x is less, return 0
3153 // if y is negative infinity, then x is greater, return 1
3154 {
3155 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3156 BID_RETURN (res);
200359e8 3157 }
b2a00c89 3158}
200359e8 3159 // CONVERT X
b2a00c89
L
3160sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
3161sig_x.w[0] = x.w[0];
3162exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
3163
3164 // CHECK IF X IS CANONICAL
3165 // 9999999999999999999999999999999999(decimal) =
3166 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3167 // [0, 10^34) is the 754r supported canonical range.
3168 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3169if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
3170 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
3171 && (sig_x.w[0] > 0x378d8e63ffffffffull))
3172 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3173 non_canon_x = 1;
3174else
3175 non_canon_x = 0;
200359e8
L
3176
3177 // CONVERT Y
b2a00c89
L
3178exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
3179sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
3180sig_y.w[0] = y.w[0];
200359e8
L
3181
3182 // CHECK IF Y IS CANONICAL
3183 // 9999999999999999999999999999999999(decimal) =
3184 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3185 // [0, 10^34) is the 754r supported canonical range.
3186 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3187if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
3188 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
3189 && (sig_y.w[0] > 0x378d8e63ffffffffull))
3190 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3191 non_canon_y = 1;
3192else
3193 non_canon_y = 0;
200359e8
L
3194
3195 // ZERO (CASE4)
3196 // some properties:
3197 // (+ZERO == -ZERO) => therefore ignore the sign
3198 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
3199 // ignore the exponent field
3200 // (Any non-canonical # is considered 0)
b2a00c89
L
3201if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
3202 x_is_zero = 1;
3203}
3204if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
3205 y_is_zero = 1;
3206}
200359e8 3207 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
3208if (x_is_zero && y_is_zero) {
3209 res = 0;
3210 BID_RETURN (res);
3211}
200359e8 3212 // is x is zero, it is greater if Y is negative
b2a00c89
L
3213else if (x_is_zero) {
3214 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3215 BID_RETURN (res);
3216}
200359e8 3217 // is y is zero, X is greater if it is positive
b2a00c89
L
3218else if (y_is_zero) {
3219 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3220 BID_RETURN (res);
3221}
200359e8
L
3222 // OPPOSITE SIGN (CASE5)
3223 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
3224if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
3225 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3226 BID_RETURN (res);
3227}
200359e8
L
3228 // REDUNDANT REPRESENTATIONS (CASE6)
3229 // if exponents are the same, then we have a simple comparison
3230 // of the significands
b2a00c89
L
3231if (exp_y == exp_x) {
3232 res = (((sig_x.w[1] > sig_y.w[1])
3233 || (sig_x.w[1] == sig_y.w[1]
3234 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
3235 MASK_SIGN));
3236 BID_RETURN (res);
3237}
200359e8
L
3238 // if both components are either bigger or smaller,
3239 // it is clear what needs to be done
b2a00c89
L
3240if ((sig_x.w[1] > sig_y.w[1]
3241 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
3242 && exp_x >= exp_y) {
3243 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3244 BID_RETURN (res);
3245}
3246if ((sig_x.w[1] < sig_y.w[1]
3247 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
3248 && exp_x <= exp_y) {
3249 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3250 BID_RETURN (res);
3251}
200359e8 3252
b2a00c89 3253diff = exp_x - exp_y;
200359e8
L
3254
3255 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 3256if (diff > 0) { // to simplify the loop below,
200359e8 3257
b2a00c89
L
3258 // if exp_x is 33 greater than exp_y, no need for compensation
3259 if (diff > 33) {
3260 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3261 BID_RETURN (res);
3262 } // difference cannot be greater than 10^33
200359e8 3263
b2a00c89
L
3264 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
3265 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 3266
200359e8
L
3267
3268 // if postitive, return whichever significand is larger
3269 // (converse if negative)
b2a00c89
L
3270 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3271 && sig_n_prime256.w[1] == sig_y.w[1]
3272 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
3273 res = 0;
3274 BID_RETURN (res);
b2a00c89 3275 } // if equal, return 0
200359e8 3276 {
b2a00c89
L
3277 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
3278 || (sig_n_prime256.w[1] > sig_y.w[1])
3279 || (sig_n_prime256.w[1] == sig_y.w[1]
3280 && sig_n_prime256.w[0] >
3281 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
3282 BID_RETURN (res);
3283 }
3284 }
b2a00c89
L
3285 //else { //128 by 64 bit multiply -> 192 bits
3286 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 3287
b2a00c89
L
3288 // if postitive, return whichever significand is larger
3289 // (converse if negative)
3290 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
3291 && (sig_n_prime192.w[0] == sig_y.w[0])) {
3292 res = 0;
3293 BID_RETURN (res);
3294 } // if equal, return 0
3295 {
3296 res = (((sig_n_prime192.w[2] > 0)
3297 || (sig_n_prime192.w[1] > sig_y.w[1])
3298 || (sig_n_prime192.w[1] == sig_y.w[1]
3299 && sig_n_prime192.w[0] >
3300 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
3301 BID_RETURN (res);
3302 }
b2a00c89 3303}
200359e8 3304
b2a00c89 3305diff = exp_y - exp_x;
200359e8 3306
b2a00c89
L
3307 // if exp_x is 33 less than exp_y, |x| < |y|, return 1 if positive
3308if (diff > 33) {
3309 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3310 BID_RETURN (res);
3311}
200359e8 3312
b2a00c89 3313if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 3314 // adjust the y significand upwards
b2a00c89
L
3315 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
3316
200359e8
L
3317
3318 // if postitive, return whichever significand is larger
3319 // (converse if negative)
b2a00c89
L
3320 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3321 && sig_n_prime256.w[1] == sig_x.w[1]
3322 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
3323 res = 0;
3324 BID_RETURN (res);
b2a00c89 3325 } // if equal, return 1
200359e8 3326 {
b2a00c89
L
3327 res =
3328 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
3329 || (sig_n_prime256.w[1] > sig_x.w[1]
3330 || (sig_n_prime256.w[1] == sig_x.w[1]
3331 && sig_n_prime256.w[0] >
3332 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
3333 BID_RETURN (res);
3334 }
b2a00c89
L
3335}
3336 //else { //128 by 64 bit multiply -> 192 bits
3337 // adjust the y significand upwards
3338__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
3339
3340 // if postitive, return whichever significand is larger
3341 // (converse if negative)
3342if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
3343 && (sig_n_prime192.w[0] == sig_x.w[0])) {
3344 res = 0;
3345 BID_RETURN (res);
3346} // if equal, return 0
3347{
3348 res = (sig_n_prime192.w[2] != 0
3349 || (sig_n_prime192.w[1] > sig_x.w[1]
3350 || (sig_n_prime192.w[1] == sig_x.w[1]
3351 && sig_n_prime192.w[0] >
3352 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
3353 BID_RETURN (res);
3354}
200359e8
L
3355}
3356
b2a00c89
L
3357BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
3358 bid128_signaling_less_equal,
3359 x, y)
200359e8 3360
b2a00c89
L
3361 int res;
3362 int exp_x, exp_y;
3363 int diff;
3364 UINT128 sig_x, sig_y;
3365 UINT192 sig_n_prime192;
3366 UINT256 sig_n_prime256;
3367 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
3368
3369 // NaN (CASE1)
3370 // if either number is NAN, the comparison is unordered,
3371 // rather than equal : return 0
b2a00c89
L
3372if (((x.w[1] & MASK_NAN) == MASK_NAN)
3373 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
3374*pfpsf |= INVALID_EXCEPTION;
3375{
3376 res = 0;
3377 BID_RETURN (res);
3378}
3379}
200359e8
L
3380 // SIMPLE (CASE2)
3381 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
3382if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
3383 res = 1;
3384 BID_RETURN (res);
3385}
3386 // INFINITY (CASE3)
3387if ((x.w[1] & MASK_INF) == MASK_INF) {
3388 // if x is neg infinity, there is no way it is greater than y, return 1
3389 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
3390 res = 1;
3391 BID_RETURN (res);
3392 }
b2a00c89
L
3393 // x is pos infinity, it is greater, unless y is positive infinity => return y!=pos_infinity
3394 else {
3395 res = (((y.w[1] & MASK_INF) == MASK_INF)
3396 && ((y.w[1] & MASK_SIGN) != MASK_SIGN));
3397 BID_RETURN (res);
200359e8 3398 }
b2a00c89
L
3399} else if ((y.w[1] & MASK_INF) == MASK_INF) {
3400 // x is finite, so if y is positive infinity, then x is less, return 0
3401 // if y is negative infinity, then x is greater, return 1
3402 {
3403 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3404 BID_RETURN (res);
3405 }
3406}
200359e8 3407 // CONVERT X
b2a00c89
L
3408sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
3409sig_x.w[0] = x.w[0];
3410exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
3411
3412 // CHECK IF X IS CANONICAL
3413 // 9999999999999999999999999999999999(decimal) =
3414 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3415 // [0, 10^34) is the 754r supported canonical range.
3416 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3417if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
3418 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
3419 && (sig_x.w[0] > 0x378d8e63ffffffffull))
3420 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3421 non_canon_x = 1;
3422else
3423 non_canon_x = 0;
200359e8
L
3424
3425 // CONVERT Y
b2a00c89
L
3426exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
3427sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
3428sig_y.w[0] = y.w[0];
200359e8
L
3429
3430 // CHECK IF Y IS CANONICAL
3431 // 9999999999999999999999999999999999(decimal) =
3432 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3433 // [0, 10^34) is the 754r supported canonical range.
3434 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3435if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
3436 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
3437 && (sig_y.w[0] > 0x378d8e63ffffffffull))
3438 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3439 non_canon_y = 1;
3440else
3441 non_canon_y = 0;
200359e8
L
3442
3443 // ZERO (CASE4)
3444 // some properties:
3445 // (+ZERO == -ZERO) => therefore ignore the sign
3446 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
3447 // ignore the exponent field
3448 // (Any non-canonical # is considered 0)
b2a00c89
L
3449if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
3450 x_is_zero = 1;
3451}
3452if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
3453 y_is_zero = 1;
3454}
200359e8 3455 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
3456if (x_is_zero && y_is_zero) {
3457 res = 1;
3458 BID_RETURN (res);
3459}
200359e8 3460 // is x is zero, it is greater if Y is negative
b2a00c89
L
3461else if (x_is_zero) {
3462 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3463 BID_RETURN (res);
3464}
200359e8 3465 // is y is zero, X is greater if it is positive
b2a00c89
L
3466else if (y_is_zero) {
3467 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3468 BID_RETURN (res);
3469}
200359e8
L
3470 // OPPOSITE SIGN (CASE5)
3471 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
3472if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
3473 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3474 BID_RETURN (res);
3475}
200359e8
L
3476 // REDUNDANT REPRESENTATIONS (CASE6)
3477 // if exponents are the same, then we have a simple comparison
3478 // of the significands
b2a00c89
L
3479if (exp_y == exp_x) {
3480 res = (((sig_x.w[1] > sig_y.w[1])
3481 || (sig_x.w[1] == sig_y.w[1]
3482 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
3483 MASK_SIGN));
3484 BID_RETURN (res);
3485}
200359e8
L
3486 // if both components are either bigger or smaller,
3487 // it is clear what needs to be done
b2a00c89
L
3488if ((sig_x.w[1] > sig_y.w[1]
3489 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
3490 && exp_x >= exp_y) {
3491 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3492 BID_RETURN (res);
3493}
3494if ((sig_x.w[1] < sig_y.w[1]
3495 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
3496 && exp_x <= exp_y) {
3497 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3498 BID_RETURN (res);
3499}
200359e8 3500
b2a00c89 3501diff = exp_x - exp_y;
200359e8
L
3502
3503 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 3504if (diff > 0) { // to simplify the loop below,
200359e8 3505
b2a00c89
L
3506 // if exp_x is 33 greater than exp_y, no need for compensation
3507 if (diff > 33) {
3508 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3509 BID_RETURN (res);
3510 } // difference cannot be greater than 10^33
200359e8 3511
b2a00c89
L
3512 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
3513 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 3514
200359e8
L
3515
3516 // if postitive, return whichever significand is larger
3517 // (converse if negative)
b2a00c89
L
3518 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3519 && sig_n_prime256.w[1] == sig_y.w[1]
3520 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
3521 res = 1;
3522 BID_RETURN (res);
b2a00c89 3523 } // if equal, return 0
200359e8 3524 {
b2a00c89
L
3525 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
3526 || (sig_n_prime256.w[1] > sig_y.w[1])
3527 || (sig_n_prime256.w[1] == sig_y.w[1]
3528 && sig_n_prime256.w[0] >
3529 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
3530 BID_RETURN (res);
3531 }
3532 }
b2a00c89
L
3533 //else { //128 by 64 bit multiply -> 192 bits
3534 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 3535
b2a00c89
L
3536 // if postitive, return whichever significand is larger
3537 // (converse if negative)
3538 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
3539 && (sig_n_prime192.w[0] == sig_y.w[0])) {
3540 res = 1;
3541 BID_RETURN (res);
3542 } // if equal, return 0
3543 {
3544 res = (((sig_n_prime192.w[2] > 0)
3545 || (sig_n_prime192.w[1] > sig_y.w[1])
3546 || (sig_n_prime192.w[1] == sig_y.w[1]
3547 && sig_n_prime192.w[0] >
3548 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
3549 BID_RETURN (res);
3550 }
b2a00c89 3551}
200359e8 3552
b2a00c89 3553diff = exp_y - exp_x;
200359e8 3554
b2a00c89
L
3555 // if exp_x is 33 less than exp_y, no need for compensation
3556if (diff > 33) {
3557 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3558 BID_RETURN (res);
3559}
200359e8 3560
b2a00c89 3561if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 3562 // adjust the y significand upwards
b2a00c89
L
3563 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
3564
200359e8
L
3565
3566 // if postitive, return whichever significand is larger
3567 // (converse if negative)
b2a00c89
L
3568 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3569 && sig_n_prime256.w[1] == sig_x.w[1]
3570 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
3571 res = 1;
3572 BID_RETURN (res);
b2a00c89 3573 } // if equal, return 0
200359e8 3574 {
b2a00c89
L
3575 res =
3576 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
3577 || (sig_n_prime256.w[1] > sig_x.w[1]
3578 || (sig_n_prime256.w[1] == sig_x.w[1]
3579 && sig_n_prime256.w[0] >
3580 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
3581 BID_RETURN (res);
3582 }
b2a00c89
L
3583}
3584 //else { //128 by 64 bit multiply -> 192 bits
3585 // adjust the y significand upwards
3586__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
3587
3588 // if postitive, return whichever significand is larger
3589 // (converse if negative)
3590if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
3591 && (sig_n_prime192.w[0] == sig_x.w[0])) {
3592 res = 1;
3593 BID_RETURN (res);
3594} // if equal, return 0
3595{
3596 res = (sig_n_prime192.w[2] != 0
3597 || (sig_n_prime192.w[1] > sig_x.w[1]
3598 || (sig_n_prime192.w[1] == sig_x.w[1]
3599 && sig_n_prime192.w[0] >
3600 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
3601 BID_RETURN (res);
3602}
200359e8
L
3603}
3604
b2a00c89
L
3605BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
3606 bid128_signaling_less_unordered,
3607 x, y)
200359e8 3608
b2a00c89
L
3609 int res;
3610 int exp_x, exp_y;
3611 int diff;
3612 UINT128 sig_x, sig_y;
3613 UINT192 sig_n_prime192;
3614 UINT256 sig_n_prime256;
3615 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
3616
3617 // NaN (CASE1)
3618 // if either number is NAN, the comparison is unordered
b2a00c89
L
3619if (((x.w[1] & MASK_NAN) == MASK_NAN)
3620 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
3621*pfpsf |= INVALID_EXCEPTION;
3622{
3623 res = 1;
3624 BID_RETURN (res);
3625}
3626}
200359e8
L
3627 // SIMPLE (CASE2)
3628 // if all the bits are the same, these numbers are equal.
b2a00c89
L
3629if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
3630 res = 0;
3631 BID_RETURN (res);
3632}
3633 // INFINITY (CASE3)
3634if ((x.w[1] & MASK_INF) == MASK_INF) {
3635 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
3636 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
3637 // x is -inf, so it is less than y unless y is -inf
3638 {
3639 res = (((y.w[1] & MASK_INF) != MASK_INF)
3640 || (y.w[1] & MASK_SIGN) != MASK_SIGN);
3641 BID_RETURN (res);
3642 } else
3643 // x is pos_inf, no way for it to be less than y
3644 {
200359e8
L
3645 res = 0;
3646 BID_RETURN (res);
3647 }
b2a00c89
L
3648} else if ((y.w[1] & MASK_INF) == MASK_INF) {
3649 // x is finite, so if y is positive infinity, then x is less, return 0
3650 // if y is negative infinity, then x is greater, return 1
3651 {
3652 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3653 BID_RETURN (res);
200359e8 3654 }
b2a00c89 3655}
200359e8 3656 // CONVERT X
b2a00c89
L
3657sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
3658sig_x.w[0] = x.w[0];
3659exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
3660
3661 // CHECK IF X IS CANONICAL
3662 // 9999999999999999999999999999999999(decimal) =
3663 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3664 // [0, 10^34) is the 754r supported canonical range.
3665 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3666if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
3667 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
3668 && (sig_x.w[0] > 0x378d8e63ffffffffull))
3669 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3670 non_canon_x = 1;
3671else
3672 non_canon_x = 0;
200359e8
L
3673
3674 // CONVERT Y
b2a00c89
L
3675exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
3676sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
3677sig_y.w[0] = y.w[0];
200359e8
L
3678
3679 // CHECK IF Y IS CANONICAL
3680 // 9999999999999999999999999999999999(decimal) =
3681 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3682 // [0, 10^34) is the 754r supported canonical range.
3683 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3684if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
3685 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
3686 && (sig_y.w[0] > 0x378d8e63ffffffffull))
3687 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3688 non_canon_y = 1;
3689else
3690 non_canon_y = 0;
200359e8
L
3691
3692 // ZERO (CASE4)
3693 // some properties:
3694 // (+ZERO == -ZERO) => therefore ignore the sign
3695 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
3696 // ignore the exponent field
3697 // (Any non-canonical # is considered 0)
b2a00c89
L
3698if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
3699 x_is_zero = 1;
3700}
3701if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
3702 y_is_zero = 1;
3703}
200359e8 3704 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
3705if (x_is_zero && y_is_zero) {
3706 res = 0;
3707 BID_RETURN (res);
3708}
200359e8 3709 // is x is zero, it is greater if Y is negative
b2a00c89
L
3710else if (x_is_zero) {
3711 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3712 BID_RETURN (res);
3713}
200359e8 3714 // is y is zero, X is greater if it is positive
b2a00c89
L
3715else if (y_is_zero) {
3716 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3717 BID_RETURN (res);
3718}
200359e8
L
3719 // OPPOSITE SIGN (CASE5)
3720 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
3721if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
3722 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3723 BID_RETURN (res);
3724}
200359e8
L
3725 // REDUNDANT REPRESENTATIONS (CASE6)
3726 // if exponents are the same, then we have a simple comparison
3727 // of the significands
b2a00c89
L
3728if (exp_y == exp_x) {
3729 res = (((sig_x.w[1] > sig_y.w[1])
3730 || (sig_x.w[1] == sig_y.w[1]
3731 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
3732 MASK_SIGN));
3733 BID_RETURN (res);
3734}
200359e8
L
3735 // if both components are either bigger or smaller,
3736 // it is clear what needs to be done
b2a00c89
L
3737if ((sig_x.w[1] > sig_y.w[1]
3738 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
3739 && exp_x >= exp_y) {
3740 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3741 BID_RETURN (res);
3742}
3743if ((sig_x.w[1] < sig_y.w[1]
3744 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
3745 && exp_x <= exp_y) {
3746 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3747 BID_RETURN (res);
3748}
200359e8 3749
b2a00c89 3750diff = exp_x - exp_y;
200359e8
L
3751
3752 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 3753if (diff > 0) { // to simplify the loop below,
200359e8 3754
b2a00c89 3755 // if exp_x is 33 greater than exp_y, no need for compensation
200359e8 3756 if (diff > 33) {
b2a00c89 3757 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
200359e8 3758 BID_RETURN (res);
b2a00c89 3759 } // difference cannot be greater than 10^33
200359e8 3760
b2a00c89
L
3761 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
3762 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8
L
3763
3764
3765 // if postitive, return whichever significand is larger
3766 // (converse if negative)
3767 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
b2a00c89
L
3768 && sig_n_prime256.w[1] == sig_y.w[1]
3769 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
3770 res = 0;
3771 BID_RETURN (res);
b2a00c89 3772 } // if equal, return 0
200359e8 3773 {
b2a00c89
L
3774 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
3775 || (sig_n_prime256.w[1] > sig_y.w[1])
3776 || (sig_n_prime256.w[1] == sig_y.w[1]
3777 && sig_n_prime256.w[0] >
3778 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
3779 BID_RETURN (res);
3780 }
3781 }
3782 //else { //128 by 64 bit multiply -> 192 bits
b2a00c89 3783 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 3784
b2a00c89
L
3785 // if postitive, return whichever significand is larger
3786 // (converse if negative)
3787 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
3788 && (sig_n_prime192.w[0] == sig_y.w[0])) {
200359e8
L
3789 res = 0;
3790 BID_RETURN (res);
b2a00c89
L
3791 } // if equal, return 0
3792 {
3793 res = (((sig_n_prime192.w[2] > 0)
3794 || (sig_n_prime192.w[1] > sig_y.w[1])
3795 || (sig_n_prime192.w[1] == sig_y.w[1]
3796 && sig_n_prime192.w[0] >
3797 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
3798 BID_RETURN (res);
3799 }
b2a00c89 3800}
200359e8 3801
b2a00c89 3802diff = exp_y - exp_x;
200359e8 3803
b2a00c89
L
3804 // if exp_x is 33 less than exp_y, no need for compensation
3805if (diff > 33) {
3806 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3807 BID_RETURN (res);
3808}
200359e8 3809
b2a00c89
L
3810if (diff > 19) { //128 by 128 bit multiply -> 256 bits
3811 // adjust the y significand upwards
3812 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8 3813
b2a00c89
L
3814
3815 // if postitive, return whichever significand is larger
3816 // (converse if negative)
3817 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
3818 && sig_n_prime256.w[1] == sig_x.w[1]
3819 && (sig_n_prime256.w[0] == sig_x.w[0])) {
3820 res = 0;
3821 BID_RETURN (res);
3822 } // if equal, return 1
200359e8 3823 {
b2a00c89
L
3824 res =
3825 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
3826 || (sig_n_prime256.w[1] > sig_x.w[1]
3827 || (sig_n_prime256.w[1] == sig_x.w[1]
3828 && sig_n_prime256.w[0] >
3829 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
3830 BID_RETURN (res);
3831 }
b2a00c89
L
3832}
3833 //else { //128 by 64 bit multiply -> 192 bits
3834 // adjust the y significand upwards
3835__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
3836
3837 // if postitive, return whichever significand is larger (converse if negative)
3838if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
3839 && (sig_n_prime192.w[0] == sig_x.w[0])) {
3840 res = 0;
3841 BID_RETURN (res);
3842} // if equal, return 0
3843{
3844 res = (sig_n_prime192.w[2] != 0
3845 || (sig_n_prime192.w[1] > sig_x.w[1]
3846 || (sig_n_prime192.w[1] == sig_x.w[1]
3847 && sig_n_prime192.w[0] >
3848 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
3849 BID_RETURN (res);
3850}
200359e8
L
3851}
3852
b2a00c89
L
3853BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
3854 bid128_signaling_not_greater,
3855 x, y)
200359e8 3856
b2a00c89
L
3857 int res;
3858 int exp_x, exp_y;
3859 int diff;
3860 UINT128 sig_x, sig_y;
3861 UINT192 sig_n_prime192;
3862 UINT256 sig_n_prime256;
3863 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
3864
3865 // NaN (CASE1)
3866 // if either number is NAN, the comparison is unordered,
3867 // rather than equal : return 0
b2a00c89
L
3868if (((x.w[1] & MASK_NAN) == MASK_NAN)
3869 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
3870*pfpsf |= INVALID_EXCEPTION;
3871{
3872 res = 1;
3873 BID_RETURN (res);
3874}
3875}
200359e8
L
3876 // SIMPLE (CASE2)
3877 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
3878if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
3879 res = 1;
3880 BID_RETURN (res);
3881}
3882 // INFINITY (CASE3)
3883if ((x.w[1] & MASK_INF) == MASK_INF) {
3884 // if x is neg infinity, there is no way it is greater than y, return 1
3885 if (((x.w[1] & MASK_SIGN) == MASK_SIGN)) {
200359e8
L
3886 res = 1;
3887 BID_RETURN (res);
3888 }
b2a00c89
L
3889 // x is pos infinity, it is greater, unless y is positive infinity => return y!=pos_infinity
3890 else {
3891 res = (((y.w[1] & MASK_INF) == MASK_INF)
3892 && ((y.w[1] & MASK_SIGN) != MASK_SIGN));
3893 BID_RETURN (res);
3894 }
3895} else if ((y.w[1] & MASK_INF) == MASK_INF) {
3896 // x is finite, so if y is positive infinity, then x is less, return 0
3897 // if y is negative infinity, then x is greater, return 1
3898 {
3899 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3900 BID_RETURN (res);
200359e8 3901 }
b2a00c89 3902}
200359e8 3903 // CONVERT X
b2a00c89
L
3904sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
3905sig_x.w[0] = x.w[0];
3906exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
3907
3908 // CHECK IF X IS CANONICAL
3909 // 9999999999999999999999999999999999(decimal) =
3910 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3911 // [0, 10^34) is the 754r supported canonical range.
3912 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3913if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
3914 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
3915 && (sig_x.w[0] > 0x378d8e63ffffffffull))
3916 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3917 non_canon_x = 1;
3918else
3919 non_canon_x = 0;
200359e8
L
3920
3921 // CONVERT Y
b2a00c89
L
3922exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
3923sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
3924sig_y.w[0] = y.w[0];
200359e8
L
3925
3926 // CHECK IF Y IS CANONICAL
3927 // 9999999999999999999999999999999999(decimal) =
3928 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
3929 // [0, 10^34) is the 754r supported canonical range.
3930 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
3931if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
3932 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
3933 && (sig_y.w[0] > 0x378d8e63ffffffffull))
3934 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
3935 non_canon_y = 1;
3936else
3937 non_canon_y = 0;
200359e8
L
3938
3939 // ZERO (CASE4)
3940 // some properties:
3941 // (+ZERO == -ZERO) => therefore ignore the sign
3942 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
3943 // ignore the exponent field
3944 // (Any non-canonical # is considered 0)
b2a00c89
L
3945if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
3946 x_is_zero = 1;
3947}
3948if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
3949 y_is_zero = 1;
3950}
200359e8 3951 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
3952if (x_is_zero && y_is_zero) {
3953 res = 1;
3954 BID_RETURN (res);
3955}
200359e8 3956 // is x is zero, it is greater if Y is negative
b2a00c89
L
3957else if (x_is_zero) {
3958 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3959 BID_RETURN (res);
3960}
200359e8 3961 // is y is zero, X is greater if it is positive
b2a00c89
L
3962else if (y_is_zero) {
3963 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3964 BID_RETURN (res);
3965}
200359e8
L
3966 // OPPOSITE SIGN (CASE5)
3967 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
3968if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
3969 res = ((y.w[1] & MASK_SIGN) != MASK_SIGN);
3970 BID_RETURN (res);
3971}
200359e8
L
3972 // REDUNDANT REPRESENTATIONS (CASE6)
3973 // if exponents are the same, then we have a simple comparison
3974 // of the significands
b2a00c89
L
3975if (exp_y == exp_x) {
3976 res = (((sig_x.w[1] > sig_y.w[1])
3977 || (sig_x.w[1] == sig_y.w[1]
3978 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) !=
3979 MASK_SIGN));
3980 BID_RETURN (res);
3981}
200359e8
L
3982 // if both components are either bigger or smaller,
3983 // it is clear what needs to be done
b2a00c89
L
3984if ((sig_x.w[1] > sig_y.w[1]
3985 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] > sig_y.w[0]))
3986 && exp_x >= exp_y) {
3987 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
3988 BID_RETURN (res);
3989}
3990if ((sig_x.w[1] < sig_y.w[1]
3991 || (sig_x.w[1] == sig_y.w[1] && sig_x.w[0] < sig_y.w[0]))
3992 && exp_x <= exp_y) {
3993 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
3994 BID_RETURN (res);
3995}
200359e8 3996
b2a00c89 3997diff = exp_x - exp_y;
200359e8
L
3998
3999 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 4000if (diff > 0) { // to simplify the loop below,
200359e8 4001
b2a00c89
L
4002 // if exp_x is 33 greater than exp_y, no need for compensation
4003 if (diff > 33) {
4004 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
4005 BID_RETURN (res);
4006 } // difference cannot be greater than 10^33
200359e8 4007
b2a00c89
L
4008 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
4009 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8 4010
200359e8
L
4011
4012 // if postitive, return whichever significand is larger
4013 // (converse if negative)
b2a00c89
L
4014 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
4015 && sig_n_prime256.w[1] == sig_y.w[1]
4016 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
4017 res = 1;
4018 BID_RETURN (res);
b2a00c89 4019 } // if equal, return 0
200359e8 4020 {
b2a00c89
L
4021 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
4022 || (sig_n_prime256.w[1] > sig_y.w[1])
4023 || (sig_n_prime256.w[1] == sig_y.w[1]
4024 && sig_n_prime256.w[0] >
4025 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
4026 BID_RETURN (res);
4027 }
4028 }
b2a00c89
L
4029 //else { //128 by 64 bit multiply -> 192 bits
4030 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 4031
b2a00c89
L
4032 // if postitive, return whichever significand is larger
4033 // (converse if negative)
4034 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
4035 && (sig_n_prime192.w[0] == sig_y.w[0])) {
4036 res = 1;
4037 BID_RETURN (res);
4038 } // if equal, return 0
4039 {
4040 res = (((sig_n_prime192.w[2] > 0)
4041 || (sig_n_prime192.w[1] > sig_y.w[1])
4042 || (sig_n_prime192.w[1] == sig_y.w[1]
4043 && sig_n_prime192.w[0] >
4044 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) != MASK_SIGN));
200359e8
L
4045 BID_RETURN (res);
4046 }
b2a00c89 4047}
200359e8 4048
b2a00c89 4049diff = exp_y - exp_x;
200359e8 4050
b2a00c89
L
4051 // if exp_x is 33 less than exp_y, no need for compensation
4052if (diff > 33) {
4053 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
4054 BID_RETURN (res);
4055}
4056
4057if (diff > 19) { //128 by 128 bit multiply -> 256 bits
200359e8 4058 // adjust the y significand upwards
b2a00c89 4059 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8
L
4060
4061 // if postitive, return whichever significand is larger
4062 // (converse if negative)
b2a00c89
L
4063 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
4064 && sig_n_prime256.w[1] == sig_x.w[1]
4065 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
4066 res = 1;
4067 BID_RETURN (res);
b2a00c89 4068 } // if equal, return 0
200359e8 4069 {
b2a00c89
L
4070 res =
4071 ((sig_n_prime256.w[3] != 0 || sig_n_prime256.w[2] != 0
4072 || (sig_n_prime256.w[1] > sig_x.w[1]
4073 || (sig_n_prime256.w[1] == sig_x.w[1]
4074 && sig_n_prime256.w[0] >
4075 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
4076 BID_RETURN (res);
4077 }
b2a00c89
L
4078}
4079 //else { //128 by 64 bit multiply -> 192 bits
4080 // adjust the y significand upwards
4081__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
4082
4083 // if postitive, return whichever significand is larger
4084 // (converse if negative)
4085if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
4086 && (sig_n_prime192.w[0] == sig_x.w[0])) {
4087 res = 1;
4088 BID_RETURN (res);
4089} // if equal, return 0
4090{
4091 res = (sig_n_prime192.w[2] != 0
4092 || (sig_n_prime192.w[1] > sig_x.w[1]
4093 || (sig_n_prime192.w[1] == sig_x.w[1]
4094 && sig_n_prime192.w[0] >
4095 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
4096 BID_RETURN (res);
4097}
200359e8
L
4098}
4099
b2a00c89
L
4100BID128_FUNCTION_ARG2_NORND_CUSTOMRESTYPE (int,
4101 bid128_signaling_not_less, x,
4102 y)
200359e8 4103
b2a00c89
L
4104 int res;
4105 int exp_x, exp_y;
4106 int diff;
4107 UINT128 sig_x, sig_y;
4108 UINT192 sig_n_prime192;
4109 UINT256 sig_n_prime256;
4110 char x_is_zero = 0, y_is_zero = 0, non_canon_x, non_canon_y;
200359e8
L
4111
4112 // NaN (CASE1)
4113 // if either number is NAN, the comparison is unordered,
4114 // rather than equal : return 1
b2a00c89
L
4115if (((x.w[1] & MASK_NAN) == MASK_NAN)
4116 || ((y.w[1] & MASK_NAN) == MASK_NAN)) {
4117*pfpsf |= INVALID_EXCEPTION;
4118{
4119 res = 1;
4120 BID_RETURN (res);
4121}
4122}
200359e8
L
4123 // SIMPLE (CASE2)
4124 // if all the bits are the same, these numbers are equal (not Greater).
b2a00c89
L
4125if (x.w[0] == y.w[0] && x.w[1] == y.w[1]) {
4126 res = 1;
4127 BID_RETURN (res);
4128}
4129 // INFINITY (CASE3)
4130if ((x.w[1] & MASK_INF) == MASK_INF) {
4131 // if x==neg_inf, { res = (y == neg_inf)?1:0; BID_RETURN (res) }
4132 if ((x.w[1] & MASK_SIGN) == MASK_SIGN)
4133 // x is -inf, so it is less than y unless y is -inf
4134 {
4135 res = (((y.w[1] & MASK_INF) == MASK_INF)
4136 && (y.w[1] & MASK_SIGN) == MASK_SIGN);
4137 BID_RETURN (res);
4138 } else
4139 // x is pos_inf, no way for it to be less than y
4140 {
200359e8
L
4141 res = 1;
4142 BID_RETURN (res);
4143 }
b2a00c89
L
4144} else if ((y.w[1] & MASK_INF) == MASK_INF) {
4145 // x is finite, so if y is positive infinity, then x is less, return 0
4146 // if y is negative infinity, then x is greater, return 1
4147 {
4148 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
4149 BID_RETURN (res);
200359e8 4150 }
b2a00c89 4151}
200359e8 4152 // CONVERT X
b2a00c89
L
4153sig_x.w[1] = x.w[1] & 0x0001ffffffffffffull;
4154sig_x.w[0] = x.w[0];
4155exp_x = (x.w[1] >> 49) & 0x000000000003fffull;
200359e8
L
4156
4157 // CHECK IF X IS CANONICAL
4158 // 9999999999999999999999999999999999(decimal) =
4159 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
4160 // [0, 10^34) is the 754r supported canonical range.
4161 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
4162if ((sig_x.w[1] > 0x0001ed09bead87c0ull)
4163 || ((sig_x.w[1] == 0x0001ed09bead87c0ull)
4164 && (sig_x.w[0] > 0x378d8e63ffffffffull))
4165 || ((x.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
4166 non_canon_x = 1;
4167else
4168 non_canon_x = 0;
200359e8
L
4169
4170 // CONVERT Y
b2a00c89
L
4171exp_y = (y.w[1] >> 49) & 0x0000000000003fffull;
4172sig_y.w[1] = y.w[1] & 0x0001ffffffffffffull;
4173sig_y.w[0] = y.w[0];
200359e8
L
4174
4175 // CHECK IF Y IS CANONICAL
4176 // 9999999999999999999999999999999999(decimal) =
4177 // 1ed09_bead87c0_378d8e63_ffffffff(hexadecimal)
4178 // [0, 10^34) is the 754r supported canonical range.
4179 // If the value exceeds that, it is interpreted as 0.
b2a00c89
L
4180if ((sig_y.w[1] > 0x0001ed09bead87c0ull)
4181 || ((sig_y.w[1] == 0x0001ed09bead87c0ull)
4182 && (sig_y.w[0] > 0x378d8e63ffffffffull))
4183 || ((y.w[1] & 0x6000000000000000ull) == 0x6000000000000000ull))
4184 non_canon_y = 1;
4185else
4186 non_canon_y = 0;
200359e8
L
4187
4188 // ZERO (CASE4)
4189 // some properties:
4190 // (+ZERO == -ZERO) => therefore ignore the sign
4191 // (ZERO x 10^A == ZERO x 10^B) for any valid A, B => therefore
4192 // ignore the exponent field
4193 // (Any non-canonical # is considered 0)
b2a00c89
L
4194if (non_canon_x || ((sig_x.w[1] == 0) && (sig_x.w[0] == 0))) {
4195 x_is_zero = 1;
4196}
4197if (non_canon_y || ((sig_y.w[1] == 0) && (sig_y.w[0] == 0))) {
4198 y_is_zero = 1;
4199}
200359e8 4200 // if both numbers are zero, neither is greater => return NOTGREATERTHAN
b2a00c89
L
4201if (x_is_zero && y_is_zero) {
4202 res = 1;
4203 BID_RETURN (res);
4204}
200359e8 4205 // is x is zero, it is greater if Y is negative
b2a00c89
L
4206else if (x_is_zero) {
4207 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
4208 BID_RETURN (res);
4209}
200359e8 4210 // is y is zero, X is greater if it is positive
b2a00c89
L
4211else if (y_is_zero) {
4212 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
4213 BID_RETURN (res);
4214}
200359e8
L
4215 // OPPOSITE SIGN (CASE5)
4216 // now, if the sign bits differ, x is greater if y is negative
b2a00c89
L
4217if (((x.w[1] ^ y.w[1]) & MASK_SIGN) == MASK_SIGN) {
4218 res = ((y.w[1] & MASK_SIGN) == MASK_SIGN);
4219 BID_RETURN (res);
4220}
200359e8
L
4221 // REDUNDANT REPRESENTATIONS (CASE6)
4222
4223 // if exponents are the same, then we have a simple comparison
4224 // of the significands
b2a00c89
L
4225if (exp_y == exp_x) {
4226 res = (((sig_x.w[1] > sig_y.w[1])
4227 || (sig_x.w[1] == sig_y.w[1]
4228 && sig_x.w[0] >= sig_y.w[0])) ^ ((x.w[1] & MASK_SIGN) ==
4229 MASK_SIGN));
4230 BID_RETURN (res);
4231}
200359e8
L
4232 // if both components are either bigger or smaller,
4233 // it is clear what needs to be done
b2a00c89
L
4234if (sig_x.w[1] >= sig_y.w[1] && sig_x.w[0] >= sig_y.w[0]
4235 && exp_x > exp_y) {
4236 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
4237 BID_RETURN (res);
4238}
4239if (sig_x.w[1] <= sig_y.w[1] && sig_x.w[0] <= sig_y.w[0]
4240 && exp_x < exp_y) {
4241 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
4242 BID_RETURN (res);
4243}
200359e8 4244
b2a00c89 4245diff = exp_x - exp_y;
200359e8
L
4246
4247 // if |exp_x - exp_y| < 33, it comes down to the compensated significand
b2a00c89 4248if (diff > 0) { // to simplify the loop below,
200359e8 4249
b2a00c89 4250 // if exp_x is 33 greater than exp_y, no need for compensation
200359e8 4251 if (diff > 33) {
b2a00c89 4252 res = ((x.w[1] & MASK_SIGN) != MASK_SIGN);
200359e8 4253 BID_RETURN (res);
b2a00c89 4254 } // difference cannot be greater than 10^33
200359e8 4255
b2a00c89
L
4256 if (diff > 19) { //128 by 128 bit multiply -> 256 bits
4257 __mul_128x128_to_256 (sig_n_prime256, sig_x, ten2k128[diff - 20]);
200359e8
L
4258
4259
4260 // if postitive, return whichever significand is larger
4261 // (converse if negative)
4262 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
b2a00c89
L
4263 && sig_n_prime256.w[1] == sig_y.w[1]
4264 && (sig_n_prime256.w[0] == sig_y.w[0])) {
200359e8
L
4265 res = 1;
4266 BID_RETURN (res);
b2a00c89 4267 } // if equal, return 1
200359e8 4268 {
b2a00c89
L
4269 res = ((((sig_n_prime256.w[3] > 0) || sig_n_prime256.w[2] > 0)
4270 || (sig_n_prime256.w[1] > sig_y.w[1])
4271 || (sig_n_prime256.w[1] == sig_y.w[1]
4272 && sig_n_prime256.w[0] >
4273 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
4274 BID_RETURN (res);
4275 }
4276 }
4277 //else { //128 by 64 bit multiply -> 192 bits
b2a00c89 4278 __mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_x);
200359e8 4279
b2a00c89
L
4280 // if postitive, return whichever significand is larger
4281 // (converse if negative)
4282 if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_y.w[1]
4283 && (sig_n_prime192.w[0] == sig_y.w[0])) {
200359e8
L
4284 res = 1;
4285 BID_RETURN (res);
b2a00c89 4286 } // if equal, return 1
200359e8 4287 {
b2a00c89
L
4288 res = (((sig_n_prime192.w[2] > 0)
4289 || (sig_n_prime192.w[1] > sig_y.w[1])
4290 || (sig_n_prime192.w[1] == sig_y.w[1]
4291 && sig_n_prime192.w[0] >
4292 sig_y.w[0])) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN));
200359e8
L
4293 BID_RETURN (res);
4294 }
4295}
4296
b2a00c89 4297diff = exp_y - exp_x;
200359e8 4298
b2a00c89
L
4299 // if exp_x is 33 less than exp_y, no need for compensation
4300if (diff > 33) {
4301 res = ((x.w[1] & MASK_SIGN) == MASK_SIGN);
4302 BID_RETURN (res);
200359e8
L
4303}
4304
b2a00c89
L
4305if (diff > 19) { //128 by 128 bit multiply -> 256 bits
4306 // adjust the y significand upwards
4307 __mul_128x128_to_256 (sig_n_prime256, sig_y, ten2k128[diff - 20]);
200359e8 4308
200359e8 4309
b2a00c89
L
4310 // if postitive, return whichever significand is larger
4311 // (converse if negative)
4312 if (sig_n_prime256.w[3] == 0 && (sig_n_prime256.w[2] == 0)
4313 && sig_n_prime256.w[1] == sig_x.w[1]
4314 && (sig_n_prime256.w[0] == sig_x.w[0])) {
200359e8
L
4315 res = 1;
4316 BID_RETURN (res);
b2a00c89
L
4317 } // if equal, return 1
4318 {
4319 res =
4320 ((sig_n_prime256.w[3] == 0 && sig_n_prime256.w[2] == 0
4321 && (sig_n_prime256.w[1] < sig_x.w[1]
4322 || (sig_n_prime256.w[1] == sig_x.w[1]
4323 && sig_n_prime256.w[0] <
4324 sig_x.w[0]))) ^ ((x.w[1] & MASK_SIGN) == MASK_SIGN));
4325 BID_RETURN (res);
200359e8 4326 }
b2a00c89
L
4327}
4328 //else { //128 by 64 bit multiply -> 192 bits
4329 // adjust the y significand upwards
4330__mul_64x128_to192 (sig_n_prime192, ten2k64[diff], sig_y);
4331
4332 // if postitive, return whichever significand is larger (converse if negative)
4333if ((sig_n_prime192.w[2] == 0) && sig_n_prime192.w[1] == sig_x.w[1]
4334 && (sig_n_prime192.w[0] == sig_x.w[0])) {
4335 res = 1;
200359e8 4336 BID_RETURN (res);
b2a00c89
L
4337} // if equal, return 1
4338{
4339 res = (sig_n_prime192.w[2] == 0
4340 && (sig_n_prime192.w[1] < sig_x.w[1]
4341 || (sig_n_prime192.w[1] == sig_x.w[1]
4342 && sig_n_prime192.w[0] <
4343 sig_x.w[0]))) ^ ((y.w[1] & MASK_SIGN) == MASK_SIGN);
4344 BID_RETURN (res);
4345}
200359e8 4346}