1.file "log1p.s" 2 3 4// Copyright (c) 2000 - 2005, Intel Corporation 5// All rights reserved. 6// 7// 8// Redistribution and use in source and binary forms, with or without 9// modification, are permitted provided that the following conditions are 10// met: 11// 12// * Redistributions of source code must retain the above copyright 13// notice, this list of conditions and the following disclaimer. 14// 15// * Redistributions in binary form must reproduce the above copyright 16// notice, this list of conditions and the following disclaimer in the 17// documentation and/or other materials provided with the distribution. 18// 19// * The name of Intel Corporation may not be used to endorse or promote 20// products derived from this software without specific prior written 21// permission. 22 23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS 27// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 31// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING 32// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34// 35// Intel Corporation is the author of this code, and requests that all 36// problem reports or change requests be submitted to it directly at 37// http://www.intel.com/software/products/opensource/libraries/num.htm. 38// 39// History 40//============================================================== 41// 02/02/00 Initial version 42// 04/04/00 Unwind support added 43// 08/15/00 Bundle added after call to __libm_error_support to properly 44// set [the previously overwritten] GR_Parameter_RESULT. 45// 06/29/01 Improved speed of all paths 46// 05/20/02 Cleaned up namespace and sf0 syntax 47// 10/02/02 Improved performance by basing on log algorithm 48// 02/10/03 Reordered header: .section, .global, .proc, .align 49// 04/18/03 Eliminate possible WAW dependency warning 50// 03/31/05 Reformatted delimiters between data tables 51// 52// API 53//============================================================== 54// double log1p(double) 55// 56// log1p(x) = log(x+1) 57// 58// Overview of operation 59//============================================================== 60// Background 61// ---------- 62// 63// This algorithm is based on fact that 64// log1p(x) = log(1+x) and 65// log(a b) = log(a) + log(b). 66// In our case we have 1+x = 2^N f, where 1 <= f < 2. 67// So 68// log(1+x) = log(2^N f) = log(2^N) + log(f) = n*log(2) + log(f) 69// 70// To calculate log(f) we do following 71// log(f) = log(f * frcpa(f) / frcpa(f)) = 72// = log(f * frcpa(f)) + log(1/frcpa(f)) 73// 74// According to definition of IA-64's frcpa instruction it's a 75// floating point that approximates 1/f using a lookup on the 76// top of 8 bits of the input number's + 1 significand with relative 77// error < 2^(-8.886). So we have following 78// 79// |(1/f - frcpa(f)) / (1/f))| = |1 - f*frcpa(f)| < 1/256 80// 81// and 82// 83// log(f) = log(f * frcpa(f)) + log(1/frcpa(f)) = 84// = log(1 + r) + T 85// 86// The first value can be computed by polynomial P(r) approximating 87// log(1 + r) on |r| < 1/256 and the second is precomputed tabular 88// value defined by top 8 bit of f. 89// 90// Finally we have that log(1+x) ~ (N*log(2) + T) + P(r) 91// 92// Note that if input argument is close to 0.0 (in our case it means 93// that |x| < 1/256) we can use just polynomial approximation 94// because 1+x = 2^0 * f = f = 1 + r and 95// log(1+x) = log(1 + r) ~ P(r) 96// 97// 98// Implementation 99// -------------- 100// 101// 1. |x| >= 2^(-8), and x > -1 102// InvX = frcpa(x+1) 103// r = InvX*(x+1) - 1 104// P(r) = r*((r*A3 - A2) + r^4*((A4 + r*A5) + r^2*(A6 + r*A7)), 105// all coefficients are calculated in quad and rounded to double 106// precision. A7,A6,A5,A4 are stored in memory whereas A3 and A2 107// created with setf. 108// 109// N = float(n) where n is true unbiased exponent of x 110// 111// T is tabular value of log(1/frcpa(x)) calculated in quad precision 112// and represented by two floating-point numbers 64-bit Thi and 32-bit Tlo. 113// To load Thi,Tlo we get bits from 55 to 62 of register format significand 114// as index and calculate two addresses 115// ad_Thi = Thi_table_base_addr + 8 * index 116// ad_Tlo = Tlo_table_base_addr + 4 * index 117// 118// L1 (log(2)) is calculated in quad 119// precision and represented by two floating-point 64-bit numbers L1hi,L1lo 120// stored in memory. 121// 122// And final result = ((L1hi*N + Thi) + (N*L1lo + Tlo)) + P(r) 123// 124// 125// 2. 2^(-80) <= |x| < 2^(-8) 126// r = x 127// P(r) = r*((r*A3 - A2) + r^4*((A4 + r*A5) + r^2*(A6 + r*A7)), 128// A7,A6,A5,A4,A3,A2 are the same as in case |x| >= 1/256 129// 130// And final results 131// log(1+x) = P(r) 132// 133// 3. 0 < |x| < 2^(-80) 134// Although log1p(x) is basically x, we would like to preserve the inexactness 135// nature as well as consistent behavior under different rounding modes. 136// We can do this by computing the result as 137// 138// log1p(x) = x - x*x 139// 140// 141// Note: NaT, any NaNs, +/-INF, +/-0, negatives and unnormalized numbers are 142// filtered and processed on special branches. 143// 144 145// 146// Special values 147//============================================================== 148// 149// log1p(-1) = -inf // Call error support 150// 151// log1p(+qnan) = +qnan 152// log1p(-qnan) = -qnan 153// log1p(+snan) = +qnan 154// log1p(-snan) = -qnan 155// 156// log1p(x),x<-1= QNAN Indefinite // Call error support 157// log1p(-inf) = QNAN Indefinite 158// log1p(+inf) = +inf 159// log1p(+/-0) = +/-0 160// 161// 162// Registers used 163//============================================================== 164// Floating Point registers used: 165// f8, input 166// f7 -> f15, f32 -> f40 167// 168// General registers used: 169// r8 -> r11 170// r14 -> r20 171// 172// Predicate registers used: 173// p6 -> p12 174 175// Assembly macros 176//============================================================== 177GR_TAG = r8 178GR_ad_1 = r8 179GR_ad_2 = r9 180GR_Exp = r10 181GR_N = r11 182 183GR_signexp_x = r14 184GR_exp_mask = r15 185GR_exp_bias = r16 186GR_05 = r17 187GR_A3 = r18 188GR_Sig = r19 189GR_Ind = r19 190GR_exp_x = r20 191 192 193GR_SAVE_B0 = r33 194GR_SAVE_PFS = r34 195GR_SAVE_GP = r35 196GR_SAVE_SP = r36 197 198GR_Parameter_X = r37 199GR_Parameter_Y = r38 200GR_Parameter_RESULT = r39 201GR_Parameter_TAG = r40 202 203 204 205FR_NormX = f7 206FR_RcpX = f9 207FR_r = f10 208FR_r2 = f11 209FR_r4 = f12 210FR_N = f13 211FR_Ln2hi = f14 212FR_Ln2lo = f15 213 214FR_A7 = f32 215FR_A6 = f33 216FR_A5 = f34 217FR_A4 = f35 218FR_A3 = f36 219FR_A2 = f37 220 221FR_Thi = f38 222FR_NxLn2hipThi = f38 223FR_NxLn2pT = f38 224FR_Tlo = f39 225FR_NxLn2lopTlo = f39 226 227FR_Xp1 = f40 228 229 230FR_Y = f1 231FR_X = f10 232FR_RESULT = f8 233 234 235// Data 236//============================================================== 237RODATA 238.align 16 239 240LOCAL_OBJECT_START(log_data) 241// coefficients of polynomial approximation 242data8 0x3FC2494104381A8E // A7 243data8 0xBFC5556D556BBB69 // A6 244data8 0x3FC999999988B5E9 // A5 245data8 0xBFCFFFFFFFF6FFF5 // A4 246// 247// hi parts of ln(1/frcpa(1+i/256)), i=0...255 248data8 0x3F60040155D5889D // 0 249data8 0x3F78121214586B54 // 1 250data8 0x3F841929F96832EF // 2 251data8 0x3F8C317384C75F06 // 3 252data8 0x3F91A6B91AC73386 // 4 253data8 0x3F95BA9A5D9AC039 // 5 254data8 0x3F99D2A8074325F3 // 6 255data8 0x3F9D6B2725979802 // 7 256data8 0x3FA0C58FA19DFAA9 // 8 257data8 0x3FA2954C78CBCE1A // 9 258data8 0x3FA4A94D2DA96C56 // 10 259data8 0x3FA67C94F2D4BB58 // 11 260data8 0x3FA85188B630F068 // 12 261data8 0x3FAA6B8ABE73AF4C // 13 262data8 0x3FAC441E06F72A9E // 14 263data8 0x3FAE1E6713606D06 // 15 264data8 0x3FAFFA6911AB9300 // 16 265data8 0x3FB0EC139C5DA600 // 17 266data8 0x3FB1DBD2643D190B // 18 267data8 0x3FB2CC7284FE5F1C // 19 268data8 0x3FB3BDF5A7D1EE64 // 20 269data8 0x3FB4B05D7AA012E0 // 21 270data8 0x3FB580DB7CEB5701 // 22 271data8 0x3FB674F089365A79 // 23 272data8 0x3FB769EF2C6B568D // 24 273data8 0x3FB85FD927506A47 // 25 274data8 0x3FB9335E5D594988 // 26 275data8 0x3FBA2B0220C8E5F4 // 27 276data8 0x3FBB0004AC1A86AB // 28 277data8 0x3FBBF968769FCA10 // 29 278data8 0x3FBCCFEDBFEE13A8 // 30 279data8 0x3FBDA727638446A2 // 31 280data8 0x3FBEA3257FE10F79 // 32 281data8 0x3FBF7BE9FEDBFDE5 // 33 282data8 0x3FC02AB352FF25F3 // 34 283data8 0x3FC097CE579D204C // 35 284data8 0x3FC1178E8227E47B // 36 285data8 0x3FC185747DBECF33 // 37 286data8 0x3FC1F3B925F25D41 // 38 287data8 0x3FC2625D1E6DDF56 // 39 288data8 0x3FC2D1610C868139 // 40 289data8 0x3FC340C59741142E // 41 290data8 0x3FC3B08B6757F2A9 // 42 291data8 0x3FC40DFB08378003 // 43 292data8 0x3FC47E74E8CA5F7C // 44 293data8 0x3FC4EF51F6466DE4 // 45 294data8 0x3FC56092E02BA516 // 46 295data8 0x3FC5D23857CD74D4 // 47 296data8 0x3FC6313A37335D76 // 48 297data8 0x3FC6A399DABBD383 // 49 298data8 0x3FC70337DD3CE41A // 50 299data8 0x3FC77654128F6127 // 51 300data8 0x3FC7E9D82A0B022D // 52 301data8 0x3FC84A6B759F512E // 53 302data8 0x3FC8AB47D5F5A30F // 54 303data8 0x3FC91FE49096581B // 55 304data8 0x3FC981634011AA75 // 56 305data8 0x3FC9F6C407089664 // 57 306data8 0x3FCA58E729348F43 // 58 307data8 0x3FCABB55C31693AC // 59 308data8 0x3FCB1E104919EFD0 // 60 309data8 0x3FCB94EE93E367CA // 61 310data8 0x3FCBF851C067555E // 62 311data8 0x3FCC5C0254BF23A5 // 63 312data8 0x3FCCC000C9DB3C52 // 64 313data8 0x3FCD244D99C85673 // 65 314data8 0x3FCD88E93FB2F450 // 66 315data8 0x3FCDEDD437EAEF00 // 67 316data8 0x3FCE530EFFE71012 // 68 317data8 0x3FCEB89A1648B971 // 69 318data8 0x3FCF1E75FADF9BDE // 70 319data8 0x3FCF84A32EAD7C35 // 71 320data8 0x3FCFEB2233EA07CD // 72 321data8 0x3FD028F9C7035C1C // 73 322data8 0x3FD05C8BE0D9635A // 74 323data8 0x3FD085EB8F8AE797 // 75 324data8 0x3FD0B9C8E32D1911 // 76 325data8 0x3FD0EDD060B78080 // 77 326data8 0x3FD122024CF0063F // 78 327data8 0x3FD14BE2927AECD4 // 79 328data8 0x3FD180618EF18ADF // 80 329data8 0x3FD1B50BBE2FC63B // 81 330data8 0x3FD1DF4CC7CF242D // 82 331data8 0x3FD214456D0EB8D4 // 83 332data8 0x3FD23EC5991EBA49 // 84 333data8 0x3FD2740D9F870AFB // 85 334data8 0x3FD29ECDABCDFA03 // 86 335data8 0x3FD2D46602ADCCEE // 87 336data8 0x3FD2FF66B04EA9D4 // 88 337data8 0x3FD335504B355A37 // 89 338data8 0x3FD360925EC44F5C // 90 339data8 0x3FD38BF1C3337E74 // 91 340data8 0x3FD3C25277333183 // 92 341data8 0x3FD3EDF463C1683E // 93 342data8 0x3FD419B423D5E8C7 // 94 343data8 0x3FD44591E0539F48 // 95 344data8 0x3FD47C9175B6F0AD // 96 345data8 0x3FD4A8B341552B09 // 97 346data8 0x3FD4D4F39089019F // 98 347data8 0x3FD501528DA1F967 // 99 348data8 0x3FD52DD06347D4F6 // 100 349data8 0x3FD55A6D3C7B8A89 // 101 350data8 0x3FD5925D2B112A59 // 102 351data8 0x3FD5BF406B543DB1 // 103 352data8 0x3FD5EC433D5C35AD // 104 353data8 0x3FD61965CDB02C1E // 105 354data8 0x3FD646A84935B2A1 // 106 355data8 0x3FD6740ADD31DE94 // 107 356data8 0x3FD6A18DB74A58C5 // 108 357data8 0x3FD6CF31058670EC // 109 358data8 0x3FD6F180E852F0B9 // 110 359data8 0x3FD71F5D71B894EF // 111 360data8 0x3FD74D5AEFD66D5C // 112 361data8 0x3FD77B79922BD37D // 113 362data8 0x3FD7A9B9889F19E2 // 114 363data8 0x3FD7D81B037EB6A6 // 115 364data8 0x3FD8069E33827230 // 116 365data8 0x3FD82996D3EF8BCA // 117 366data8 0x3FD85855776DCBFA // 118 367data8 0x3FD8873658327CCE // 119 368data8 0x3FD8AA75973AB8CE // 120 369data8 0x3FD8D992DC8824E4 // 121 370data8 0x3FD908D2EA7D9511 // 122 371data8 0x3FD92C59E79C0E56 // 123 372data8 0x3FD95BD750EE3ED2 // 124 373data8 0x3FD98B7811A3EE5B // 125 374data8 0x3FD9AF47F33D406B // 126 375data8 0x3FD9DF270C1914A7 // 127 376data8 0x3FDA0325ED14FDA4 // 128 377data8 0x3FDA33440224FA78 // 129 378data8 0x3FDA57725E80C382 // 130 379data8 0x3FDA87D0165DD199 // 131 380data8 0x3FDAAC2E6C03F895 // 132 381data8 0x3FDADCCC6FDF6A81 // 133 382data8 0x3FDB015B3EB1E790 // 134 383data8 0x3FDB323A3A635948 // 135 384data8 0x3FDB56FA04462909 // 136 385data8 0x3FDB881AA659BC93 // 137 386data8 0x3FDBAD0BEF3DB164 // 138 387data8 0x3FDBD21297781C2F // 139 388data8 0x3FDC039236F08818 // 140 389data8 0x3FDC28CB1E4D32FC // 141 390data8 0x3FDC4E19B84723C1 // 142 391data8 0x3FDC7FF9C74554C9 // 143 392data8 0x3FDCA57B64E9DB05 // 144 393data8 0x3FDCCB130A5CEBAF // 145 394data8 0x3FDCF0C0D18F326F // 146 395data8 0x3FDD232075B5A201 // 147 396data8 0x3FDD490246DEFA6B // 148 397data8 0x3FDD6EFA918D25CD // 149 398data8 0x3FDD9509707AE52F // 150 399data8 0x3FDDBB2EFE92C554 // 151 400data8 0x3FDDEE2F3445E4AE // 152 401data8 0x3FDE148A1A2726CD // 153 402data8 0x3FDE3AFC0A49FF3F // 154 403data8 0x3FDE6185206D516D // 155 404data8 0x3FDE882578823D51 // 156 405data8 0x3FDEAEDD2EAC990C // 157 406data8 0x3FDED5AC5F436BE2 // 158 407data8 0x3FDEFC9326D16AB8 // 159 408data8 0x3FDF2391A21575FF // 160 409data8 0x3FDF4AA7EE03192C // 161 410data8 0x3FDF71D627C30BB0 // 162 411data8 0x3FDF991C6CB3B379 // 163 412data8 0x3FDFC07ADA69A90F // 164 413data8 0x3FDFE7F18EB03D3E // 165 414data8 0x3FE007C053C5002E // 166 415data8 0x3FE01B942198A5A0 // 167 416data8 0x3FE02F74400C64EA // 168 417data8 0x3FE04360BE7603AC // 169 418data8 0x3FE05759AC47FE33 // 170 419data8 0x3FE06B5F1911CF51 // 171 420data8 0x3FE078BF0533C568 // 172 421data8 0x3FE08CD9687E7B0E // 173 422data8 0x3FE0A10074CF9019 // 174 423data8 0x3FE0B5343A234476 // 175 424data8 0x3FE0C974C89431CD // 176 425data8 0x3FE0DDC2305B9886 // 177 426data8 0x3FE0EB524BAFC918 // 178 427data8 0x3FE0FFB54213A475 // 179 428data8 0x3FE114253DA97D9F // 180 429data8 0x3FE128A24F1D9AFF // 181 430data8 0x3FE1365252BF0864 // 182 431data8 0x3FE14AE558B4A92D // 183 432data8 0x3FE15F85A19C765B // 184 433data8 0x3FE16D4D38C119FA // 185 434data8 0x3FE18203C20DD133 // 186 435data8 0x3FE196C7BC4B1F3A // 187 436data8 0x3FE1A4A738B7A33C // 188 437data8 0x3FE1B981C0C9653C // 189 438data8 0x3FE1CE69E8BB106A // 190 439data8 0x3FE1DC619DE06944 // 191 440data8 0x3FE1F160A2AD0DA3 // 192 441data8 0x3FE2066D7740737E // 193 442data8 0x3FE2147DBA47A393 // 194 443data8 0x3FE229A1BC5EBAC3 // 195 444data8 0x3FE237C1841A502E // 196 445data8 0x3FE24CFCE6F80D9A // 197 446data8 0x3FE25B2C55CD5762 // 198 447data8 0x3FE2707F4D5F7C40 // 199 448data8 0x3FE285E0842CA383 // 200 449data8 0x3FE294294708B773 // 201 450data8 0x3FE2A9A2670AFF0C // 202 451data8 0x3FE2B7FB2C8D1CC0 // 203 452data8 0x3FE2C65A6395F5F5 // 204 453data8 0x3FE2DBF557B0DF42 // 205 454data8 0x3FE2EA64C3F97654 // 206 455data8 0x3FE3001823684D73 // 207 456data8 0x3FE30E97E9A8B5CC // 208 457data8 0x3FE32463EBDD34E9 // 209 458data8 0x3FE332F4314AD795 // 210 459data8 0x3FE348D90E7464CF // 211 460data8 0x3FE35779F8C43D6D // 212 461data8 0x3FE36621961A6A99 // 213 462data8 0x3FE37C299F3C366A // 214 463data8 0x3FE38AE2171976E7 // 215 464data8 0x3FE399A157A603E7 // 216 465data8 0x3FE3AFCCFE77B9D1 // 217 466data8 0x3FE3BE9D503533B5 // 218 467data8 0x3FE3CD7480B4A8A2 // 219 468data8 0x3FE3E3C43918F76C // 220 469data8 0x3FE3F2ACB27ED6C6 // 221 470data8 0x3FE4019C2125CA93 // 222 471data8 0x3FE4181061389722 // 223 472data8 0x3FE42711518DF545 // 224 473data8 0x3FE436194E12B6BF // 225 474data8 0x3FE445285D68EA69 // 226 475data8 0x3FE45BCC464C893A // 227 476data8 0x3FE46AED21F117FC // 228 477data8 0x3FE47A1527E8A2D3 // 229 478data8 0x3FE489445EFFFCCB // 230 479data8 0x3FE4A018BCB69835 // 231 480data8 0x3FE4AF5A0C9D65D7 // 232 481data8 0x3FE4BEA2A5BDBE87 // 233 482data8 0x3FE4CDF28F10AC46 // 234 483data8 0x3FE4DD49CF994058 // 235 484data8 0x3FE4ECA86E64A683 // 236 485data8 0x3FE503C43CD8EB68 // 237 486data8 0x3FE513356667FC57 // 238 487data8 0x3FE522AE0738A3D7 // 239 488data8 0x3FE5322E26867857 // 240 489data8 0x3FE541B5CB979809 // 241 490data8 0x3FE55144FDBCBD62 // 242 491data8 0x3FE560DBC45153C6 // 243 492data8 0x3FE5707A26BB8C66 // 244 493data8 0x3FE587F60ED5B8FF // 245 494data8 0x3FE597A7977C8F31 // 246 495data8 0x3FE5A760D634BB8A // 247 496data8 0x3FE5B721D295F10E // 248 497data8 0x3FE5C6EA94431EF9 // 249 498data8 0x3FE5D6BB22EA86F5 // 250 499data8 0x3FE5E6938645D38F // 251 500data8 0x3FE5F673C61A2ED1 // 252 501data8 0x3FE6065BEA385926 // 253 502data8 0x3FE6164BFA7CC06B // 254 503data8 0x3FE62643FECF9742 // 255 504// 505// two parts of ln(2) 506data8 0x3FE62E42FEF00000,0x3DD473DE6AF278ED 507// 508// lo parts of ln(1/frcpa(1+i/256)), i=0...255 509data4 0x20E70672 // 0 510data4 0x1F60A5D0 // 1 511data4 0x218EABA0 // 2 512data4 0x21403104 // 3 513data4 0x20E9B54E // 4 514data4 0x21EE1382 // 5 515data4 0x226014E3 // 6 516data4 0x2095E5C9 // 7 517data4 0x228BA9D4 // 8 518data4 0x22932B86 // 9 519data4 0x22608A57 // 10 520data4 0x220209F3 // 11 521data4 0x212882CC // 12 522data4 0x220D46E2 // 13 523data4 0x21FA4C28 // 14 524data4 0x229E5BD9 // 15 525data4 0x228C9838 // 16 526data4 0x2311F954 // 17 527data4 0x221365DF // 18 528data4 0x22BD0CB3 // 19 529data4 0x223D4BB7 // 20 530data4 0x22A71BBE // 21 531data4 0x237DB2FA // 22 532data4 0x23194C9D // 23 533data4 0x22EC639E // 24 534data4 0x2367E669 // 25 535data4 0x232E1D5F // 26 536data4 0x234A639B // 27 537data4 0x2365C0E0 // 28 538data4 0x234646C1 // 29 539data4 0x220CBF9C // 30 540data4 0x22A00FD4 // 31 541data4 0x2306A3F2 // 32 542data4 0x23745A9B // 33 543data4 0x2398D756 // 34 544data4 0x23DD0B6A // 35 545data4 0x23DE338B // 36 546data4 0x23A222DF // 37 547data4 0x223164F8 // 38 548data4 0x23B4E87B // 39 549data4 0x23D6CCB8 // 40 550data4 0x220C2099 // 41 551data4 0x21B86B67 // 42 552data4 0x236D14F1 // 43 553data4 0x225A923F // 44 554data4 0x22748723 // 45 555data4 0x22200D13 // 46 556data4 0x23C296EA // 47 557data4 0x2302AC38 // 48 558data4 0x234B1996 // 49 559data4 0x2385E298 // 50 560data4 0x23175BE5 // 51 561data4 0x2193F482 // 52 562data4 0x23BFEA90 // 53 563data4 0x23D70A0C // 54 564data4 0x231CF30A // 55 565data4 0x235D9E90 // 56 566data4 0x221AD0CB // 57 567data4 0x22FAA08B // 58 568data4 0x23D29A87 // 59 569data4 0x20C4B2FE // 60 570data4 0x2381B8B7 // 61 571data4 0x23F8D9FC // 62 572data4 0x23EAAE7B // 63 573data4 0x2329E8AA // 64 574data4 0x23EC0322 // 65 575data4 0x2357FDCB // 66 576data4 0x2392A9AD // 67 577data4 0x22113B02 // 68 578data4 0x22DEE901 // 69 579data4 0x236A6D14 // 70 580data4 0x2371D33E // 71 581data4 0x2146F005 // 72 582data4 0x23230B06 // 73 583data4 0x22F1C77D // 74 584data4 0x23A89FA3 // 75 585data4 0x231D1241 // 76 586data4 0x244DA96C // 77 587data4 0x23ECBB7D // 78 588data4 0x223E42B4 // 79 589data4 0x23801BC9 // 80 590data4 0x23573263 // 81 591data4 0x227C1158 // 82 592data4 0x237BD749 // 83 593data4 0x21DDBAE9 // 84 594data4 0x23401735 // 85 595data4 0x241D9DEE // 86 596data4 0x23BC88CB // 87 597data4 0x2396D5F1 // 88 598data4 0x23FC89CF // 89 599data4 0x2414F9A2 // 90 600data4 0x2474A0F5 // 91 601data4 0x24354B60 // 92 602data4 0x23C1EB40 // 93 603data4 0x2306DD92 // 94 604data4 0x24353B6B // 95 605data4 0x23CD1701 // 96 606data4 0x237C7A1C // 97 607data4 0x245793AA // 98 608data4 0x24563695 // 99 609data4 0x23C51467 // 100 610data4 0x24476B68 // 101 611data4 0x212585A9 // 102 612data4 0x247B8293 // 103 613data4 0x2446848A // 104 614data4 0x246A53F8 // 105 615data4 0x246E496D // 106 616data4 0x23ED1D36 // 107 617data4 0x2314C258 // 108 618data4 0x233244A7 // 109 619data4 0x245B7AF0 // 110 620data4 0x24247130 // 111 621data4 0x22D67B38 // 112 622data4 0x2449F620 // 113 623data4 0x23BBC8B8 // 114 624data4 0x237D3BA0 // 115 625data4 0x245E8F13 // 116 626data4 0x2435573F // 117 627data4 0x242DE666 // 118 628data4 0x2463BC10 // 119 629data4 0x2466587D // 120 630data4 0x2408144B // 121 631data4 0x2405F0E5 // 122 632data4 0x22381CFF // 123 633data4 0x24154F9B // 124 634data4 0x23A4E96E // 125 635data4 0x24052967 // 126 636data4 0x2406963F // 127 637data4 0x23F7D3CB // 128 638data4 0x2448AFF4 // 129 639data4 0x24657A21 // 130 640data4 0x22FBC230 // 131 641data4 0x243C8DEA // 132 642data4 0x225DC4B7 // 133 643data4 0x23496EBF // 134 644data4 0x237C2B2B // 135 645data4 0x23A4A5B1 // 136 646data4 0x2394E9D1 // 137 647data4 0x244BC950 // 138 648data4 0x23C7448F // 139 649data4 0x2404A1AD // 140 650data4 0x246511D5 // 141 651data4 0x24246526 // 142 652data4 0x23111F57 // 143 653data4 0x22868951 // 144 654data4 0x243EB77F // 145 655data4 0x239F3DFF // 146 656data4 0x23089666 // 147 657data4 0x23EBFA6A // 148 658data4 0x23C51312 // 149 659data4 0x23E1DD5E // 150 660data4 0x232C0944 // 151 661data4 0x246A741F // 152 662data4 0x2414DF8D // 153 663data4 0x247B5546 // 154 664data4 0x2415C980 // 155 665data4 0x24324ABD // 156 666data4 0x234EB5E5 // 157 667data4 0x2465E43E // 158 668data4 0x242840D1 // 159 669data4 0x24444057 // 160 670data4 0x245E56F0 // 161 671data4 0x21AE30F8 // 162 672data4 0x23FB3283 // 163 673data4 0x247A4D07 // 164 674data4 0x22AE314D // 165 675data4 0x246B7727 // 166 676data4 0x24EAD526 // 167 677data4 0x24B41DC9 // 168 678data4 0x24EE8062 // 169 679data4 0x24A0C7C4 // 170 680data4 0x24E8DA67 // 171 681data4 0x231120F7 // 172 682data4 0x24401FFB // 173 683data4 0x2412DD09 // 174 684data4 0x248C131A // 175 685data4 0x24C0A7CE // 176 686data4 0x243DD4C8 // 177 687data4 0x24457FEB // 178 688data4 0x24DEEFBB // 179 689data4 0x243C70AE // 180 690data4 0x23E7A6FA // 181 691data4 0x24C2D311 // 182 692data4 0x23026255 // 183 693data4 0x2437C9B9 // 184 694data4 0x246BA847 // 185 695data4 0x2420B448 // 186 696data4 0x24C4CF5A // 187 697data4 0x242C4981 // 188 698data4 0x24DE1525 // 189 699data4 0x24F5CC33 // 190 700data4 0x235A85DA // 191 701data4 0x24A0B64F // 192 702data4 0x244BA0A4 // 193 703data4 0x24AAF30A // 194 704data4 0x244C86F9 // 195 705data4 0x246D5B82 // 196 706data4 0x24529347 // 197 707data4 0x240DD008 // 198 708data4 0x24E98790 // 199 709data4 0x2489B0CE // 200 710data4 0x22BC29AC // 201 711data4 0x23F37C7A // 202 712data4 0x24987FE8 // 203 713data4 0x22AFE20B // 204 714data4 0x24C8D7C2 // 205 715data4 0x24B28B7D // 206 716data4 0x23B6B271 // 207 717data4 0x24C77CB6 // 208 718data4 0x24EF1DCA // 209 719data4 0x24A4F0AC // 210 720data4 0x24CF113E // 211 721data4 0x2496BBAB // 212 722data4 0x23C7CC8A // 213 723data4 0x23AE3961 // 214 724data4 0x2410A895 // 215 725data4 0x23CE3114 // 216 726data4 0x2308247D // 217 727data4 0x240045E9 // 218 728data4 0x24974F60 // 219 729data4 0x242CB39F // 220 730data4 0x24AB8D69 // 221 731data4 0x23436788 // 222 732data4 0x24305E9E // 223 733data4 0x243E71A9 // 224 734data4 0x23C2A6B3 // 225 735data4 0x23FFE6CF // 226 736data4 0x2322D801 // 227 737data4 0x24515F21 // 228 738data4 0x2412A0D6 // 229 739data4 0x24E60D44 // 230 740data4 0x240D9251 // 231 741data4 0x247076E2 // 232 742data4 0x229B101B // 233 743data4 0x247B12DE // 234 744data4 0x244B9127 // 235 745data4 0x2499EC42 // 236 746data4 0x21FC3963 // 237 747data4 0x23E53266 // 238 748data4 0x24CE102D // 239 749data4 0x23CC45D2 // 240 750data4 0x2333171D // 241 751data4 0x246B3533 // 242 752data4 0x24931129 // 243 753data4 0x24405FFA // 244 754data4 0x24CF464D // 245 755data4 0x237095CD // 246 756data4 0x24F86CBD // 247 757data4 0x24E2D84B // 248 758data4 0x21ACBB44 // 249 759data4 0x24F43A8C // 250 760data4 0x249DB931 // 251 761data4 0x24A385EF // 252 762data4 0x238B1279 // 253 763data4 0x2436213E // 254 764data4 0x24F18A3B // 255 765LOCAL_OBJECT_END(log_data) 766 767 768// Code 769//============================================================== 770 771.section .text 772GLOBAL_IEEE754_ENTRY(log1p) 773{ .mfi 774 getf.exp GR_signexp_x = f8 // if x is unorm then must recompute 775 fadd.s1 FR_Xp1 = f8, f1 // Form 1+x 776 mov GR_05 = 0xfffe 777} 778{ .mlx 779 addl GR_ad_1 = @ltoff(log_data),gp 780 movl GR_A3 = 0x3fd5555555555557 // double precision memory 781 // representation of A3 782} 783;; 784 785{ .mfi 786 ld8 GR_ad_1 = [GR_ad_1] 787 fclass.m p8,p0 = f8,0xb // Is x unorm? 788 mov GR_exp_mask = 0x1ffff 789} 790{ .mfi 791 nop.m 0 792 fnorm.s1 FR_NormX = f8 // Normalize x 793 mov GR_exp_bias = 0xffff 794} 795;; 796 797{ .mfi 798 setf.exp FR_A2 = GR_05 // create A2 = 0.5 799 fclass.m p9,p0 = f8,0x1E1 // is x NaN, NaT or +Inf? 800 nop.i 0 801} 802{ .mib 803 setf.d FR_A3 = GR_A3 // create A3 804 add GR_ad_2 = 16,GR_ad_1 // address of A5,A4 805(p8) br.cond.spnt log1p_unorm // Branch if x=unorm 806} 807;; 808 809log1p_common: 810{ .mfi 811 nop.m 0 812 frcpa.s1 FR_RcpX,p0 = f1,FR_Xp1 813 nop.i 0 814} 815{ .mfb 816 nop.m 0 817(p9) fma.d.s0 f8 = f8,f1,f0 // set V-flag 818(p9) br.ret.spnt b0 // exit for NaN, NaT and +Inf 819} 820;; 821 822{ .mfi 823 getf.exp GR_Exp = FR_Xp1 // signexp of x+1 824 fclass.m p10,p0 = FR_Xp1,0x3A // is 1+x < 0? 825 and GR_exp_x = GR_exp_mask, GR_signexp_x // biased exponent of x 826} 827{ .mfi 828 ldfpd FR_A7,FR_A6 = [GR_ad_1] 829 nop.f 0 830 nop.i 0 831} 832;; 833 834{ .mfi 835 getf.sig GR_Sig = FR_Xp1 // get significand to calculate index 836 // for Thi,Tlo if |x| >= 2^-8 837 fcmp.eq.s1 p12,p0 = f8,f0 // is x equal to 0? 838 sub GR_exp_x = GR_exp_x, GR_exp_bias // true exponent of x 839} 840;; 841 842{ .mfi 843 sub GR_N = GR_Exp,GR_exp_bias // true exponent of x+1 844 fcmp.eq.s1 p11,p0 = FR_Xp1,f0 // is x = -1? 845 cmp.gt p6,p7 = -8, GR_exp_x // Is |x| < 2^-8 846} 847{ .mfb 848 ldfpd FR_A5,FR_A4 = [GR_ad_2],16 849 nop.f 0 850(p10) br.cond.spnt log1p_lt_minus_1 // jump if x < -1 851} 852;; 853 854// p6 is true if |x| < 1/256 855// p7 is true if |x| >= 1/256 856.pred.rel "mutex",p6,p7 857{ .mfi 858(p7) add GR_ad_1 = 0x820,GR_ad_1 // address of log(2) parts 859(p6) fms.s1 FR_r = f8,f1,f0 // range reduction for |x|<1/256 860(p6) cmp.gt.unc p10,p0 = -80, GR_exp_x // Is |x| < 2^-80 861} 862{ .mfb 863(p7) setf.sig FR_N = GR_N // copy unbiased exponent of x to the 864 // significand field of FR_N 865(p7) fms.s1 FR_r = FR_RcpX,FR_Xp1,f1 // range reduction for |x|>=1/256 866(p12) br.ret.spnt b0 // exit for x=0, return x 867} 868;; 869 870{ .mib 871(p7) ldfpd FR_Ln2hi,FR_Ln2lo = [GR_ad_1],16 872(p7) extr.u GR_Ind = GR_Sig,55,8 // get bits from 55 to 62 as index 873(p11) br.cond.spnt log1p_eq_minus_1 // jump if x = -1 874} 875;; 876 877{ .mmf 878(p7) shladd GR_ad_2 = GR_Ind,3,GR_ad_2 // address of Thi 879(p7) shladd GR_ad_1 = GR_Ind,2,GR_ad_1 // address of Tlo 880(p10) fnma.d.s0 f8 = f8,f8,f8 // If |x| very small, result=x-x*x 881} 882;; 883 884{ .mmb 885(p7) ldfd FR_Thi = [GR_ad_2] 886(p7) ldfs FR_Tlo = [GR_ad_1] 887(p10) br.ret.spnt b0 // Exit if |x| < 2^(-80) 888} 889;; 890 891{ .mfi 892 nop.m 0 893 fma.s1 FR_r2 = FR_r,FR_r,f0 // r^2 894 nop.i 0 895} 896{ .mfi 897 nop.m 0 898 fms.s1 FR_A2 = FR_A3,FR_r,FR_A2 // A3*r+A2 899 nop.i 0 900} 901;; 902 903{ .mfi 904 nop.m 0 905 fma.s1 FR_A6 = FR_A7,FR_r,FR_A6 // A7*r+A6 906 nop.i 0 907} 908{ .mfi 909 nop.m 0 910 fma.s1 FR_A4 = FR_A5,FR_r,FR_A4 // A5*r+A4 911 nop.i 0 912} 913;; 914 915{ .mfi 916 nop.m 0 917(p7) fcvt.xf FR_N = FR_N 918 nop.i 0 919} 920;; 921 922{ .mfi 923 nop.m 0 924 fma.s1 FR_r4 = FR_r2,FR_r2,f0 // r^4 925 nop.i 0 926} 927{ .mfi 928 nop.m 0 929 // (A3*r+A2)*r^2+r 930 fma.s1 FR_A2 = FR_A2,FR_r2,FR_r 931 nop.i 0 932} 933;; 934 935{ .mfi 936 nop.m 0 937 // (A7*r+A6)*r^2+(A5*r+A4) 938 fma.s1 FR_A4 = FR_A6,FR_r2,FR_A4 939 nop.i 0 940} 941;; 942 943{ .mfi 944 nop.m 0 945 // N*Ln2hi+Thi 946(p7) fma.s1 FR_NxLn2hipThi = FR_N,FR_Ln2hi,FR_Thi 947 nop.i 0 948} 949{ .mfi 950 nop.m 0 951 // N*Ln2lo+Tlo 952(p7) fma.s1 FR_NxLn2lopTlo = FR_N,FR_Ln2lo,FR_Tlo 953 nop.i 0 954} 955;; 956 957{ .mfi 958 nop.m 0 959(p7) fma.s1 f8 = FR_A4,FR_r4,FR_A2 // P(r) if |x| >= 1/256 960 nop.i 0 961} 962{ .mfi 963 nop.m 0 964 // (N*Ln2hi+Thi) + (N*Ln2lo+Tlo) 965(p7) fma.s1 FR_NxLn2pT = FR_NxLn2hipThi,f1,FR_NxLn2lopTlo 966 nop.i 0 967} 968;; 969 970.pred.rel "mutex",p6,p7 971{ .mfi 972 nop.m 0 973(p6) fma.d.s0 f8 = FR_A4,FR_r4,FR_A2 // result if 2^(-80) <= |x| < 1/256 974 nop.i 0 975} 976{ .mfb 977 nop.m 0 978(p7) fma.d.s0 f8 = f8,f1,FR_NxLn2pT // result if |x| >= 1/256 979 br.ret.sptk b0 // Exit if |x| >= 2^(-80) 980} 981;; 982 983.align 32 984log1p_unorm: 985// Here if x=unorm 986{ .mfb 987 getf.exp GR_signexp_x = FR_NormX // recompute biased exponent 988 nop.f 0 989 br.cond.sptk log1p_common 990} 991;; 992 993.align 32 994log1p_eq_minus_1: 995// Here if x=-1 996{ .mfi 997 nop.m 0 998 fmerge.s FR_X = f8,f8 // keep input argument for subsequent 999 // call of __libm_error_support# 1000 nop.i 0 1001} 1002;; 1003 1004{ .mfi 1005 mov GR_TAG = 140 // set libm error in case of log1p(-1). 1006 frcpa.s0 f8,p0 = f8,f0 // log1p(-1) should be equal to -INF. 1007 // We can get it using frcpa because it 1008 // sets result to the IEEE-754 mandated 1009 // quotient of f8/f0. 1010 nop.i 0 1011} 1012{ .mib 1013 nop.m 0 1014 nop.i 0 1015 br.cond.sptk log_libm_err 1016} 1017;; 1018 1019.align 32 1020log1p_lt_minus_1: 1021// Here if x < -1 1022{ .mfi 1023 nop.m 0 1024 fmerge.s FR_X = f8,f8 1025 nop.i 0 1026} 1027;; 1028 1029{ .mfi 1030 mov GR_TAG = 141 // set libm error in case of x < -1. 1031 frcpa.s0 f8,p0 = f0,f0 // log1p(x) x < -1 should be equal to NaN. 1032 // We can get it using frcpa because it 1033 // sets result to the IEEE-754 mandated 1034 // quotient of f0/f0 i.e. NaN. 1035 nop.i 0 1036} 1037;; 1038 1039.align 32 1040log_libm_err: 1041{ .mmi 1042 alloc r32 = ar.pfs,1,4,4,0 1043 mov GR_Parameter_TAG = GR_TAG 1044 nop.i 0 1045} 1046;; 1047 1048GLOBAL_IEEE754_END(log1p) 1049libm_alias_double_other (__log1p, log1p) 1050 1051 1052LOCAL_LIBM_ENTRY(__libm_error_region) 1053.prologue 1054{ .mfi 1055 add GR_Parameter_Y = -32,sp // Parameter 2 value 1056 nop.f 0 1057.save ar.pfs,GR_SAVE_PFS 1058 mov GR_SAVE_PFS = ar.pfs // Save ar.pfs 1059} 1060{ .mfi 1061.fframe 64 1062 add sp = -64,sp // Create new stack 1063 nop.f 0 1064 mov GR_SAVE_GP = gp // Save gp 1065};; 1066{ .mmi 1067 stfd [GR_Parameter_Y] = FR_Y,16 // STORE Parameter 2 on stack 1068 add GR_Parameter_X = 16,sp // Parameter 1 address 1069.save b0, GR_SAVE_B0 1070 mov GR_SAVE_B0 = b0 // Save b0 1071};; 1072.body 1073{ .mib 1074 stfd [GR_Parameter_X] = FR_X // STORE Parameter 1 on stack 1075 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address 1076 nop.b 0 1077} 1078{ .mib 1079 stfd [GR_Parameter_Y] = FR_RESULT // STORE Parameter 3 on stack 1080 add GR_Parameter_Y = -16,GR_Parameter_Y 1081 br.call.sptk b0=__libm_error_support# // Call error handling function 1082};; 1083{ .mmi 1084 add GR_Parameter_RESULT = 48,sp 1085 nop.m 0 1086 nop.i 0 1087};; 1088{ .mmi 1089 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack 1090.restore sp 1091 add sp = 64,sp // Restore stack pointer 1092 mov b0 = GR_SAVE_B0 // Restore return address 1093};; 1094{ .mib 1095 mov gp = GR_SAVE_GP // Restore gp 1096 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs 1097 br.ret.sptk b0 // Return 1098};; 1099LOCAL_LIBM_END(__libm_error_region) 1100 1101.type __libm_error_support#,@function 1102.global __libm_error_support# 1103