Skip to content

Commit

Permalink
build: upgrade gmp to 6.3.0 (#735)
Browse files Browse the repository at this point in the history
The advent of the zig build system on edge introduced a bug on
`macos-aarch64` and possibly `linux-aarch64` as well. This bug presented
as random loom corruption after heavy workloads such as booting from a
pill or recompiling arvo several times. The root cause ended up being
buggy assembly in GMP 6.2.1. We had disabled assembly altogether for
`macos-aarch64` in Bazel:

https://github.com/urbit/vere/blob/be3b0424f7e07c09e8dea0a63874f5e8abeae443/bazel/third_party/gmp/gmp.BUILD#L22-L23

The buggy assembly can be reproduced in isolation by downloading GMP
6.2.1 on a `macos-aarch64` machine, running `./configure --disable-share
--with-pic`, and then running `make check` and looking at all the
failing tests. This issue has been fixed in 6.3.0 and the random loom
corruption does not happen with these changes.

cc @ripperi
  • Loading branch information
pkova authored Oct 17, 2024
2 parents f59ab4e + fb807c1 commit a537c85
Show file tree
Hide file tree
Showing 50 changed files with 1,519 additions and 257 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ name: Feature pull request
on:
pull_request:
paths:
- '.bazelrc'
- '.github/workflows/*.yml'
- 'BUILD.bazel'
- 'WORKSPACE.bazel'
- 'bazel/**'
- 'build.zig'
- 'build.zig.zon'
- 'ext/**'
- '!ext/**.md'
- 'pkg/**'
- '.github/workflows/**.yml'
- '*.sh'

jobs:
urbit:
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ on:
branches:
- master
paths:
- '*.bazel'
- '.bazelrc'
- '.github/workflows/**.yml'
- 'PACE'
- 'VERSION'
- 'bazel/**'
- 'build.zig'
- 'build.zig.zon'
- 'ext/**'
- '!ext/**.md'
- 'pkg/**'

- '.github/workflows/**.yml'
- '*.sh'

jobs:
urbit:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
branches:
- 'next/kelvin/*'
paths:
- '*.bazel'
- '.bazelrc'
- '.github/workflows/**.yml'
- 'PACE'
- 'VERSION'
- 'bazel/**'
- 'build.zig'
- 'build.zig.zon'
- 'ext/**'
- '!ext/**.md'
- 'pkg/**'
- '.github/workflows/**.yml'
- '*.sh'

jobs:
urbit:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
branches:
- release
paths:
- '*.bazel'
- '.bazelrc'
- '.github/workflows/**.yml'
- 'PACE'
- 'VERSION'
- 'bazel/**'
- 'build.zig'
- 'build.zig.zon'
- 'ext/**'
- '!ext/**.md'
- 'pkg/**'
- '.github/workflows/**.yml'
- '*.sh'

jobs:
urbit:
Expand Down
1 change: 1 addition & 0 deletions ext/gmp/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ const generic_c_sources = [_][]const u8{
"mpn/generic/mulmid_basecase.c",
"mpn/generic/mulmid_n.c",
"mpn/generic/mulmod_bnm1.c",
"mpn/generic/mulmod_bknp1.c",
"mpn/generic/neg.c",
"mpn/generic/nussbaumer_mul.c",
"mpn/generic/perfpow.c",
Expand Down
4 changes: 2 additions & 2 deletions ext/gmp/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.version = "0.0.1",
.dependencies = .{
.gmp = .{
.url = "https://github.com/alisw/GMP/archive/refs/tags/v6.2.1.tar.gz",
.hash = "12209dd340fd48ad775604d2d4e95155dcf106b8f6c63dd054641d606e2007d806f4",
.url = "https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.gz",
.hash = "1220d46202c17aa35ab5848a7f7a812b797c9f07698f263c8a02b4ad9640a1bbe0e3",
},
},
.paths = .{
Expand Down
1 change: 1 addition & 0 deletions ext/gmp/gen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Now, under the GMP root dir run `make` and copy these files as well:
- `fac_table.h`
- `fib_table.h`
- `trialdivtab.h`
- `sieve_table.h`
- `mpn/fib_table.c`
- `mpn/jacobitab.h`
- `mpn/mp_bases.c`
Expand Down
20 changes: 12 additions & 8 deletions ext/gmp/gen/aarch64-linux/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*
Copyright 1996-2020 Free Software Foundation, Inc.
Copyright 1996-2022 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
Expand Down Expand Up @@ -187,6 +187,7 @@ see https://www.gnu.org/licenses/.
/* #undef HAVE_HOST_CPU_skylake */
/* #undef HAVE_HOST_CPU_silvermont */
/* #undef HAVE_HOST_CPU_goldmont */
/* #undef HAVE_HOST_CPU_tremont */
/* #undef HAVE_HOST_CPU_k8 */
/* #undef HAVE_HOST_CPU_k10 */
/* #undef HAVE_HOST_CPU_bulldozer */
Expand All @@ -201,6 +202,9 @@ see https://www.gnu.org/licenses/.
/* #undef HAVE_HOST_CPU_s390_z9 */
/* #undef HAVE_HOST_CPU_s390_z10 */
/* #undef HAVE_HOST_CPU_s390_z196 */
/* #undef HAVE_HOST_CPU_s390_z13 */
/* #undef HAVE_HOST_CPU_s390_z14 */
/* #undef HAVE_HOST_CPU_s390_z15 */

/* Define to 1 iff we have a s390 with 64-bit registers. */
/* #undef HAVE_HOST_CPU_s390_zarch */
Expand Down Expand Up @@ -300,7 +304,7 @@ see https://www.gnu.org/licenses/.
/* #undef HAVE_NATIVE_mpn_div_qr_2 */
/* #undef HAVE_NATIVE_mpn_divexact_1 */
/* #undef HAVE_NATIVE_mpn_divexact_by3c */
/* #undef HAVE_NATIVE_mpn_divrem_1 */
#define HAVE_NATIVE_mpn_divrem_1 1
/* #undef HAVE_NATIVE_mpn_divrem_1c */
/* #undef HAVE_NATIVE_mpn_divrem_2 */
/* #undef HAVE_NATIVE_mpn_gcd_1 */
Expand Down Expand Up @@ -333,7 +337,7 @@ see https://www.gnu.org/licenses/.
#define HAVE_NATIVE_mpn_nand_n 1
#define HAVE_NATIVE_mpn_nior_n 1
#define HAVE_NATIVE_mpn_popcount 1
/* #undef HAVE_NATIVE_mpn_preinv_divrem_1 */
#define HAVE_NATIVE_mpn_preinv_divrem_1 1
/* #undef HAVE_NATIVE_mpn_preinv_mod_1 */
/* #undef HAVE_NATIVE_mpn_redc_1 */
/* #undef HAVE_NATIVE_mpn_redc_2 */
Expand Down Expand Up @@ -382,7 +386,7 @@ see https://www.gnu.org/licenses/.
#define HAVE_NL_TYPES_H 1

/* Define to 1 if you have the `obstack_vprintf' function. */
/* #define HAVE_OBSTACK_VPRINTF 1 */
/* #undef HAVE_OBSTACK_VPRINTF 1 */

/* Define to 1 if you have the `popen' function. */
#define HAVE_POPEN 1
Expand Down Expand Up @@ -542,13 +546,13 @@ see https://www.gnu.org/licenses/.
#define PACKAGE "gmp"

/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "[email protected], see https://gmplib.org/manual/Reporting-Bugs.html"
#define PACKAGE_BUGREPORT "[email protected] (see https://gmplib.org/manual/Reporting-Bugs.html)"

/* Define to the full name of this package. */
#define PACKAGE_NAME "GNU MP"

/* Define to the full name and version of this package. */
#define PACKAGE_STRING "GNU MP 6.2.1"
#define PACKAGE_STRING "GNU MP 6.3.0"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "gmp"
Expand All @@ -557,7 +561,7 @@ see https://www.gnu.org/licenses/.
#define PACKAGE_URL "http://www.gnu.org/software/gmp/"

/* Define to the version of this package. */
#define PACKAGE_VERSION "6.2.1"
#define PACKAGE_VERSION "6.3.0"

/* Define as the return type of signal handlers (`int' or `void'). */
#define RETSIGTYPE void
Expand Down Expand Up @@ -590,7 +594,7 @@ see https://www.gnu.org/licenses/.
#define TUNE_SQR_TOOM2_MAX SQR_TOOM2_MAX_GENERIC

/* Version number of package */
#define VERSION "6.2.1"
#define VERSION "6.3.0"

/* Define to 1 to enable ASSERT checking, per --enable-assert */
/* #undef WANT_ASSERT */
Expand Down
46 changes: 46 additions & 0 deletions ext/gmp/gen/aarch64-linux/sieve_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* This file generated by gen-sieve.c - DO NOT EDIT. */

#if GMP_LIMB_BITS != 64
Error, error, this data is for 64 bits
#endif

#define PRIMESIEVE_INIT_TABLE \
CNST_LIMB (0x3294C9E069128480), /* 5 - 196 (42 primes) */ \
CNST_LIMB (0x95A35E1EC4AB21DC), /* 197 - 388 (32 primes) */ \
CNST_LIMB (0x4AD7CE99B8693366), /* 389 - 580 (30 primes) */ \
CNST_LIMB (0x6595B6DA728DC52B), /* 581 - 772 (30 primes) */ \
CNST_LIMB (0xEA6D9F8787B0CEDE), /* 773 - 964 (26 primes) */ \
CNST_LIMB (0x3F56A1F4CD3275A9), /* 965 - 1156 (29 primes) */ \
CNST_LIMB (0xFD3848FB74A76ADB), /* 1157 - 1348 (26 primes) */ \
CNST_LIMB (0xDBBA0DD1A1EDF6AF), /* 1349 - 1540 (25 primes) */ \
CNST_LIMB (0xCEC7F17ED22799A5), /* 1541 - 1732 (27 primes) */ \
CNST_LIMB (0xEAEC17BDBB717D56), /* 1733 - 1924 (24 primes) */ \
CNST_LIMB (0x3B0EB7B3585AFCF3), /* 1925 - 2116 (26 primes) */ \
CNST_LIMB (0xE563D8F69FDF6C4F), /* 2117 - 2308 (23 primes) */ \
CNST_LIMB (0xFE5BA7ABA45E92FC), /* 2309 - 2500 (25 primes) */ \
CNST_LIMB (0x158DEE6F3BF49B7D), /* 2501 - 2692 (24 primes) */ \
CNST_LIMB (0xBE5A7BC4EDE6CD1A), /* 2693 - 2884 (26 primes) */ \
CNST_LIMB (0xD7679B3FCA7BB6AD), /* 2885 - 3076 (22 primes) */ \
CNST_LIMB (0xC3F66B971FEF37E9), /* 3077 - 3268 (22 primes) */ \
CNST_LIMB (0x6F7EBCF339C953FD), /* 3269 - 3460 (22 primes) */ \
CNST_LIMB (0xD5A5ECDCD235DBF0), /* 3461 - 3652 (27 primes) */ \
CNST_LIMB (0xECFA7B2FD5B65E3B), /* 3653 - 3844 (22 primes) */ \
CNST_LIMB (0xD28EFDF9C89F67B1), /* 3845 - 4036 (25 primes) */ \
CNST_LIMB (0xCB7F7C7A3DD3AF4F), /* 4037 - 4228 (21 primes) */ \
CNST_LIMB (0xEEBED6CDFF6B32CC), /* 4229 - 4420 (22 primes) */ \
CNST_LIMB (0xD5BD73F85ECFA97C), /* 4421 - 4612 (23 primes) */ \
CNST_LIMB (0x21FDBE4FBBAD48F7), /* 4613 - 4804 (24 primes) */ \
CNST_LIMB (0x5E35A3B5EEB7FDE7), /* 4805 - 4996 (21 primes) */ \
CNST_LIMB (0xD9EBFD53A7DBBCC9), /* 4997 - 5188 (22 primes) */ \
CNST_LIMB (0xFF9EDEAF2EFE1F76), /* 5189 - 5380 (18 primes) */
#define PRIMESIEVE_NUMBEROF_TABLE 28
/* #define PRIMESIEVE_PRIMES_IN_TABLE 706 */
#define PRIMESIEVE_HIGHEST_PRIME 5351
/* #define PRIMESIEVE_FIRST_UNCHECKED 5381 */

#define SIEVE_MASK1 CNST_LIMB(0x3204C1A049120485)
#define SIEVE_MASKT CNST_LIMB(0xA1204892058)
#define SIEVE_2MSK1 CNST_LIMB(0x29048402110840A)
#define SIEVE_2MSK2 CNST_LIMB(0x9402180C40230184)
#define SIEVE_2MSKT CNST_LIMB(0x5021088402120)

12 changes: 6 additions & 6 deletions ext/gmp/gen/aarch64-macos/mpn/add_n.s
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ ___gmpn_add_nc:

___gmpn_add_n:
cmn xzr, xzr
Lent: lsr x18, x3, #2
Lent: lsr x17, x3, #2
tbz x3, #0, Lbx0

Lbx1: ldr x7, [x1]
Expand All @@ -86,7 +86,7 @@ Lbx1: ldr x7, [x1]
str x13, [x0],#8
tbnz x3, #1, Lb11

Lb01: cbz x18, Lret
Lb01: cbz x17, Lret
ldp x4, x5, [x1,#8]
ldp x8, x9, [x2,#8]
sub x1, x1, #8
Expand All @@ -97,7 +97,7 @@ Lb11: ldp x6, x7, [x1,#8]
ldp x10, x11, [x2,#8]
add x1, x1, #8
add x2, x2, #8
cbz x18, Lend
cbz x17, Lend
b Ltop

Lbx0: tbnz x3, #1, Lb10
Expand All @@ -110,7 +110,7 @@ Lb00: ldp x4, x5, [x1]

Lb10: ldp x6, x7, [x1]
ldp x10, x11, [x2]
cbz x18, Lend
cbz x17, Lend

.align 4
Ltop: ldp x4, x5, [x1,#16]
Expand All @@ -123,8 +123,8 @@ Lmid: ldp x6, x7, [x1,#32]!
adcs x12, x4, x8
adcs x13, x5, x9
stp x12, x13, [x0],#16
sub x18, x18, #1
cbnz x18, Ltop
sub x17, x17, #1
cbnz x17, Ltop

Lend: adcs x12, x6, x10
adcs x13, x7, x11
Expand Down
12 changes: 6 additions & 6 deletions ext/gmp/gen/aarch64-macos/mpn/addlsh1_n.s
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@
.globl ___gmpn_addlsh1_n

___gmpn_addlsh1_n:
lsr x18, x3, #2
lsr x6, x3, #2
tbz x3, #0, Lbx0

Lbx1: ldr x5, [x1]
tbnz x3, #1, Lb11

Lb01: ldr x11, [x2]
cbz x18, L1
cbz x6, L1
ldp x8, x9, [x2,#8]
lsl x13, x11, #1
adds x15, x13, x5
Expand All @@ -115,7 +115,7 @@ Lb11: ldr x9, [x2]
adds x17, x13, x5
str x17, [x0],#8
sub x1, x1, #8
cbz x18, Lend
cbz x6, Lend
b Ltop

Lbx0: tbnz x3, #1, Lb10
Expand All @@ -128,7 +128,7 @@ Lb00: adds x11, xzr, xzr
Lb10: adds x9, xzr, xzr
ldp x10, x11, [x2]
sub x1, x1, #16
cbz x18, Lend
cbz x6, Lend

.align 4
Ltop: ldp x4, x5, [x1,#16]
Expand All @@ -145,8 +145,8 @@ Lmid: ldp x4, x5, [x1,#32]!
adcs x16, x12, x4
adcs x17, x13, x5
stp x16, x17, [x0],#16
sub x18, x18, #1
cbnz x18, Ltop
sub x6, x6, #1
cbnz x6, Ltop

Lend: ldp x4, x5, [x1,#16]
extr x12, x10, x9, #63
Expand Down
12 changes: 6 additions & 6 deletions ext/gmp/gen/aarch64-macos/mpn/addlsh2_n.s
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@
.globl ___gmpn_addlsh2_n

___gmpn_addlsh2_n:
lsr x18, x3, #2
lsr x6, x3, #2
tbz x3, #0, Lbx0

Lbx1: ldr x5, [x1]
tbnz x3, #1, Lb11

Lb01: ldr x11, [x2]
cbz x18, L1
cbz x6, L1
ldp x8, x9, [x2,#8]
lsl x13, x11, #2
adds x15, x13, x5
Expand All @@ -115,7 +115,7 @@ Lb11: ldr x9, [x2]
adds x17, x13, x5
str x17, [x0],#8
sub x1, x1, #8
cbz x18, Lend
cbz x6, Lend
b Ltop

Lbx0: tbnz x3, #1, Lb10
Expand All @@ -128,7 +128,7 @@ Lb00: adds x11, xzr, xzr
Lb10: adds x9, xzr, xzr
ldp x10, x11, [x2]
sub x1, x1, #16
cbz x18, Lend
cbz x6, Lend

.align 4
Ltop: ldp x4, x5, [x1,#16]
Expand All @@ -145,8 +145,8 @@ Lmid: ldp x4, x5, [x1,#32]!
adcs x16, x12, x4
adcs x17, x13, x5
stp x16, x17, [x0],#16
sub x18, x18, #1
cbnz x18, Ltop
sub x6, x6, #1
cbnz x6, Ltop

Lend: ldp x4, x5, [x1,#16]
extr x12, x10, x9, #62
Expand Down
5 changes: 5 additions & 0 deletions ext/gmp/gen/aarch64-macos/mpn/addmul_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@











Expand Down
Loading

0 comments on commit a537c85

Please sign in to comment.