Add optional GMP-backed bignum multiplication#1008
Open
Peter1169 wants to merge 1 commit into
Open
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This adds an opt-in
--enable-gmp-bignumconfigure option that uses LibGMP for large bignum multiplication and squaring.The default build remains unchanged. When the option is enabled, configure checks for
gmp.hand-lgmp, defines___USE_GMP_BIGNUMfor the Gambit runtime library build, and large bignum multiplication tries the GMP path before falling back to Gambit's existing algorithms.The GMP path keeps Gambit's bignum representation unchanged:
mpz_tvaluesmpz_mulfor multiplication and squaringRelated to #761.
Validation
Validated on Linux/WSL and in Docker
gcc:9.3.0with LibGMP installed../configure,make -j6 from-scratchGAMBITLIB_DEFSand_num.ocompile lines do not include-D___USE_GMP_BIGNUM../gsi/gsi -:tl,~~bin=../bin,~~lib=../lib,~~include=../include -f ./run-unit-tests.scm unit-tests/03-number/_num.scm./configure --enable-gmp-bignum,make -j6 from-scratchgmp.hand__gmpz_mulin-lgmplib/_num.ccontains the___USE_GMP_BIGNUMguards andmpz_mulcallsGAMBITLIB_DEFScontains-D___USE_GMP_BIGNUMinmakefile,lib/makefile, andlib/module-common.mk_num.ocompile lines include-D___USE_GMP_BIGNUM../gsi/gsi -:tl,~~bin=../bin,~~lib=../lib,~~include=../include -f ./run-unit-tests.scm unit-tests/03-number/_num.scmmaster:git diff --check origin/master...HEADA local bignum multiplication/squaring probe used non-sparse operands and checked result tails modulo
1000000007; the default and GMP builds produced matching tails.0.019825s0.000939s21.1x8,127,200254,0800.013814s0.000669s20.6x5,503,200254,0800.021878s0.001537s14.2x8,117,880251,3600.015129s0.001080s14.0x5,495,840251,400Disclosure: I used Codex (GPT-5.5 xHigh) for a final code review pass after human programming.