OLD | NEW |
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* ***** BEGIN LICENSE BLOCK ***** | 2 /* ***** BEGIN LICENSE BLOCK ***** |
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 * | 4 * |
5 * The contents of this file are subject to the Mozilla Public License Version | 5 * The contents of this file are subject to the Mozilla Public License Version |
6 * 1.1 (the "License"); you may not use this file except in compliance with | 6 * 1.1 (the "License"); you may not use this file except in compliance with |
7 * the License. You may obtain a copy of the License at | 7 * the License. You may obtain a copy of the License at |
8 * http://www.mozilla.org/MPL/ | 8 * http://www.mozilla.org/MPL/ |
9 * | 9 * |
10 * Software distributed under the License is distributed on an "AS IS" basis, | 10 * Software distributed under the License is distributed on an "AS IS" basis, |
(...skipping 28 matching lines...) Expand all Loading... |
39 * This file is based on the third-party code dtoa.c. We minimize our | 39 * This file is based on the third-party code dtoa.c. We minimize our |
40 * modifications to third-party code to make it easy to merge new versions. | 40 * modifications to third-party code to make it easy to merge new versions. |
41 * The author of dtoa.c was not willing to add the parentheses suggested by | 41 * The author of dtoa.c was not willing to add the parentheses suggested by |
42 * GCC, so we suppress these warnings. | 42 * GCC, so we suppress these warnings. |
43 */ | 43 */ |
44 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) | 44 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2) |
45 #pragma GCC diagnostic ignored "-Wparentheses" | 45 #pragma GCC diagnostic ignored "-Wparentheses" |
46 #endif | 46 #endif |
47 | 47 |
48 #include "primpl.h" | 48 #include "primpl.h" |
| 49 #include "prbit.h" |
49 | 50 |
50 #define MULTIPLE_THREADS | 51 #define MULTIPLE_THREADS |
51 #define ACQUIRE_DTOA_LOCK(n) PR_Lock(dtoa_lock[n]) | 52 #define ACQUIRE_DTOA_LOCK(n) PR_Lock(dtoa_lock[n]) |
52 #define FREE_DTOA_LOCK(n) PR_Unlock(dtoa_lock[n]) | 53 #define FREE_DTOA_LOCK(n) PR_Unlock(dtoa_lock[n]) |
53 | 54 |
54 static PRLock *dtoa_lock[2]; | 55 static PRLock *dtoa_lock[2]; |
55 | 56 |
56 void _PR_InitDtoa(void) | 57 void _PR_InitDtoa(void) |
57 { | 58 { |
58 dtoa_lock[0] = PR_NewLock(); | 59 dtoa_lock[0] = PR_NewLock(); |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 } | 736 } |
736 | 737 |
737 static int | 738 static int |
738 hi0bits | 739 hi0bits |
739 #ifdef KR_headers | 740 #ifdef KR_headers |
740 (x) register ULong x; | 741 (x) register ULong x; |
741 #else | 742 #else |
742 (register ULong x) | 743 (register ULong x) |
743 #endif | 744 #endif |
744 { | 745 { |
| 746 #ifdef PR_HAVE_BUILTIN_BITSCAN32 |
| 747 return( (!x) ? 32 : pr_bitscan_clz32(x) ); |
| 748 #else |
745 register int k = 0; | 749 register int k = 0; |
746 | 750 |
747 if (!(x & 0xffff0000)) { | 751 if (!(x & 0xffff0000)) { |
748 k = 16; | 752 k = 16; |
749 x <<= 16; | 753 x <<= 16; |
750 } | 754 } |
751 if (!(x & 0xff000000)) { | 755 if (!(x & 0xff000000)) { |
752 k += 8; | 756 k += 8; |
753 x <<= 8; | 757 x <<= 8; |
754 } | 758 } |
755 if (!(x & 0xf0000000)) { | 759 if (!(x & 0xf0000000)) { |
756 k += 4; | 760 k += 4; |
757 x <<= 4; | 761 x <<= 4; |
758 } | 762 } |
759 if (!(x & 0xc0000000)) { | 763 if (!(x & 0xc0000000)) { |
760 k += 2; | 764 k += 2; |
761 x <<= 2; | 765 x <<= 2; |
762 } | 766 } |
763 if (!(x & 0x80000000)) { | 767 if (!(x & 0x80000000)) { |
764 k++; | 768 k++; |
765 if (!(x & 0x40000000)) | 769 if (!(x & 0x40000000)) |
766 return 32; | 770 return 32; |
767 } | 771 } |
768 return k; | 772 return k; |
| 773 #endif /* PR_HAVE_BUILTIN_BITSCAN32 */ |
769 } | 774 } |
770 | 775 |
771 static int | 776 static int |
772 lo0bits | 777 lo0bits |
773 #ifdef KR_headers | 778 #ifdef KR_headers |
774 (y) ULong *y; | 779 (y) ULong *y; |
775 #else | 780 #else |
776 (ULong *y) | 781 (ULong *y) |
777 #endif | 782 #endif |
778 { | 783 { |
| 784 #ifdef PR_HAVE_BUILTIN_BITSCAN32 |
| 785 int k; |
| 786 ULong x = *y; |
| 787 |
| 788 if (x>1) |
| 789 *y = ( x >> (k = pr_bitscan_ctz32(x)) ); |
| 790 else |
| 791 k = ((x ^ 1) << 5); |
| 792 #else |
779 register int k; | 793 register int k; |
780 register ULong x = *y; | 794 register ULong x = *y; |
781 | 795 |
782 if (x & 7) { | 796 if (x & 7) { |
783 if (x & 1) | 797 if (x & 1) |
784 return 0; | 798 return 0; |
785 if (x & 2) { | 799 if (x & 2) { |
786 *y = x >> 1; | 800 *y = x >> 1; |
787 return 1; | 801 return 1; |
788 } | 802 } |
(...skipping 17 matching lines...) Expand all Loading... |
806 k += 2; | 820 k += 2; |
807 x >>= 2; | 821 x >>= 2; |
808 } | 822 } |
809 if (!(x & 1)) { | 823 if (!(x & 1)) { |
810 k++; | 824 k++; |
811 x >>= 1; | 825 x >>= 1; |
812 if (!x) | 826 if (!x) |
813 return 32; | 827 return 32; |
814 } | 828 } |
815 *y = x; | 829 *y = x; |
| 830 #endif /* PR_HAVE_BUILTIN_BITSCAN32 */ |
816 return k; | 831 return k; |
817 } | 832 } |
818 | 833 |
819 static Bigint * | 834 static Bigint * |
820 i2b | 835 i2b |
821 #ifdef KR_headers | 836 #ifdef KR_headers |
822 (i) int i; | 837 (i) int i; |
823 #else | 838 #else |
824 (int i) | 839 (int i) |
825 #endif | 840 #endif |
(...skipping 2702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3528 } | 3543 } |
3529 | 3544 |
3530 while (*nump != '\0') { | 3545 while (*nump != '\0') { |
3531 *bufp++ = *nump++; | 3546 *bufp++ = *nump++; |
3532 } | 3547 } |
3533 *bufp++ = '\0'; | 3548 *bufp++ = '\0'; |
3534 } | 3549 } |
3535 done: | 3550 done: |
3536 PR_DELETE(num); | 3551 PR_DELETE(num); |
3537 } | 3552 } |
OLD | NEW |