summaryrefslogtreecommitdiff
path: root/src/bignum.h
Commit message (Collapse)AuthorAge
* Update copyright year to 2021Paul Eggert2021-01-01
| | | | Run "TZ=UTC0 admin/update-copyright".
* Use Gnulib libgmp modulePaul Eggert2020-07-09
| | | | | | | | | | | | | | | | | | | | 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.
* Pacify buggy old GCC with a castPaul Eggert2020-05-06
| | | | | | * src/bignum.h (bignum_integer): Pacify GCC 4.8.5. Problem reported by Andreas Schwab in: https://lists.gnu.org/r/emacs-devel/2020-05/msg00781.html
* Use ATTRIBUTE_CONST for some bignum functionsPaul Eggert2020-03-27
| | | | | | | * src/bignum.h (mpz_get_d_rounded): * src/lisp.h (bignum_to_double, bignum_to_intmax) (bignum_to_uintmax, bignum_bufsize): Declare as ATTRIBUTE_CONST.
* Update copyright year to 2020Paul Eggert2020-01-01
| | | | Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
* Refactor bignum multiplication, exponentiationPaul Eggert2019-11-13
| | | | | | | 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.
* Be more careful about pointers to bignum valsPaul Eggert2019-08-21
| | | | | | | | | | | | | | | 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.
* Avoid some excess precision in time arithmeticPaul Eggert2019-08-20
| | | | | | | | | | | | | | | | | | | * 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.
* Improve bignum_integer static checkingPaul Eggert2019-08-18
| | | | | | | * 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.
* Refactoring: Factor out a function to set an mpz_t from a Lisp int.Philipp Stephani2019-05-04
| | | | | | * src/bignum.h (mpz_set_integer): New function. * src/emacs-module.c (module_make_big_integer): Use it.
* Update more copyright yearsPaul Eggert2018-12-31
| | | | | | | | 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'.
* Export converting mpz to [u]intmaxPaul Eggert2018-10-06
| | | | | | | | | | | | 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.
* Round bignums consistently with other integersPaul Eggert2018-09-22
| | | | | | | | | | | | * 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.
* Shrink pseudovectors a bitPaul Eggert2018-09-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix bignum initializationPaul Eggert2018-09-04
| | | | | | | | | | | | | 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.
* Speed up (+ 2 2) by a factor of 10Paul Eggert2018-09-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Modularize bignums betterPaul Eggert2018-08-27
* 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.