-
Notifications
You must be signed in to change notification settings - Fork 85
[CHIA-3769] - Update GMP to 6.3.0 and include new patch files #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
166f8a2
add patch files for GMP6.3.0 and adjust build steps
emlowe fbec9a4
Update compat.patch for compatibility changes
altendky 65a521b
a different take on the patching
altendky 0ceeeb9
Merge pull request #273 from Chia-Network/altendky-patch-2
emlowe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| diff --git a/compat.c b/compat.c | ||
| index b4b44ce..3f563dd 100644 | ||
| --- a/compat.c | ||
| +++ b/compat.c | ||
| @@ -31,6 +31,12 @@ see https://www.gnu.org/licenses/. */ | ||
| #include <stdio.h> | ||
| #include "gmp-impl.h" | ||
|
|
||
| +/* RUNTIMECPUID */ | ||
| +int bCheckedBMI = 0; | ||
| +int bBMI1 = 0; | ||
| +int bBMI2 = 0; | ||
| +int bCheckedLZCNT = 0; | ||
| +int bLZCNT = 0; | ||
|
|
||
| /* mpn_divexact_by3 was a function in gmp 3.0.1, but as of gmp 3.1 it's a | ||
| macro calling mpn_divexact_by3c. */ | ||
| diff --git a/longlong.h b/longlong.h | ||
| index edbaf56..c0a7468 100644 | ||
| --- a/longlong.h | ||
| +++ b/longlong.h | ||
| @@ -1040,6 +1040,86 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype); | ||
| #endif /* 80x86 */ | ||
|
|
||
| #if defined (__amd64__) && W_TYPE_SIZE == 64 | ||
| + | ||
| +#ifndef RUNTIMECPUID | ||
| +#define RUNTIMECPUID | ||
| + | ||
| +extern int bCheckedBMI; | ||
| +extern int bBMI1; | ||
| +extern int bBMI2; | ||
| + | ||
| +inline void hasBMI() | ||
| +{ | ||
| + if(bCheckedBMI) | ||
| + return; | ||
| + | ||
| + bCheckedBMI = 1; | ||
| + int info[4] = {0}; | ||
| +#if defined(_MSC_VER) | ||
| + __cpuid(info, 0x7); | ||
| +#elif defined(__GNUC__) || defined(__clang__) | ||
| +#if defined(ARCH_X86) && defined(__PIC__) | ||
| + __asm__ __volatile__ ( | ||
| + "xchg{l} {%%}ebx, %k1;" | ||
| + "cpuid;" | ||
| + "xchg{l} {%%}ebx, %k1;" | ||
| + : "=a"(info[0]), "=&r"(info[1]), "=c"(info[2]), "=d"(info[3]) : "a"(0x7), "c"(0) | ||
| + ); | ||
| +#else | ||
| + __asm__ __volatile__ ( | ||
| + "cpuid" : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3]) : "a"(0x7), "c"(0) | ||
| + ); | ||
| +#endif | ||
| +#endif | ||
| + bBMI1 = ((info[1] & (1 << 3)) != 0); | ||
| + bBMI2 = ((info[1] & (1 << 8)) != 0); | ||
| +} | ||
| + | ||
| +inline int hasBMI1() | ||
| +{ | ||
| + hasBMI(); | ||
| + return bBMI1; | ||
| +} | ||
| + | ||
| +inline int hasBMI2() | ||
| +{ | ||
| + hasBMI(); | ||
| + return bBMI2; | ||
| +} | ||
| + | ||
| +extern int bCheckedLZCNT; | ||
| +extern int bLZCNT; | ||
| + | ||
| +inline int hasLZCNT() | ||
| +{ | ||
| + if(bCheckedLZCNT) | ||
| + return bLZCNT; | ||
| + | ||
| + bCheckedLZCNT = 1; | ||
| + int info[4] = {0}; | ||
| + #if defined(_MSC_VER) | ||
| + __cpuid(info, 0x80000001); | ||
| + #elif defined(__GNUC__) || defined(__clang__) | ||
| + #if defined(ARCH_X86) && defined(__PIC__) | ||
| + __asm__ __volatile__ ( | ||
| + "xchg{l} {%%}ebx, %k1;" | ||
| + "cpuid;" | ||
| + "xchg{l} {%%}ebx, %k1;" | ||
| + : "=a"(info[0]), "=&r"(info[1]), "=c"(info[2]), "=d"(info[3]) : "a"(0x80000001), "c"(0) | ||
| + ); | ||
| + #else | ||
| + __asm__ __volatile__ ( | ||
| + "cpuid" : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3]) : "a"(0x80000001), "c"(0) | ||
| + ); | ||
| + #endif | ||
| + #endif | ||
| + | ||
| + bLZCNT = ((info[2] & (1 << 5)) != 0); | ||
| + return bLZCNT; | ||
| +} | ||
| + | ||
| +#endif // RUNTIMECPUID | ||
| + | ||
| #define add_ssaaaa(sh, sl, ah, al, bh, bl) \ | ||
| __asm__ ("addq %5,%q1\n\tadcq %3,%q0" \ | ||
| : "=r" (sh), "=&r" (sl) \ | ||
| @@ -1050,61 +1130,52 @@ extern UWtype __MPN(udiv_qrnnd) (UWtype *, UWtype, UWtype, UWtype); | ||
| : "=r" (sh), "=&r" (sl) \ | ||
| : "0" ((UDItype)(ah)), "rme" ((UDItype)(bh)), \ | ||
| "1" ((UDItype)(al)), "rme" ((UDItype)(bl))) | ||
| -#if X86_ASM_MULX \ | ||
| - && (HAVE_HOST_CPU_haswell || HAVE_HOST_CPU_broadwell \ | ||
| - || HAVE_HOST_CPU_skylake || HAVE_HOST_CPU_bd4 || HAVE_HOST_CPU_zen) | ||
| #define umul_ppmm(w1, w0, u, v) \ | ||
| - __asm__ ("mulx\t%3, %q0, %q1" \ | ||
| + if(hasBMI2()) { \ | ||
| + __asm__ ("mulx\t%3, %q0, %q1" \ | ||
| : "=r" (w0), "=r" (w1) \ | ||
| - : "%d" ((UDItype)(u)), "rm" ((UDItype)(v))) | ||
| -#else | ||
| -#define umul_ppmm(w1, w0, u, v) \ | ||
| - __asm__ ("mulq\t%3" \ | ||
| + : "%d" ((UDItype)(u)), "rm" ((UDItype)(v))); \ | ||
| + } else { \ | ||
| + __asm__ ("mulq\t%3" \ | ||
| : "=a" (w0), "=d" (w1) \ | ||
| - : "%0" ((UDItype)(u)), "rm" ((UDItype)(v))) | ||
| -#endif | ||
| + : "%0" ((UDItype)(u)), "rm" ((UDItype)(v))); \ | ||
| + } | ||
| #define udiv_qrnnd(q, r, n1, n0, dx) /* d renamed to dx avoiding "=d" */\ | ||
| __asm__ ("divq %4" /* stringification in K&R C */ \ | ||
| : "=a" (q), "=d" (r) \ | ||
| : "0" ((UDItype)(n0)), "1" ((UDItype)(n1)), "rm" ((UDItype)(dx))) | ||
|
|
||
| -#if HAVE_HOST_CPU_haswell || HAVE_HOST_CPU_broadwell || HAVE_HOST_CPU_skylake \ | ||
| - || HAVE_HOST_CPU_k10 || HAVE_HOST_CPU_bd1 || HAVE_HOST_CPU_bd2 \ | ||
| - || HAVE_HOST_CPU_bd3 || HAVE_HOST_CPU_bd4 || HAVE_HOST_CPU_zen \ | ||
| - || HAVE_HOST_CPU_bobcat || HAVE_HOST_CPU_jaguar | ||
| #define count_leading_zeros(count, x) \ | ||
| - do { \ | ||
| - /* This is lzcnt, spelled for older assemblers. Destination and */ \ | ||
| - /* source must be a 64-bit registers, hence cast and %q. */ \ | ||
| - __asm__ ("rep;bsr\t%1, %q0" : "=r" (count) : "rm" ((UDItype)(x))); \ | ||
| - } while (0) | ||
| + if(hasLZCNT()) { \ | ||
| + do { \ | ||
| + /* This is lzcnt, spelled for older assemblers. Destination and */ \ | ||
| + /* source must be a 64-bit registers, hence cast and %q. */ \ | ||
| + __asm__ ("rep;bsr\t%1, %q0" : "=r" (count) : "rm" ((UDItype)(x))); \ | ||
| + } while (0); \ | ||
| + } else { \ | ||
| + do { \ | ||
| + UDItype __cbtmp; \ | ||
| + ASSERT ((x) != 0); \ | ||
| + __asm__ ("bsr\t%1,%0" : "=r" (__cbtmp) : "rm" ((UDItype)(x))); \ | ||
| + (count) = __cbtmp ^ 63; \ | ||
| + } while (0); \ | ||
| + } | ||
| #define COUNT_LEADING_ZEROS_0 64 | ||
| -#else | ||
| -#define count_leading_zeros(count, x) \ | ||
| - do { \ | ||
| - UDItype __cbtmp; \ | ||
| - ASSERT ((x) != 0); \ | ||
| - __asm__ ("bsr\t%1,%0" : "=r" (__cbtmp) : "rm" ((UDItype)(x))); \ | ||
| - (count) = __cbtmp ^ 63; \ | ||
| - } while (0) | ||
| -#endif | ||
|
|
||
| -#if HAVE_HOST_CPU_bd2 || HAVE_HOST_CPU_bd3 || HAVE_HOST_CPU_bd4 \ | ||
| - || HAVE_HOST_CPU_zen || HAVE_HOST_CPU_jaguar | ||
| #define count_trailing_zeros(count, x) \ | ||
| - do { \ | ||
| - /* This is tzcnt, spelled for older assemblers. Destination and */ \ | ||
| - /* source must be a 64-bit registers, hence cast and %q. */ \ | ||
| - __asm__ ("rep;bsf\t%1, %q0" : "=r" (count) : "rm" ((UDItype)(x))); \ | ||
| - } while (0) | ||
| + if(hasBMI1()) { \ | ||
| + do { \ | ||
| + /* This is tzcnt, spelled for older assemblers. Destination and */ \ | ||
| + /* source must be a 64-bit registers, hence cast and %q. */ \ | ||
| + __asm__ ("rep;bsf\t%1, %q0" : "=r" (count) : "rm" ((UDItype)(x))); \ | ||
| + } while (0); \ | ||
| + } else { \ | ||
| + do { \ | ||
| + ASSERT ((x) != 0); \ | ||
| + __asm__ ("bsf\t%1, %q0" : "=r" (count) : "rm" ((UDItype)(x))); \ | ||
| + } while (0); \ | ||
| + } | ||
| #define COUNT_TRAILING_ZEROS_0 64 | ||
| -#else | ||
| -#define count_trailing_zeros(count, x) \ | ||
| - do { \ | ||
| - ASSERT ((x) != 0); \ | ||
| - __asm__ ("bsf\t%1, %q0" : "=r" (count) : "rm" ((UDItype)(x))); \ | ||
| - } while (0) | ||
| -#endif | ||
| #endif /* __amd64__ */ | ||
|
|
||
| #if defined (__i860__) && W_TYPE_SIZE == 32 | ||
| diff --git a/mpz/inp_raw.c b/mpz/inp_raw.c | ||
| index 378c42b..f88fea9 100644 | ||
| --- a/mpz/inp_raw.c | ||
| +++ b/mpz/inp_raw.c | ||
| @@ -88,8 +88,11 @@ mpz_inp_raw (mpz_ptr x, FILE *fp) | ||
|
|
||
| abs_csize = ABS (csize); | ||
|
|
||
| + if (UNLIKELY (abs_csize > ~(mp_bitcnt_t) 0 / 8)) | ||
| + return 0; /* Bit size overflows */ | ||
| + | ||
| /* round up to a multiple of limbs */ | ||
| - abs_xsize = BITS_TO_LIMBS (abs_csize*8); | ||
| + abs_xsize = BITS_TO_LIMBS ((mp_bitcnt_t) abs_csize * 8); | ||
|
|
||
| if (abs_xsize != 0) | ||
| { | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.