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//    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*2^7+0.5))/2^7
39//
40//    Reduced argument: r=B*mx-1.0 (computed accurately in high and low parts)
41//
42//    Result:  k*log(2) - log(B) + p(r) if |x-1| >= small value (2^-6)  and
43//             p(r) is a degree 7 polynomial
44//             -log(B) read from data table (high, low parts)
45//             Result is formed from high and low parts
46//
47// Special cases:
48//  log(NaN) = quiet NaN, and raise invalid exception
49//  log(+INF) = that INF
50//  log(0) = -INF with divide-by-zero exception raised
51//  log(1) = +0
52//  log(x) = NaN with invalid exception raised if x < -0, including -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  log
73ENTRY(log)
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        xorpd     %xmm3, %xmm3
87        movl      $30704, %edx
88        pinsrw    $3, %edx, %xmm3
89        movsd     112(%esp), %xmm0
90        movapd    %xmm0, %xmm1
91        movl      $32768, %ecx
92        movd      %ecx, %xmm4
93        movsd     2128(%ebx), %xmm5
94        pextrw    $3, %xmm0, %eax
95        orpd      %xmm2, %xmm0
96        psllq     $5, %xmm0
97        movl      $16352, %ecx
98        psrlq     $34, %xmm0
99        rcpss     %xmm0, %xmm0
100        psllq     $12, %xmm1
101        pshufd    $228, %xmm5, %xmm6
102        psrlq     $12, %xmm1
103        subl      $16, %eax
104        cmpl      $32736, %eax
105        jae       .L_2TAG_PACKET_0.0.2
106.L_2TAG_PACKET_1.0.2:
107        paddd     %xmm4, %xmm0
108        orpd      %xmm3, %xmm1
109        movd      %xmm0, %edx
110        psllq     $29, %xmm0
111        andpd     %xmm1, %xmm5
112        andpd     %xmm6, %xmm0
113        subsd     %xmm5, %xmm1
114        mulpd     %xmm0, %xmm5
115        andl      $32752, %eax
116        subl      %ecx, %eax
117        cvtsi2sdl %eax, %xmm7
118        mulsd     %xmm0, %xmm1
119        movsd     2064(%ebx), %xmm6
120        movapd    2080(%ebx), %xmm3
121        subsd     %xmm2, %xmm5
122        andl      $16711680, %edx
123        shrl      $12, %edx
124        movapd    (%ebx,%edx), %xmm0
125        movapd    2096(%ebx), %xmm4
126        addsd     %xmm5, %xmm1
127        movapd    2112(%ebx), %xmm2
128        mulsd     %xmm7, %xmm6
129        pshufd    $68, %xmm1, %xmm5
130        mulsd     2072(%ebx), %xmm7
131        mulsd     %xmm1, %xmm3
132        addsd     %xmm6, %xmm0
133        mulpd     %xmm5, %xmm4
134        mulpd     %xmm5, %xmm5
135        pshufd    $228, %xmm0, %xmm6
136        addsd     %xmm1, %xmm0
137        addpd     %xmm2, %xmm4
138        mulpd     %xmm5, %xmm3
139        subsd     %xmm0, %xmm6
140        mulsd     %xmm1, %xmm4
141        pshufd    $238, %xmm0, %xmm2
142        addsd     %xmm6, %xmm1
143        mulsd     %xmm5, %xmm5
144        addsd     %xmm2, %xmm7
145        addpd     %xmm3, %xmm4
146        addsd     %xmm7, %xmm1
147        mulpd     %xmm5, %xmm4
148        addsd     %xmm4, %xmm1
149        pshufd    $238, %xmm4, %xmm5
150        addsd     %xmm5, %xmm1
151        addsd     %xmm1, %xmm0
152        jmp       .L_2TAG_PACKET_2.0.2
153.L_2TAG_PACKET_0.0.2:
154        movsd     112(%esp), %xmm0
155        movapd    %xmm0, %xmm1
156        addl      $16, %eax
157        cmpl      $32768, %eax
158        jae       .L_2TAG_PACKET_3.0.2
159        cmpl      $16, %eax
160        jb        .L_2TAG_PACKET_4.0.2
161.L_2TAG_PACKET_5.0.2:
162        addsd     %xmm0, %xmm0
163        jmp       .L_2TAG_PACKET_2.0.2
164.L_2TAG_PACKET_6.0.2:
165        ja        .L_2TAG_PACKET_5.0.2
166        cmpl      $0, %edx
167        ja        .L_2TAG_PACKET_5.0.2
168        jmp       .L_2TAG_PACKET_7.0.2
169.L_2TAG_PACKET_3.0.2:
170        movd      %xmm1, %edx
171        psrlq     $32, %xmm1
172        movd      %xmm1, %ecx
173        addl      %ecx, %ecx
174        cmpl      $-2097152, %ecx
175        jae       .L_2TAG_PACKET_6.0.2
176        orl       %ecx, %edx
177        cmpl      $0, %edx
178        je        .L_2TAG_PACKET_8.0.2
179.L_2TAG_PACKET_7.0.2:
180        xorpd     %xmm1, %xmm1
181        xorpd     %xmm0, %xmm0
182        movl      $32752, %eax
183        pinsrw    $3, %eax, %xmm1
184        movl      $3, %edx
185        mulsd     %xmm1, %xmm0
186.L_2TAG_PACKET_9.0.2:
187        movsd     %xmm0, (%esp)
188        movsd     112(%esp), %xmm0
189        fldl      (%esp)
190        jmp       .L_2TAG_PACKET_10.0.2
191.L_2TAG_PACKET_8.0.2:
192        xorpd     %xmm1, %xmm1
193        xorpd     %xmm0, %xmm0
194        movl      $49136, %eax
195        pinsrw    $3, %eax, %xmm0
196        divsd     %xmm1, %xmm0
197        movl      $2, %edx
198        jmp       .L_2TAG_PACKET_9.0.2
199.L_2TAG_PACKET_4.0.2:
200        movd      %xmm1, %edx
201        psrlq     $32, %xmm1
202        movd      %xmm1, %ecx
203        orl       %ecx, %edx
204        cmpl      $0, %edx
205        je        .L_2TAG_PACKET_8.0.2
206        xorpd     %xmm1, %xmm1
207        movl      $18416, %eax
208        pinsrw    $3, %eax, %xmm1
209        mulsd     %xmm1, %xmm0
210        movapd    %xmm0, %xmm1
211        pextrw    $3, %xmm0, %eax
212        orpd      %xmm2, %xmm0
213        psllq     $5, %xmm0
214        movl      $18416, %ecx
215        psrlq     $34, %xmm0
216        rcpss     %xmm0, %xmm0
217        psllq     $12, %xmm1
218        pshufd    $228, %xmm5, %xmm6
219        psrlq     $12, %xmm1
220        jmp       .L_2TAG_PACKET_1.0.2
221.L_2TAG_PACKET_2.0.2:
222        movsd     %xmm0, 24(%esp)
223        fldl      24(%esp)
224.L_2TAG_PACKET_10.0.2:
225        movl      40(%esp), %ebx
226        movl      %ebp, %esp
227        popl      %ebp
228        ret
229..B2.3:
230END(log)
231# -- End  log
232
233# Start file scope ASM
234ALIAS_SYMBOL(logl, log);
235# End file scope ASM
236	.section .rodata, "a"
237	.align 16
238	.align 16
239static_const_table:
240	.long	4277811200
241	.long	1072049730
242	.long	2479318832
243	.long	1026487127
244	.long	2854492160
245	.long	1072033410
246	.long	215631550
247	.long	1025638968
248	.long	1547061248
249	.long	1072017216
250	.long	2886781435
251	.long	1026423395
252	.long	649825280
253	.long	1072001146
254	.long	4281533405
255	.long	1024038923
256	.long	646346752
257	.long	1071985198
258	.long	1562735921
259	.long	1023790276
260	.long	2203734016
261	.long	1071969370
262	.long	1838397691
263	.long	3173936209
264	.long	1872169984
265	.long	1071953661
266	.long	3981202460
267	.long	1022325013
268	.long	669557760
269	.long	1071938069
270	.long	4182597802
271	.long	3173174122
272	.long	4076413952
273	.long	1071922591
274	.long	1209029111
275	.long	3170736207
276	.long	556125184
277	.long	1071907228
278	.long	821086028
279	.long	3173437049
280	.long	204914688
281	.long	1071891976
282	.long	2097025986
283	.long	3171071798
284	.long	387545088
285	.long	1071876834
286	.long	3142936996
287	.long	3173092218
288	.long	2912783360
289	.long	1071861800
290	.long	2502420140
291	.long	1024505919
292	.long	1144260608
293	.long	1071846874
294	.long	3315658140
295	.long	3173469843
296	.long	1471209472
297	.long	1071832053
298	.long	129621009
299	.long	3172443877
300	.long	1829683200
301	.long	1071817336
302	.long	3885467693
303	.long	1025535275
304	.long	288676864
305	.long	1071802722
306	.long	86139472
307	.long	3171639793
308	.long	3636378624
309	.long	1071788208
310	.long	1850238587
311	.long	1024654342
312	.long	1606817792
313	.long	1071773795
314	.long	3388899795
315	.long	3173675586
316	.long	1236164608
317	.long	1071759480
318	.long	3983599207
319	.long	1020046558
320	.long	1089616896
321	.long	1071745262
322	.long	4171974224
323	.long	1024773198
324	.long	4143093760
325	.long	1071731139
326	.long	2727587401
327	.long	3173965207
328	.long	600267776
329	.long	1071717112
330	.long	3147685042
331	.long	3173353031
332	.long	2249313280
333	.long	1071703177
334	.long	125835074
335	.long	1025255832
336	.long	3805303808
337	.long	1071689334
338	.long	2289991207
339	.long	1025460331
340	.long	87278592
341	.long	1071675583
342	.long	1106114045
343	.long	1025933602
344	.long	3195405312
345	.long	1071661920
346	.long	3885316576
347	.long	3171206239
348	.long	3853649920
349	.long	1071648346
350	.long	2977069852
351	.long	3171236771
352	.long	2944026624
353	.long	1071625048
354	.long	1008093493
355	.long	1023444474
356	.long	3993180160
357	.long	1071598247
358	.long	1862355595
359	.long	1024642533
360	.long	1454641152
361	.long	1071571617
362	.long	1514603089
363	.long	1026500596
364	.long	3286085632
365	.long	1071545154
366	.long	1400028424
367	.long	3173279056
368	.long	438773760
369	.long	1071518858
370	.long	120727864
371	.long	3172148914
372	.long	1212979200
373	.long	1071492725
374	.long	1625055594
375	.long	3172901933
376	.long	1189017600
377	.long	1071466754
378	.long	3920062376
379	.long	1025727407
380	.long	403064832
381	.long	1071440943
382	.long	1053271728
383	.long	3171391427
384	.long	3343210496
385	.long	1071415289
386	.long	3243395502
387	.long	3173627613
388	.long	1765777408
389	.long	1071389792
390	.long	2145968512
391	.long	1026354304
392	.long	461430784
393	.long	1071364449
394	.long	4094322285
395	.long	1026021467
396	.long	71706624
397	.long	1071339258
398	.long	763632021
399	.long	1024496933
400	.long	1380503552
401	.long	1071314217
402	.long	1383547992
403	.long	3173088453
404	.long	1015732224
405	.long	1071289325
406	.long	3198646877
407	.long	1025390322
408	.long	35977216
409	.long	1071264580
410	.long	2141026805
411	.long	1025754693
412	.long	3927306240
413	.long	1071239979
414	.long	282116272
415	.long	3173394334
416	.long	1125341184
417	.long	1071215523
418	.long	2768427504
419	.long	3172279059
420	.long	1666971648
421	.long	1071191208
422	.long	786837629
423	.long	3172427445
424	.long	2827694080
425	.long	1071167033
426	.long	3857122416
427	.long	3173014241
428	.long	2003683328
429	.long	1071142997
430	.long	859010954
431	.long	1026545007
432	.long	1004017664
433	.long	1071119098
434	.long	3356644970
435	.long	3173458064
436	.long	1753020416
437	.long	1071095334
438	.long	788338552
439	.long	1026157693
440	.long	1992718336
441	.long	1071071704
442	.long	1239179443
443	.long	1026394889
444	.long	3870234624
445	.long	1071048206
446	.long	2082614663
447	.long	1024926053
448	.long	1050437632
449	.long	1071024840
450	.long	660007840
451	.long	1025548499
452	.long	188395520
453	.long	1071001603
454	.long	3878792704
455	.long	3173889571
456	.long	3747176448
457	.long	1070978493
458	.long	144991708
459	.long	3171552042
460	.long	1405669376
461	.long	1070955511
462	.long	3999088879
463	.long	1025486317
464	.long	121151488
465	.long	1070932654
466	.long	2170865497
467	.long	1026473584
468	.long	2652319744
469	.long	1070909920
470	.long	453695652
471	.long	3173916809
472	.long	3262236672
473	.long	1070887309
474	.long	157800053
475	.long	3173984206
476	.long	601221120
477	.long	1070864820
478	.long	3968917661
479	.long	1023992886
480	.long	1999843328
481	.long	1070842450
482	.long	3053895004
483	.long	1024998228
484	.long	1992167424
485	.long	1070820199
486	.long	2968614856
487	.long	1024552653
488	.long	3788726272
489	.long	1070798065
490	.long	3542170808
491	.long	3173573242
492	.long	2094829568
493	.long	1070776048
494	.long	1246758132
495	.long	1026202874
496	.long	288675840
497	.long	1070754146
498	.long	3747328950
499	.long	1026331585
500	.long	1829681152
501	.long	1070732357
502	.long	3125197546
503	.long	1024100318
504	.long	1666869248
505	.long	1070710681
506	.long	1363656119
507	.long	1026336493
508	.long	3417110528
509	.long	1070689116
510	.long	4154791553
511	.long	1026267853
512	.long	2183653376
513	.long	1070667662
514	.long	1671819292
515	.long	3173785870
516	.long	1734434816
517	.long	1070646317
518	.long	373091049
519	.long	1025972363
520	.long	1615681536
521	.long	1070625080
522	.long	384650897
523	.long	1022926043
524	.long	1445382144
525	.long	1070603950
526	.long	344320330
527	.long	3172397196
528	.long	1823715328
529	.long	1070569756
530	.long	3389841200
531	.long	1025231852
532	.long	3839688704
533	.long	1070527917
534	.long	1706790417
535	.long	3167363349
536	.long	4293332992
537	.long	1070486286
538	.long	1614935088
539	.long	1019351591
540	.long	2966720512
541	.long	1070444861
542	.long	4145393717
543	.long	3173711658
544	.long	4066729984
545	.long	1070403639
546	.long	1974925028
547	.long	3171437182
548	.long	3337621504
549	.long	1070362619
550	.long	3314953170
551	.long	3169971314
552	.long	943448064
553	.long	1070321799
554	.long	1498682038
555	.long	3173862340
556	.long	1465634816
557	.long	1070281176
558	.long	1319952810
559	.long	3171693965
560	.long	1015734272
561	.long	1070240749
562	.long	1347821929
563	.long	3173544515
564	.long	118001664
565	.long	1070200516
566	.long	1751482746
567	.long	1026134093
568	.long	3707174912
569	.long	1070160474
570	.long	1486946159
571	.long	1023930920
572	.long	3946381312
573	.long	1070120623
574	.long	2867408081
575	.long	3171368276
576	.long	1699848192
577	.long	1070080961
578	.long	2590187139
579	.long	1025379803
580	.long	2235846656
581	.long	1070041485
582	.long	1888568069
583	.long	3172754960
584	.long	2339729408
585	.long	1070002194
586	.long	3852214753
587	.long	3173323149
588	.long	3196850176
589	.long	1069963086
590	.long	742141560
591	.long	1025101707
592	.long	1800683520
593	.long	1069924160
594	.long	3949500444
595	.long	3172102179
596	.long	3835801600
597	.long	1069885413
598	.long	3848895943
599	.long	1025913832
600	.long	2201202688
601	.long	1069846845
602	.long	1425913464
603	.long	1025868665
604	.long	2778279936
605	.long	1069808453
606	.long	2120889677
607	.long	3173831128
608	.long	2954203136
609	.long	1069770236
610	.long	592147081
611	.long	1019621288
612	.long	210141184
613	.long	1069732193
614	.long	3414275233
615	.long	1023647084
616	.long	709476352
617	.long	1069694321
618	.long	2413027164
619	.long	1024462115
620	.long	2116284416
621	.long	1069656619
622	.long	1144559924
623	.long	1026336654
624	.long	2183651328
625	.long	1069619086
626	.long	3459057650
627	.long	1025634168
628	.long	3047047168
629	.long	1069581720
630	.long	1879674924
631	.long	3173508573
632	.long	970711040
633	.long	1069541521
634	.long	1335954173
635	.long	3173332182
636	.long	2198478848
637	.long	1069467449
638	.long	2951103968
639	.long	3173892200
640	.long	1669611520
641	.long	1069393703
642	.long	531044147
643	.long	1025149248
644	.long	29114368
645	.long	1069320280
646	.long	3327831251
647	.long	1025918673
648	.long	2376949760
649	.long	1069247176
650	.long	737634533
651	.long	3172176000
652	.long	1085390848
653	.long	1069174390
654	.long	3108243400
655	.long	3171828406
656	.long	1566130176
657	.long	1069101918
658	.long	985483226
659	.long	1025708380
660	.long	792780800
661	.long	1069029758
662	.long	4184866295
663	.long	1024426204
664	.long	183156736
665	.long	1068957907
666	.long	2845699378
667	.long	1022107277
668	.long	1301782528
669	.long	1068886362
670	.long	1012735262
671	.long	3173804294
672	.long	1562411008
673	.long	1068815121
674	.long	2197086703
675	.long	3170187813
676	.long	2815549440
677	.long	1068744181
678	.long	2782613207
679	.long	1026345054
680	.long	2756124672
681	.long	1068673540
682	.long	2929486205
683	.long	3173037800
684	.long	3511050240
685	.long	1068603195
686	.long	1443733147
687	.long	3173331549
688	.long	3047047168
689	.long	1068533144
690	.long	1879674924
691	.long	3172459997
692	.long	3221667840
693	.long	1068427825
694	.long	1338588027
695	.long	3171815742
696	.long	3453861888
697	.long	1068288883
698	.long	1205348359
699	.long	3172624626
700	.long	3506110464
701	.long	1068150514
702	.long	893105198
703	.long	1025571866
704	.long	346013696
705	.long	1068012714
706	.long	3495569021
707	.long	3172563349
708	.long	4074029056
709	.long	1067875476
710	.long	3961106338
711	.long	3171065595
712	.long	3559784448
713	.long	1067738798
714	.long	1975385384
715	.long	3173783155
716	.long	797769728
717	.long	1067602675
718	.long	3760305787
719	.long	1026047642
720	.long	2313633792
721	.long	1067467101
722	.long	1559353171
723	.long	1023480256
724	.long	3960766464
725	.long	1067213778
726	.long	1067365107
727	.long	1025865926
728	.long	684261376
729	.long	1066944805
730	.long	844762164
731	.long	3173687482
732	.long	630718464
733	.long	1066676905
734	.long	2458269694
735	.long	1024033081
736	.long	1486061568
737	.long	1066410070
738	.long	115537874
739	.long	3173243995
740	.long	2743664640
741	.long	1065886792
742	.long	3665098304
743	.long	3173471607
744	.long	1971912704
745	.long	1065357333
746	.long	2577214440
747	.long	3171993451
748	.long	1498939392
749	.long	1064306693
750	.long	3409036923
751	.long	1025599151
752	.long	0
753	.long	0
754	.long	0
755	.long	2147483648
756	.long	4277811200
757	.long	1067855426
758	.long	2479318832
759	.long	1022292823
760	.long	2454267026
761	.long	1069697316
762	.long	0
763	.long	3218079744
764	.long	1030730101
765	.long	3217380702
766	.long	1431655765
767	.long	1070945621
768	.long	2576980378
769	.long	1070176665
770	.long	0
771	.long	3219128320
772	.long	0
773	.long	4294959104
774	.long	0
775	.long	4294959104
776	.type	static_const_table,@object
777	.size	static_const_table,2144
778	.data
779	.section .note.GNU-stack, ""
780# End
781