1/*
2Copyright (c) 2014, Intel Corporation
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8    * Redistributions of source code must retain the above copyright notice,
9    * this list of conditions and the following disclaimer.
10
11    * Redistributions in binary form must reproduce the above copyright notice,
12    * this list of conditions and the following disclaimer in the documentation
13    * and/or other materials provided with the distribution.
14
15    * Neither the name of Intel Corporation nor the names of its contributors
16    * may be used to endorse or promote products derived from this software
17    * without specific prior written permission.
18
19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
31/******************************************************************************/
32//                     ALGORITHM DESCRIPTION
33//                     ---------------------
34//
35//    Let x=2^k * mx, mx in [1,2)
36//
37//    Get B~1/mx based on the output of rcpss instruction (B0)
38//    B = int((B0*LH*2^7+0.5))/2^7
39//    LH is a short approximation for log10(e)
40//
41//    Reduced argument: r=B*mx-LH (computed accurately in high and low parts)
42//
43//    Result:  k*log10(2) - log(B) + p(r)
44//             p(r) is a degree 7 polynomial
45//             -log(B) read from data table (high, low parts)
46//             Result is formed from high and low parts
47//
48// Special cases:
49//  log10(0) = -INF with divide-by-zero exception raised
50//  log10(1) = +0
51//  log10(x) = NaN with invalid exception raised if x < -0, including -INF
52//  log10(+INF) = +INF
53//
54/******************************************************************************/
55
56#include <private/bionic_asm.h>
57# -- Begin  static_func
58        .text
59        .align __bionic_asm_align
60        .type static_func, @function
61static_func:
62..B1.1:
63        call      ..L2
64..L2:
65        popl      %eax
66        lea       _GLOBAL_OFFSET_TABLE_+[. - ..L2](%eax), %eax
67        lea       static_const_table@GOTOFF(%eax), %eax
68        ret
69        .size   static_func,.-static_func
70# -- End  static_func
71
72# -- Begin  log10
73ENTRY(log10)
74# parameter 1: 8 + %ebp
75..B2.1:
76..B2.2:
77        pushl     %ebp
78        movl      %esp, %ebp
79        subl      $104, %esp
80        movl      %ebx, 40(%esp)
81        call      static_func
82        movl      %eax, %ebx
83        xorpd     %xmm2, %xmm2
84        movl      $16368, %eax
85        pinsrw    $3, %eax, %xmm2
86        movl      $1054736384, %ecx
87        movd      %ecx, %xmm7
88        xorpd     %xmm3, %xmm3
89        movl      $30704, %edx
90        pinsrw    $3, %edx, %xmm3
91        movsd     112(%esp), %xmm0
92        movapd    %xmm0, %xmm1
93        movl      $32768, %edx
94        movd      %edx, %xmm4
95        movapd    2128(%ebx), %xmm5
96        pextrw    $3, %xmm0, %eax
97        orpd      %xmm2, %xmm0
98        movl      $16352, %ecx
99        psllq     $5, %xmm0
100        movsd     2144(%ebx), %xmm2
101        psrlq     $34, %xmm0
102        rcpss     %xmm0, %xmm0
103        psllq     $12, %xmm1
104        pshufd    $78, %xmm5, %xmm6
105        psrlq     $12, %xmm1
106        subl      $16, %eax
107        cmpl      $32736, %eax
108        jae       .L_2TAG_PACKET_0.0.2
109.L_2TAG_PACKET_1.0.2:
110        mulss     %xmm7, %xmm0
111        orpd      %xmm3, %xmm1
112        andpd     %xmm1, %xmm5
113        paddd     %xmm4, %xmm0
114        subsd     %xmm5, %xmm1
115        movd      %xmm0, %edx
116        psllq     $29, %xmm0
117        andpd     %xmm6, %xmm0
118        andl      $32752, %eax
119        subl      %ecx, %eax
120        cvtsi2sdl %eax, %xmm7
121        mulpd     %xmm0, %xmm5
122        mulsd     %xmm0, %xmm1
123        movsd     2064(%ebx), %xmm6
124        movapd    2080(%ebx), %xmm3
125        subsd     %xmm2, %xmm5
126        andl      $16711680, %edx
127        shrl      $12, %edx
128        movapd    -1504(%ebx,%edx), %xmm0
129        movapd    2096(%ebx), %xmm4
130        addsd     %xmm5, %xmm1
131        movapd    2112(%ebx), %xmm2
132        mulsd     %xmm7, %xmm6
133        pshufd    $68, %xmm1, %xmm5
134        mulsd     2072(%ebx), %xmm7
135        mulsd     %xmm1, %xmm3
136        addsd     %xmm6, %xmm0
137        mulpd     %xmm5, %xmm4
138        movsd     2152(%ebx), %xmm6
139        mulpd     %xmm5, %xmm5
140        addpd     %xmm2, %xmm4
141        mulpd     %xmm5, %xmm3
142        pshufd    $228, %xmm0, %xmm2
143        addsd     %xmm1, %xmm0
144        mulsd     %xmm1, %xmm4
145        subsd     %xmm0, %xmm2
146        mulsd     %xmm1, %xmm6
147        addsd     %xmm2, %xmm1
148        pshufd    $238, %xmm0, %xmm2
149        mulsd     %xmm5, %xmm5
150        addsd     %xmm2, %xmm7
151        addsd     %xmm6, %xmm1
152        addpd     %xmm3, %xmm4
153        addsd     %xmm7, %xmm1
154        mulpd     %xmm5, %xmm4
155        addsd     %xmm4, %xmm1
156        pshufd    $238, %xmm4, %xmm5
157        addsd     %xmm5, %xmm1
158        addsd     %xmm1, %xmm0
159        jmp       .L_2TAG_PACKET_2.0.2
160.L_2TAG_PACKET_0.0.2:
161        movsd     112(%esp), %xmm0
162        movapd    %xmm0, %xmm1
163        addl      $16, %eax
164        cmpl      $32768, %eax
165        jae       .L_2TAG_PACKET_3.0.2
166        cmpl      $16, %eax
167        jb        .L_2TAG_PACKET_4.0.2
168.L_2TAG_PACKET_5.0.2:
169        addsd     %xmm0, %xmm0
170        jmp       .L_2TAG_PACKET_2.0.2
171.L_2TAG_PACKET_6.0.2:
172        ja        .L_2TAG_PACKET_5.0.2
173        cmpl      $0, %edx
174        ja        .L_2TAG_PACKET_5.0.2
175        jmp       .L_2TAG_PACKET_7.0.2
176.L_2TAG_PACKET_3.0.2:
177        movd      %xmm1, %edx
178        psrlq     $32, %xmm1
179        movd      %xmm1, %ecx
180        addl      %ecx, %ecx
181        cmpl      $-2097152, %ecx
182        jae       .L_2TAG_PACKET_6.0.2
183        orl       %ecx, %edx
184        cmpl      $0, %edx
185        je        .L_2TAG_PACKET_8.0.2
186.L_2TAG_PACKET_7.0.2:
187        xorpd     %xmm1, %xmm1
188        xorpd     %xmm0, %xmm0
189        movl      $32752, %eax
190        pinsrw    $3, %eax, %xmm1
191        movl      $9, %edx
192        mulsd     %xmm1, %xmm0
193.L_2TAG_PACKET_9.0.2:
194        movsd     %xmm0, (%esp)
195        movsd     112(%esp), %xmm0
196        fldl      (%esp)
197        jmp       .L_2TAG_PACKET_10.0.2
198.L_2TAG_PACKET_8.0.2:
199        xorpd     %xmm1, %xmm1
200        xorpd     %xmm0, %xmm0
201        movl      $49136, %eax
202        pinsrw    $3, %eax, %xmm0
203        divsd     %xmm1, %xmm0
204        movl      $8, %edx
205        jmp       .L_2TAG_PACKET_9.0.2
206.L_2TAG_PACKET_4.0.2:
207        movd      %xmm1, %edx
208        psrlq     $32, %xmm1
209        movd      %xmm1, %ecx
210        orl       %ecx, %edx
211        cmpl      $0, %edx
212        je        .L_2TAG_PACKET_8.0.2
213        xorpd     %xmm1, %xmm1
214        movl      $18416, %eax
215        pinsrw    $3, %eax, %xmm1
216        mulsd     %xmm1, %xmm0
217        xorpd     %xmm2, %xmm2
218        movl      $16368, %eax
219        pinsrw    $3, %eax, %xmm2
220        movapd    %xmm0, %xmm1
221        pextrw    $3, %xmm0, %eax
222        orpd      %xmm2, %xmm0
223        movl      $18416, %ecx
224        psllq     $5, %xmm0
225        movsd     2144(%ebx), %xmm2
226        psrlq     $34, %xmm0
227        rcpss     %xmm0, %xmm0
228        psllq     $12, %xmm1
229        pshufd    $78, %xmm5, %xmm6
230        psrlq     $12, %xmm1
231        jmp       .L_2TAG_PACKET_1.0.2
232.L_2TAG_PACKET_2.0.2:
233        movsd     %xmm0, 24(%esp)
234        fldl      24(%esp)
235.L_2TAG_PACKET_10.0.2:
236        movl      40(%esp), %ebx
237        movl      %ebp, %esp
238        popl      %ebp
239        ret
240..B2.3:
241END(log10)
242# -- End  log10
243
244# Start file scope ASM
245ALIAS_SYMBOL(log10l, log10);
246# End file scope ASM
247	.section .rodata, "a"
248	.align 16
249	.align 16
250static_const_table:
251	.long	1352628224
252	.long	1070810131
253	.long	521319256
254	.long	1025503025
255	.long	2150839296
256	.long	1070801944
257	.long	3329350096
258	.long	3170190015
259	.long	1360613376
260	.long	1070793794
261	.long	2024059075
262	.long	1024991594
263	.long	1875350528
264	.long	1070785680
265	.long	2163882141
266	.long	3163564137
267	.long	2312126464
268	.long	1070777602
269	.long	1975711076
270	.long	1023674196
271	.long	1306336256
272	.long	1070769560
273	.long	3524899523
274	.long	3170508164
275	.long	1806334976
276	.long	1070761553
277	.long	4254777025
278	.long	1025238739
279	.long	2483193856
280	.long	1070753581
281	.long	3800671317
282	.long	3172916830
283	.long	2025350144
284	.long	1070745644
285	.long	1731514745
286	.long	1025501083
287	.long	3433285632
288	.long	1070737741
289	.long	2551857336
290	.long	3169662186
291	.long	1134317568
292	.long	1070729873
293	.long	3426297655
294	.long	3172637891
295	.long	2457152512
296	.long	1070722038
297	.long	63549415
298	.long	1025415416
299	.long	1861803008
300	.long	1070714237
301	.long	1910171636
302	.long	1023977580
303	.long	2414140416
304	.long	1070706469
305	.long	4002514337
306	.long	3170841618
307	.long	2900726784
308	.long	1070698734
309	.long	3268064083
310	.long	1022459609
311	.long	2123517952
312	.long	1070691032
313	.long	1767031218
314	.long	1022448156
315	.long	3194569728
316	.long	1070683362
317	.long	3402332618
318	.long	3171671160
319	.long	650882048
320	.long	1070675725
321	.long	4146023905
322	.long	3171023038
323	.long	1928988672
324	.long	1070668119
325	.long	1438617867
326	.long	1016360491
327	.long	1594908672
328	.long	1070660545
329	.long	971389377
330	.long	1024763979
331	.long	2818746368
332	.long	1070653002
333	.long	3555925341
334	.long	3172434821
335	.long	194584576
336	.long	1070645491
337	.long	943919215
338	.long	3172950063
339	.long	1215096832
340	.long	1070638010
341	.long	2283358588
342	.long	1022335098
343	.long	501519360
344	.long	1070630560
345	.long	480904295
346	.long	1024437959
347	.long	1278266368
348	.long	1070623140
349	.long	2755806066
350	.long	3172342012
351	.long	2487812096
352	.long	1070615750
353	.long	2489653202
354	.long	3172481099
355	.long	3085451264
356	.long	1070608390
357	.long	3759184951
358	.long	3172574892
359	.long	2039090176
360	.long	1070601060
361	.long	1361176676
362	.long	3172355319
363	.long	953057280
364	.long	1070591423
365	.long	1176587546
366	.long	3166422018
367	.long	3370524672
368	.long	1070576879
369	.long	3669570051
370	.long	1025376630
371	.long	749742080
372	.long	1070562394
373	.long	707700964
374	.long	3170814058
375	.long	4008353792
376	.long	1070547965
377	.long	3247327652
378	.long	1022431400
379	.long	2612455424
380	.long	1070533594
381	.long	2453457344
382	.long	3172322969
383	.long	3230920704
384	.long	1070519279
385	.long	1296781801
386	.long	1025115335
387	.long	3965253632
388	.long	1070505020
389	.long	373075289
390	.long	1017938528
391	.long	2593157120
392	.long	1070476669
393	.long	1068054086
394	.long	1021616576
395	.long	925962240
396	.long	1070448537
397	.long	850121213
398	.long	1023928989
399	.long	1732556800
400	.long	1070420620
401	.long	1305206740
402	.long	3172665570
403	.long	3815630848
404	.long	1070392915
405	.long	192642943
406	.long	3172699907
407	.long	2001758208
408	.long	1070365420
409	.long	2820786683
410	.long	1024704867
411	.long	16746496
412	.long	1070338131
413	.long	1399573110
414	.long	3171372773
415	.long	1886492672
416	.long	1070311044
417	.long	3621428075
418	.long	3172974358
419	.long	3338196992
420	.long	1070284157
421	.long	3793882035
422	.long	1025124701
423	.long	381769728
424	.long	1070257468
425	.long	3877933342
426	.long	3170195490
427	.long	2186491904
428	.long	1070230972
429	.long	1838687089
430	.long	1017927292
431	.long	1008330752
432	.long	1070204668
433	.long	2228321664
434	.long	1025352196
435	.long	2247065600
436	.long	1070178552
437	.long	1413900906
438	.long	3170902532
439	.long	2964070400
440	.long	1070152622
441	.long	3590454629
442	.long	1025016844
443	.long	465154048
444	.long	1070126876
445	.long	2079688550
446	.long	3172268183
447	.long	883615744
448	.long	1070101310
449	.long	989244452
450	.long	3171900485
451	.long	1993768960
452	.long	1070075922
453	.long	1124327841
454	.long	3172964992
455	.long	1794471936
456	.long	1070050710
457	.long	1140575046
458	.long	1022673726
459	.long	2797932544
460	.long	1070025671
461	.long	1894836933
462	.long	3172544059
463	.long	3433797632
464	.long	1070000803
465	.long	3221831166
466	.long	3171921685
467	.long	2338371584
468	.long	1069976104
469	.long	3732461053
470	.long	3164513518
471	.long	2644013056
472	.long	1069951571
473	.long	2519460462
474	.long	3172548740
475	.long	3383814144
476	.long	1069927202
477	.long	2290997657
478	.long	1025499649
479	.long	3781380096
480	.long	1069902995
481	.long	380479405
482	.long	1025184136
483	.long	3245785088
484	.long	1069878948
485	.long	1096398261
486	.long	3169885192
487	.long	1366712320
488	.long	1069855059
489	.long	2218343715
490	.long	3170281628
491	.long	2204717056
492	.long	1069831325
493	.long	2668334011
494	.long	1025264524
495	.long	1401772032
496	.long	1069807745
497	.long	4103993159
498	.long	1022925721
499	.long	3356721152
500	.long	1069784316
501	.long	3573790772
502	.long	3172186527
503	.long	4041148416
504	.long	1069761037
505	.long	4027691910
506	.long	3171276990
507	.long	3880151040
508	.long	1069737906
509	.long	4087118786
510	.long	3172710734
511	.long	3453364224
512	.long	1069714921
513	.long	99014299
514	.long	3172003077
515	.long	3491092480
516	.long	1069692080
517	.long	3801836701
518	.long	3172989287
519	.long	575580160
520	.long	1069669382
521	.long	1920406012
522	.long	3170874125
523	.long	22282240
524	.long	1069646824
525	.long	964193370
526	.long	1019363159
527	.long	2991429632
528	.long	1069624404
529	.long	3372589890
530	.long	1023425053
531	.long	2189645824
532	.long	1069602122
533	.long	2610503872
534	.long	1023652442
535	.long	3341467648
536	.long	1069579975
537	.long	1190292004
538	.long	1022425665
539	.long	3711293440
540	.long	1069557962
541	.long	1104795356
542	.long	1023625829
543	.long	1380401152
544	.long	1069524644
545	.long	1156998217
546	.long	1025100499
547	.long	765710336
548	.long	1069481144
549	.long	1736649113
550	.long	1024999439
551	.long	849412096
552	.long	1069437902
553	.long	2618178330
554	.long	3170853629
555	.long	1433104384
556	.long	1069394915
557	.long	43477267
558	.long	3170378811
559	.long	2548596736
560	.long	1069352180
561	.long	3967367063
562	.long	1025246584
563	.long	157577216
564	.long	1069309695
565	.long	100402533
566	.long	3172825502
567	.long	3326238720
568	.long	1069267455
569	.long	1176892909
570	.long	1025464099
571	.long	4155494400
572	.long	1069225459
573	.long	3713707617
574	.long	3172630046
575	.long	3545804800
576	.long	1069183704
577	.long	857007315
578	.long	1024965777
579	.long	2602520576
580	.long	1069142187
581	.long	2588758347
582	.long	1022463131
583	.long	2631196672
584	.long	1069100905
585	.long	2118424235
586	.long	1022490989
587	.long	838135808
588	.long	1069059856
589	.long	4117002727
590	.long	1024874520
591	.long	3210903552
592	.long	1069019036
593	.long	650070125
594	.long	3172012966
595	.long	3039211520
596	.long	1068978444
597	.long	438055812
598	.long	1017743757
599	.long	2385633280
600	.long	1068938077
601	.long	3011990369
602	.long	3171312044
603	.long	3491618816
604	.long	1068897932
605	.long	712813818
606	.long	3172720400
607	.long	183644160
608	.long	1068858008
609	.long	4287006742
610	.long	1022379728
611	.long	3639214080
612	.long	1068818300
613	.long	353762279
614	.long	3172980009
615	.long	3728416768
616	.long	1068778808
617	.long	1851367730
618	.long	1025486574
619	.long	3370094592
620	.long	1068739529
621	.long	4046594913
622	.long	3172567047
623	.long	1348407296
624	.long	1068700461
625	.long	143189675
626	.long	1025397632
627	.long	899403776
628	.long	1068661601
629	.long	3753687842
630	.long	3170772772
631	.long	1117708288
632	.long	1068622947
633	.long	1857340812
634	.long	3170782678
635	.long	1248276480
636	.long	1068584497
637	.long	1289858203
638	.long	1025222289
639	.long	683237376
640	.long	1068546249
641	.long	2356679608
642	.long	3171629170
643	.long	3253764096
644	.long	1068508200
645	.long	3267136556
646	.long	1018554987
647	.long	94478336
648	.long	1068441756
649	.long	1927868814
650	.long	3169378180
651	.long	3233144832
652	.long	1068366445
653	.long	2682188854
654	.long	1023964004
655	.long	2940297216
656	.long	1068291522
657	.long	275301289
658	.long	1023944679
659	.long	3677708288
660	.long	1068216982
661	.long	302658771
662	.long	1024465567
663	.long	1576968192
664	.long	1068142822
665	.long	3672035940
666	.long	3172254610
667	.long	1614069760
668	.long	1068069037
669	.long	480052905
670	.long	3172692062
671	.long	424435712
672	.long	1067995624
673	.long	2207869657
674	.long	3170965436
675	.long	3477782528
676	.long	1067922578
677	.long	2980661858
678	.long	3164990018
679	.long	3598401536
680	.long	1067849897
681	.long	1974393034
682	.long	3171357083
683	.long	2435235840
684	.long	1067777577
685	.long	1385289011
686	.long	1024615823
687	.long	1867333632
688	.long	1067705614
689	.long	3442236633
690	.long	1025334384
691	.long	3999301632
692	.long	1067634004
693	.long	3506472073
694	.long	1025132546
695	.long	2566971392
696	.long	1067562745
697	.long	1425757592
698	.long	3172358463
699	.long	112943104
700	.long	1067491833
701	.long	1693407156
702	.long	3172426603
703	.long	3079929856
704	.long	1067392159
705	.long	3999942455
706	.long	1018549369
707	.long	2443837440
708	.long	1067251701
709	.long	974534460
710	.long	1023963412
711	.long	359366656
712	.long	1067111917
713	.long	2204915018
714	.long	1013514416
715	.long	3564519424
716	.long	1066972799
717	.long	3977441659
718	.long	3170879860
719	.long	2011086848
720	.long	1066834343
721	.long	590145514
722	.long	1025390011
723	.long	3216982016
724	.long	1066696541
725	.long	3629120110
726	.long	1024330313
727	.long	2194128896
728	.long	1066559388
729	.long	2367098512
730	.long	3172260338
731	.long	2916220928
732	.long	1066422877
733	.long	2262431886
734	.long	1021229446
735	.long	2263941120
736	.long	1066172214
737	.long	3118507287
738	.long	1021484970
739	.long	3076292608
740	.long	1065901726
741	.long	1411737803
742	.long	3172957147
743	.long	1186136064
744	.long	1065632488
745	.long	3109349337
746	.long	1025397383
747	.long	3085303808
748	.long	1065364487
749	.long	584715031
750	.long	3172596519
751	.long	1821048832
752	.long	1064842211
753	.long	2182246895
754	.long	3172536214
755	.long	697368576
756	.long	1064311094
757	.long	3157561765
758	.long	3172716357
759	.long	894042112
760	.long	1063260131
761	.long	3237958154
762	.long	3172587292
763	.long	0
764	.long	0
765	.long	0
766	.long	0
767	.long	1352628224
768	.long	1066615827
769	.long	521319256
770	.long	1021308721
771	.long	3248877870
772	.long	1077250164
773	.long	1691676429
774	.long	3221787401
775	.long	945132465
776	.long	3223701783
777	.long	3700831335
778	.long	1073506818
779	.long	2141010593
780	.long	1075227551
781	.long	3698831637
782	.long	3220339442
783	.long	4160749568
784	.long	4294967295
785	.long	0
786	.long	4294959104
787	.long	0
788	.long	1071366144
789	.long	3207479560
790	.long	1062894188
791	.type	static_const_table,@object
792	.size	static_const_table,2160
793	.data
794	.section .note.GNU-stack, ""
795# End
796