bid128_compare.c 131 KB

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