1. 09 Jul, 2020 1 commit
    • Paul Eggert's avatar
      Use Gnulib libgmp module · c8b6006d
      Paul Eggert authored
      Instead of doing GMP by hand, use the Gnulib libgmp module.
      * .gitignore: Add lib/gmp.h.
      * admin/merge-gnulib (GNULIB_MODULES): Add libgmp.
      * configure.ac (GMP_LIB, GMP_OBJ): Remove.  Gnulib uses the name
      LIB_GMP, so all uses changed.  All uses of GMP_OBJ removed.
      (HAVE_GMP): Set this from Gnulib’s variables.
      * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
      * lib/mini-gmp-gnulib.c, lib/mini-gmp.c, lib/mini-gmp.h, m4/libgmp.m4:
      New files, copied from Gnulib.
      * src/bignum.h, test/data/emacs-module/mod-test.c:
      Include gmp.h unconditionally.
      * src/mini-gmp-emacs.c, src/mini-gmp.c, src/mini-gmp.h:
      Remove.  This moves these files from src to lib, and
      updates them to the current GMP version.
      * test/Makefile.in (GMP_H): New macro.
      ($(test_module)): Use it to decide whether to compile
      mini-gmp-gnulib.c too.
      c8b6006d
  2. 06 May, 2020 1 commit
  3. 27 Mar, 2020 1 commit
  4. 01 Jan, 2020 1 commit
  5. 13 Nov, 2019 1 commit
    • Paul Eggert's avatar
      Refactor bignum multiplication, exponentiation · 02e637ec
      Paul Eggert authored
      This doesn’t alter behavior, and simplifies the next commit.
      * src/bignum.c (GMP_NLIMBS_MAX, NLIMBS_LIMIT, emacs_mpz_size)
      (emacs_mpz_mul, emacs_mpz_mul_2exp, emacs_mpz_pow_ui): Move here ...
      * src/data.c: ... from here.
      02e637ec
  6. 21 Aug, 2019 2 commits
    • Paul Eggert's avatar
      Be more careful about pointers to bignum vals · 39fee209
      Paul Eggert authored
      This uses ‘const’ to be better at catching bugs that
      mistakenly attempt to modify a bignum value.
      Lisp bignums are supposed to be immutable.
      * src/alloc.c (make_pure_bignum):
      * src/fns.c (sxhash_bignum):
      Accept Lisp_Object instead of struct Lisp_Bignum *, as that’s
      simpler now.  Caller changed.
      * src/bignum.h (bignum_val, xbignum_val): New inline functions.
      Prefer them to &i->value and XBIGNUM (i)->value, since they
      apply ‘const’ to the result.
      * src/timefns.c (lisp_to_timespec): Use mpz_t const *
      to point to a bignum value.
      39fee209
    • Paul Eggert's avatar
      Avoid some excess precision in time arithmetic · 396ed88a
      Paul Eggert authored
      * doc/misc/emacs-mime.texi (time-date):
      Adjust example to match new behavior.
      * etc/NEWS: Mention this.
      * lisp/calendar/time-date.el (decoded-time-add)
      (decoded-time--alter-second):
      Don’t lose underestimate precision of seconds component.
      * src/bignum.c (mpz): Grow by 1.
      * src/timefns.c (trillion_factor): New function.
      (timeform_sub_ps_p): Remove.
      (time_arith): Avoid unnecessarily-large hz, by reducing the hz
      to a value no worse than the worse hz of the two arguments.
      The result is always exact unless an error is signaled.
      * test/src/timefns-tests.el (timefns-tests--decode-time):
      New function.
      (format-time-string-with-zone): Test (decode-time LOOK ZONE t)
      resolution as well as its numeric value.
      396ed88a
  7. 18 Aug, 2019 1 commit
    • Paul Eggert's avatar
      Improve bignum_integer static checking · 780509f2
      Paul Eggert authored
      * src/bignum.h (bignum_integer): Now returns pointer-to-const,
      to catch trivial mistakes where the caller might try to modify
      a Lisp bignum.  Lisp bignums are supposed to be immutable.
      All callers changed.
      780509f2
  8. 04 May, 2019 1 commit
  9. 01 Jan, 2019 1 commit
    • Paul Eggert's avatar
      Update more copyright years · a04bf151
      Paul Eggert authored
      Update some other copyright years automatically, by running:
      Run 'UPDATE_COPYRIGHT_YEAR=2019 \
      UPDATE_COPYRIGHT_USE_INTERVALS=1 \
      UPDATE_COPYRIGHT_MAX_LINE_LENGTH=79 admin/update-copyright'
      followed by 'admin/merge-gnulib'.
      a04bf151
  10. 07 Oct, 2018 1 commit
    • Paul Eggert's avatar
      Export converting mpz to [u]intmax · 84f39d33
      Paul Eggert authored
      This refactoring will help improve timestamp handling later
      (Bug#32902).
      * src/bignum.c (mpz_set_uintmax): Move to bignum.h,
      and make inline.
      (mpz_set_uintmax_slow): Now extern.
      (mpz_to_intmax, mpz_to_uintmax): New functions, with
      implementation taken from the old bignum_to_intmax
      and bignum_to_uintmax.
      (bignum_to_intmax, bignum_to_uintmax): Use them.
      84f39d33
  11. 22 Sep, 2018 1 commit
    • Paul Eggert's avatar
      Round bignums consistently with other integers · 0b36041d
      Paul Eggert authored
      * src/bignum.c (mpz_bufsize): New function.
      (bignum_bufsize): Use it.
      (mpz_get_d_rounded): New function.
      (bignum_to_double): Use it.
      * src/bignum.c (bignum_to_double):
      * src/data.c (bignum_arith_driver):
      When converting bignums to double, round instead of
      truncating, to be consistent with what happens with fixnums.
      * test/src/floatfns-tests.el (bignum-to-float): Test rounding.
      0b36041d
  12. 07 Sep, 2018 1 commit
    • Paul Eggert's avatar
      Shrink pseudovectors a bit · 2c8520e1
      Paul Eggert authored
      sizeof (struct Lisp_Marker) was 32 on x86, where 24 would do.
      Problem noted by Stefan Monnier in:
      https://lists.gnu.org/r/emacs-devel/2018-09/msg00165.html
      * src/bignum.h (struct Lisp_Bignum):
      * src/frame.h (struct frame):
      * src/lisp.h (struct Lisp_Vector, struct Lisp_Bool_Vector)
      (struct Lisp_Char_Table, struct Lisp_Hash_Table)
      (struct Lisp_Marker, struct Lisp_Overlay)
      (struct Lisp_Misc_Ptr, struct Lisp_User_Ptr)
      (struct Lisp_Finalizer, struct Lisp_Float)
      (struct Lisp_Module_Function):
      * src/process.h (struct Lisp_Process):
      * src/termhooks.h (struct terminal):
      * src/thread.h (struct thread_state, struct Lisp_Mutex)
      (struct Lisp_CondVar):
      * src/window.c (struct save_window_data):
      * src/window.h (struct window):
      * src/xterm.h (struct scroll_bar):
      * src/xwidget.h (struct xwidget, struct xwidget_view):
      Add GCALIGNED_STRUCT attribute.
      * src/lisp.h (GCALIGNED_UNION_MEMBER): Renamed from GCALIGNED_UNION.
      All uses changed.
      (GCALIGNED_STRUCT_MEMBER, GCALIGNED_STRUCT, GCALIGNED): New macros.
      All uses of open-coded GCALIGNED changed to use GCALIGNED.
      (union vectorlike_header): No longer GC-aligned.
      (PSEUDOVECSIZE): Yield 0 for pseudovectors without Lisp
      objects that place a member before where the first Lisp object
      member would be.
      2c8520e1
  13. 04 Sep, 2018 2 commits
    • Paul Eggert's avatar
      Fix bignum initialization · 1d84e652
      Paul Eggert authored
      Problem reported by Andy Moreton in:
      https://lists.gnu.org/r/emacs-devel/2018-09/msg00072.html
      and crystal-ball diagnosis by Eli Zaretskii in:
      https://lists.gnu.org/r/emacs-devel/2018-09/msg00075.html
      * src/alloc.c (xrealloc_for_gmp, xfree_for_gmp): Move to bignum.c.
      (init_alloc): Move bignum initialization to init_bignum.
      * src/bignum.c (init_bignum): Rename from init_bignum_once.
      All users changed.
      * src/emacs.c (main): Call init_bignum after init_alloc,
      instead of calling init_bignum_once after init_bignum.
      1d84e652
    • Paul Eggert's avatar
      Speed up (+ 2 2) by a factor of 10 · fe042e9d
      Paul Eggert authored
      Improve arithmetic performance by avoiding bignums until needed.
      Also, simplify bignum memory management, fixing some unlikely leaks.
      This patch improved the performance of (+ 2 2) by a factor of ten
      on a simple microbenchmark computing (+ x 2), byte-compiled,
      with x a local variable initialized to 2 via means the byte
      compiler could not predict: performance improved from 135 to 13 ns.
      The platform was Fedora 28 x86-64, AMD Phenom II X4 910e.
      Performance also improved 0.6% on ‘make compile-always’.
      * src/bignum.c (init_bignum_once): New function.
      * src/emacs.c (main): Use it.
      * src/bignum.c (mpz): New global var.
      (make_integer_mpz): Rename from make_integer.  All uses changed.
      * src/bignum.c (double_to_bignum, make_bignum_bits)
      (make_bignum, make_bigint, make_biguint, make_integer_mpz):
      * src/data.c (bignum_arith_driver, Frem, Flogcount, Fash)
      (expt_integer, Fadd1, Fsub1, Flognot):
      * src/floatfns.c (Fabs, rounding_driver, rounddiv_q):
      * src/fns.c (Fnthcdr):
      Use mpz rather than mpz_initting and mpz_clearing private
      temporaries.
      * src/bignum.h (bignum_integer): New function.
      * src/data.c (Frem, Fmod, Fash, expt_integer):
      * src/floatfns.c (rounding_driver):
      Use it to simplify code.
      * src/data.c (FIXNUMS_FIT_IN_LONG, free_mpz_value):
      Remove.  All uses removed.
      (floating_point_op): New function.
      (floatop_arith_driver): New function, with much of the guts
      of the old float_arith_driver.
      (float_arith_driver): Use it.
      (floatop_arith_driver, arith_driver):
      Simplify by assuming NARGS is at least 2.
      All callers changed.
      (float_arith_driver):
      New arg, containing the partly converted value of the next arg.
      Reorder args for consistency.  All uses changed.
      (bignum_arith_driver): New function.
      (arith_driver): Use it.  Do fixnum-only integer calculations
      in intmax_t instead of mpz_t, when they fit.
      Break out mpz_t calculations into bignum_arith_driver.
      (Fquo): Use floatop_arith_driver instead of float_arith_driver,
      since the op is known to be valid.
      (Flogcount, Fash): Simplify by coalescing bignum and fixnum code.
      (Fadd1, Fsub1): Simplify by using make_int.
      fe042e9d
  14. 28 Aug, 2018 1 commit
    • Paul Eggert's avatar
      Modularize bignums better · 9abaf5f3
      Paul Eggert authored
      * src/bignum.c, src/bignum.h: New files.  Only modules that
      need to know how bignums are implemented should include
      bignum.h.  Currently these are alloc.c, bignum.c (of course),
      data.c, emacs.c, emacs-module.c, floatfns.c, fns.c, print.c.
      * src/Makefile.in (base_obj): Add bignum.o.
      * src/alloc.c (make_bignum_str): Move to bignum.c.
      (make_number): Remove; replaced by bignum.c’s make_integer.
      All callers changed.
      * src/conf_post.h (ARG_NONNULL): New macro.
      * src/json.c (json_to_lisp): Use it.
      * src/data.c (Fnatnump):
      Move NATNUMP’s implementation here from lisp.h.
      * src/data.c (Fnumber_to_string):
      * src/editfns.c (styled_format):
      Move conversion of string to bignum to bignum_to_string, and
      call it here.
      * src/emacs-module.c (module_make_integer):
      * src/floatfns.c (Fabs):
      Simplify by using make_int.
      * src/emacs.c: Include bignum.h, to expand its inline fns.
      * src/floatfns.c (Ffloat): Simplify by using XFLOATINT.
      (rounding_driver): Simplify by using double_to_bignum.
      (rounddiv_q): Clarify use of temporaries.
      * src/lisp.h: Move decls that need to know bignum internals to
      bignum.h.  Do not include gmp.h or mini-gmp.h; that is now
      bignum.h’s job.
      (GMP_NUM_BITS, struct Lisp_Bignum, XBIGNUM, mpz_set_intmax):
      Move to bignum.h.
      (make_int): New function.
      (NATNUMP): Remove; all callers changed to use Fnatnump.
      (XFLOATINT): If arg is a bignum, use bignum_to_double, so that
      bignum internals are not exposed here.
      * src/print.c (print_vectorlike): Use SAFE_ALLOCA to avoid the
      need for a record_unwind_protect_ptr.
      9abaf5f3