1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00
Commit graph

20730 commits

Author SHA1 Message Date
Andy Wingo
9b9149a5bf Rework bootstrap to be reproducible
* configure.ac:
* Makefile.am (SUBDIRS): Replace bootstrap/ with stage0, stage1, and
stage2.
* am/bootstrap.am: Include all files and all rules.
* meta/build-env.in (GUILE_AUTO_COMPILE): Always turn off
auto-compilation.  Take a GUILE_BOOTSTRAP_STAGE argument, which can be
stage0, stage1, stage2, or unset.  Adapt the load-compiled path
accordingly.
* meta/uninstalled-env.in: Include .go files from stage2.
* module/Makefile.am: Rework to use boostrap.am.
* module/system/base/optimize.scm (available-optimizations): Punt the
inlinable-exports machinery to -O2.
* stage0/Makefile.am:
* stage1/Makefile.am:
* stage2/Makefile.am: New files.
2022-02-01 14:50:40 +01:00
Andy Wingo
6ed66f42cb Add -ftlo support
* configure.ac: Check if the compiler supports link-time optimization.
If it does, turn it on.  Saves around 15% off libguile binary size.
Controllable via --enable-lto configure option.
2022-01-29 15:49:43 +01:00
Andy Wingo
373f35b5f7 peval cross-module-inlining gracefully handles missing interface
* module/language/tree-il/peval.scm (peval): The intention was for
resolve-interface to return an interface only if it exists, but actually
it throws if the interface isn't know.  Fix to do what we intended to
do.
2022-01-17 21:25:08 +01:00
Andy Wingo
d01ab7bf5c Fix inlinable-exports bug for pure modules
* module/language/tree-il/inlinable-exports.scm (compute-decoder): Fix
bug in which inlinable exports in a pure module would have a missing
make-struct/no-tail binding.
2022-01-17 21:07:22 +01:00
Andy Wingo
222b320868 Remove dead code in scm_integer_inexact_sqrt_z
* libguile/integers.c (scm_integer_inexact_sqrt_z): Remove some dead
code.
2022-01-13 09:37:17 +01:00
Daniel Llorens
19bc021e34 Have log and log10(real nan) return real nan regardless of sign
* libguile/numbers.c (log_of_shifted_double, scm_log10): Avoid complex
  extension when the argument is a real nan.
* test-suite/tests/numbers.test: Tests for nans of either sign.
2022-01-13 09:37:17 +01:00
Daniel Llorens
4feff820be Don't use HAVE_COPYSIGN in libguile/numbers.c
* libguile/numbers.c (icmplx2str): As stated. copysign() is required by C99 and
  already used without guards elsewhere in this file.
2022-01-13 09:37:17 +01:00
Daniel Llorens
6058d9e05d Simplify scm_abs for the real case
* libguile/numbers.c (scm_abs): As stated. When x is a nan with the sign bit
  set, this changes the behavior of (magnitude x) back to what it was in 3.0.7,
  to clear that bit.
2022-01-13 09:37:17 +01:00
Andy Wingo
9e5aa173c7 Optimize logand against a positive inum
* libguile/integers.c (scm_integer_logand_zi): Optimize.
2022-01-13 09:37:17 +01:00
Andy Wingo
6fe43301aa Optimize integer-expt for fixnums
* libguile/integers.c (scm_integer_expt_ii): Add some optimizations for
cases in which we can avoid allocating an mpz.
2022-01-13 09:37:17 +01:00
Andy Wingo
2cf80ca238 Optimize scm_integer_mul_ii
* libguile/integers.c (make_bignum_2): Always include.
(scm_integer_mul_ii): Avoid making a temporary allocation.
2022-01-13 09:37:17 +01:00
Andy Wingo
210ab8ff76 Optimize bignum subtraction
* libguile/integers.c (scm_integer_sub_iz):
(scm_integer_sub_zi):
(scm_integer_sub_zz): Optimize to avoid temporary allocations.
2022-01-13 09:37:17 +01:00
Andy Wingo
cc52f01aba Optimize bignum add to avoid temporary allocations
* libguile/integers.c (do_add_1, do_add, do_sub_1, do_sub, do_cmp): New
helpers.
(scm_integer_add_zi):
(scm_integer_add_zz): Use new helpers.
2022-01-13 09:37:17 +01:00
Andy Wingo
95350aae8c Avoid bignum clone in scm_integer_sub_zz
* libguile/integers.c (scm_integer_abs_z): Just call
scm_integer_negate_z if negation is needed.
(scm_integer_sub_zz): Use mpz_sub instead of cloning bignum.
2022-01-13 09:37:17 +01:00
Andy Wingo
cae8b30163 Start to optimize scm_integer_sub_iz
* libguile/integers.c (scm_integer_sub_iz): Avoid cloning bignum.
2022-01-13 09:37:17 +01:00
Andy Wingo
2723513712 Less pessimal scm_integer_sub_zi
* libguile/integers.c (scm_integer_sub_zi): Only delegate to
scm_integer_add_ii if y is negative.
2022-01-13 09:37:17 +01:00
Andy Wingo
ad6811a12b Optimize scm_integer_mul_zz.
* libguile/integers.c (scm_integer_mul_zz): Optimize to avoid temporary
allocations.
2022-01-13 09:37:17 +01:00
Andy Wingo
d89f75c535 Optimize scm_integer_mul_zi
* libguile/integers.c (bignum_trim1):
(bignum_negate_if): New helpers.
(scm_integer_mul_zi): Use the mpn API to avoid temporary allocation.
2022-01-13 09:37:17 +01:00
Andy Wingo
5481222670 Re-rewrite integer-expt in C
Calling out to Scheme was a performance regression.

* libguile/integers.h:
* libguile/integers.c (scm_integer_expt_ii, scm_integer_expt_zi): New
internal functions.
* libguile/numbers.c (scm_integer_expt): Go back to C.  But, include
fast cases for inums and doubles.
* module/ice-9/boot-9.scm: Revert addition of integer-expt.
2022-01-13 09:37:17 +01:00
Andy Wingo
eac47c3e45 Fix bug when making mpz from 0
* libguile/integers.c (make_bignum_0): New helper.
(make_bignum_from_uint64):
(ulong_to_bignum):
(long_to_bignum): Call new helper as appropriate.
2022-01-13 09:37:17 +01:00
Andy Wingo
443d239828 take_mpz optimization
* libguile/integers.c (take_mpz): Avoid making a bignum if the value is
fixable.
2022-01-13 09:37:17 +01:00
Andy Wingo
aa5455ea98 Bignums avoid both custom GMP allocator and finalizers
* libguile/deprecated.c (make_bignum): Move here from numbers.c, to
support scm_i_long2big etc.
(scm_i_big2dbl):
(scm_i_long2big):
(scm_i_ulong2big):
(scm_i_clonebig):
(scm_i_normbig): Deprecate.
(scm_install_gmp_memory_functions): Deprecate, happily!  SCM bignums now
have digits allocated inline with the bignum itself, so they are
completely transparent to the GC already.  The price is that if GMP ever
allocates digits via the MPZ API, those digits then have to be copied
back into managed memory.  But we avoid having to install finalizers and
we avoid having to muck with GMP's allocator.
* libguile/numbers.c (scm_from_mpz): Use scm_integer_from_mpz.
(scm_init_numbers): Never muck with GMP's allocators.
* doc/ref/guile-invoke.texi (Environment Variables): Remove note about
GUILE_INSTALL_GMP_MEMORY_FUNCTIONS.
* meta/build-env.in: No need to set GUILE_INSTALL_GMP_MEMORY_FUNCTIONS.
2022-01-13 09:37:17 +01:00
Andy Wingo
a0765f564a scm_to_ipv6 uses scm_to_mpz
* libguile/socket.c (scm_to_ipv6): Use scm_to_mpz.
2022-01-13 09:37:17 +01:00
Andy Wingo
e78bcdc29a Finish srfi-60 port off old scm mpz API
* libguile/srfi-60.c (scm_srfi60_rotate_bit_field)
(scm_srfi60_reverse_bit_field, scm_srfi60_integer_to_list)
(scm_srfi60_list_to_integer): Update.
2022-01-13 09:37:17 +01:00
Andy Wingo
399d0c8745 Start porting srfi-60 off the bad bignum interfaces
* libguile/integers.h:
* libguile/integers.c (scm_integer_scan1_i):
(scm_integer_scan1_z): New internal functions.
* libguile/srfi-60.c (scm_srfi60_log2_binary_factors): Use scan1
functions.
(scm_srfi60_copy_bit): Use integers lib.
2022-01-13 09:37:17 +01:00
Andy Wingo
bdddef3cfd Avoid scm_i_mkbig outside numbers.c.
* libguile/random.c (scm_c_random_bignum):
* libguile/socket.c (scm_from_ipv6): Avoid scm_i_mkbig.
* libguile/numbers.h:
* libguile/numbers.c (scm_i_mkbig): Remove.
2022-01-13 09:37:17 +01:00
Andy Wingo
0c502a4d3c Use scm_integer_to_double_z in numbers.c instead of big2dbl
* libguile/numbers.c: Use internal function instead of big2dbl which we
will deprecate.
2022-01-13 09:37:17 +01:00
Andy Wingo
7029a9c491 Simplify magnitude, angle
* libguile/numbers.c (scm_i_inum2big): Remove.
(scm_magnitude): Delegate to abs.
(scm_angle): Simplify.
2022-01-13 09:37:17 +01:00
Andy Wingo
3d56a90736 Remove last non-admin SCM_I_BIG_MPZ uses in numbers.c
* libguile/numbers.c (scm_magnitude, scm_angle): Use integers lib.
2022-01-13 09:37:17 +01:00
Andy Wingo
a4524da8c1 Simplify scm_exact_integer_quotient
* libguile/integers.h:
* libguile/integers.c (scm_integer_exact_quotient_iz): New internal
function.
* libguile/numbers.c (scm_i_make_ratio): Simplify and enforce
invariants.
(scm_exact_integer_quotient): Use integer lib.
2022-01-13 09:37:17 +01:00
Andy Wingo
0754dbf3e8 divide2double refactor
* libguile/integers.c (scm_integer_set_mpz_z): New internal function.
(scm_integer_init_set_mpz_z): Rename from scm_integer_to_mpz_z.
* libguile/integers.h:
* libguile/numbers.c (scm_i_divide2double): Avoid SCM_I_BIG_MPZ.
2022-01-13 09:37:17 +01:00
Andy Wingo
c06fc3df54 Remove dead bignum frexp code from numbers.c
* libguile/numbers.c (scm_i_big2dbl_2exp): Remove unused function.
2022-01-13 09:37:17 +01:00
Andy Wingo
f167627bb0 Expose frexp from integers lib
* libguile/integers.h:
* libguile/integers.c (scm_integer_frexp_z): Expose internally.
(scm_integer_to_double_z):
(scm_integer_inexact_sqrt_z): Adapt uses.
* libguile/numbers.c (log_of_exact_integer): Use exposed
scm_integer_frexp_z.
2022-01-13 09:37:17 +01:00
Andy Wingo
124d889227 Refactor scm_sqrt in terms of integers.[ch]
* libguile/integers.h:
* libguile/integers.c (scm_is_integer_perfect_square_i):
(scm_is_integer_perfect_square_z):
(scm_integer_floor_sqrt_i):
(scm_integer_floor_sqrt_z):
(scm_integer_inexact_sqrt_i):
(scm_integer_inexact_sqrt_z): New internal functions.
* libguile/numbers.c (scm_sqrt): Reimplement.
2022-01-13 09:37:17 +01:00
Andy Wingo
63a18a6c1a Reimplement exact-integer-sqrt with integers.[ch]
* libguile/numbers.c (scm_exact_integer_sqrt): Call out.
* libguile/integers.h:
* libguile/integers.c (scm_integer_exact_sqrt_i):
(scm_integer_exact_sqrt_z): New internal functions.
2022-01-13 09:37:17 +01:00
Andy Wingo
9a91c20a55 scm_to_mpz uses integer lib
* libguile/integers.h:
* libguile/integers.c (scm_integer_to_mpz_z): New internal function.
* libguile/numbers.c (scm_to_mpz): Use new function.
2022-01-13 09:37:17 +01:00
Andy Wingo
debcccc215 Remove unused conv-{u,}integer.i.c
* libguile/Makefile.am (noinst_HEADERS):
* libguile/conv-integer.i.c:
* libguile/conv-uinteger.i.c: Remove.
2022-01-13 09:37:17 +01:00
Andy Wingo
106c5de5fc Implement scm_{to,from}_wchar inline
* libguile/numbers.c (scm_to_wchar, scm_from_wchar): Implement inline.
2022-01-13 09:37:17 +01:00
Andy Wingo
1802ed17b3 Reimplement scm_{to,from}_{int64,uint64}
* libguile/numbers.c (scm_to_int64, scm_from_int64, scm_to_uint64):
(scm_from_uint64): Reimplement inline.
2022-01-13 09:37:17 +01:00
Andy Wingo
717e787da6 Reimplement scm_{to,from}_{int32,uint32}
* libguile/numbers.c (scm_to_int32, scm_from_int32, scm_to_uint32):
(scm_from_uint32): Reimplement inline.
* libguile/integers.c (make_bignum_2):
(make_bignum_from_uint64):
(negative_uint32_to_int32):
(positive_uint32_to_int32):
(bignum_to_int32):
(bignum_to_uint32):
(scm_integer_from_int32):
(scm_integer_from_uint32):
(scm_integer_to_int32_z):
(scm_integer_to_uint32_z): Better int32 support for 32-bit machines.
2022-01-13 09:37:17 +01:00
Andy Wingo
27910181c5 Reimplement scm_from_int8 etc
* libguile/integers.c (make_bignum_from_uint64):
(make_bignum_from_int64): New helpers.
(scm_integer_from_int64):
(scm_integer_from_uint64): New internal functions.
* libguile/integers.h: Declare new internal functions.
* libguile/numbers.c (range_error): Declare as noreturn.xo
(inum_in_range): New helper.
(scm_from_signed_integer):
(scm_to_signed_integer):
(scm_from_unsigned_integer):
(scm_to_unsigned_integer):
(scm_to_int8):
(scm_from_int8):
(scm_to_uint8):
(scm_from_uint8):
(scm_to_int16):
(scm_from_int16):
(scm_to_uint16):
(scm_from_uint16): Implement manually.
2022-01-13 09:37:16 +01:00
Andy Wingo
f4db3ca3f9 Reimplement scm_is_{un,}signed_integer for bignums
* libguile/integers.c (negative_int64):
(int64_magnitude):
(negative_uint64_to_int64):
(positive_uint64_to_int64):
(bignum_to_int64):
(bignum_to_uint64): New helpers.
(scm_integer_to_int64_z):
(scm_integer_to_uint64_z): New internal functions.
* libguile/integers.h: Declare internal functions.
* libguile/numbers.c (scm_is_signed_integer):
(scm_is_unsigned_integer): Simplify bigint cases.
2022-01-13 09:37:16 +01:00
Andy Wingo
7c53325c31 Fix scm_integer_to_double_z to always round; clean ups
* libguile/integers.c (scm_integer_to_double_z): Doubles that can't be
exactly represented as integers should round.
(bignum_frexp_z): New helper.
(scm_integer_from_mpz, scm_integer_from_double): New internal functions.
* libguile/numbers.h:
* libguile/numbers.c (scm_i_bigcmp, scm_i_dbl2big, scm_i_dbl2num):
Remove unused internal functions.
(scm_inexact_to_exact): Rework to avoid scm_i_dbl2big.
(scm_bigequal): Move here, from eq.c.
(scm_integer_to_double_z): Use the new helper.
(scm_i_big2dbl): Use scm_integer_to_double_z.
2022-01-13 09:37:16 +01:00
Andy Wingo
f2390e510f Fix deprecated bit-count* when counting 0 bits
* libguile/deprecated.c (scm_bit_count_star): Fix logic to count 0
bits.
2022-01-13 09:37:16 +01:00
Andy Wingo
8b2d58b993 Clean up scm_divide
* libguile/integers.h:
* libguile/integers.c (scm_is_integer_divisible_ii):
(scm_is_integer_divisible_zi):
(scm_is_integer_divisible_zz): New helpers.
* libguile/numbers.c (invert, divide, complex_div): New helpers for
scm_divide.
(scm_divide): Adapt.
2022-01-13 09:37:16 +01:00
Andy Wingo
3e08c9cec0 Remove support for allowing exact numbers to be divided by zero
* libguile/numbers.c: We require IEEE infinities and NaN so there is no
case in which ALLOW_DIVIDE_BY_ZERO would not be defined.
(scm_divide, scm_tan, scm_tanh, scm_log, scm_log10): Always throw on
overflow for divide by exact zero, never throw for divide by inexact
zero.
2022-01-13 09:37:16 +01:00
Andy Wingo
9179525a05 Simplify scm_product, use integer lib
* libguile/numbers.c (scm_product): Remove need for s_product defines.
Call out to product, as appropriate.
(product): New helper.
* libguile/integers.h:
* libguile/integers.c (scm_integer_mul_ii):
(scm_integer_mul_zi):
(scm_integer_mul_zz): New internal functions.
2022-01-13 09:37:16 +01:00
Andy Wingo
c096670d38 Simplify scm_difference, use integer lib
* libguile/numbers.c (scm_sum): Remove need for s_sum defines.
(negate, difference): New helpers.
(scm_difference): Call out to difference or negate, as appropriate.
* libguile/integers.h:
* libguile/integers.c (scm_integer_negate_i):
(scm_integer_negate_z):
(scm_integer_sub_ii):
(scm_integer_sub_iz):
(scm_integer_sub_zi):
(scm_integer_sub_zz): New internal functions.
2022-01-13 09:37:16 +01:00
Andy Wingo
10953e067c Clean up scm_sum
* libguile/integers.h:
* libguile/integers.c (scm_integer_to_double_z):
(scm_integer_add_ii, scm_integer_add_zi, scm_integer_add_zz): New
internal functions.
* libguile/numbers.c (sum): New helper for scm_sum.  Clean up to avoid
repetition.  The dispatch is less optimal but the code is shorter and
more maintainable; in any case if speed is important, the compiler needs
to be involved.
(scm_sum): Adapt.
2022-01-13 09:37:16 +01:00
Andy Wingo
281aed8aa0 Simplify implementation of min, max
* libguile/numbers.c (scm_max, scm_min): Lean more on scm_is_less_than.
2022-01-13 09:37:16 +01:00