summaryrefslogtreecommitdiffstats
path: root/mpi/mpi.c
Commit message (Collapse)AuthorAgeFilesLines
* Going back to unmodified 2-Clause BSD License.Kaz Kylheku2016-09-221-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | * LICENSE: Reverted to Two-Clause BSD license. The copyright of the Linenoise library are included, because it uses exactly the same license. A note is added about MPI being in the public domain. * LICENSE-CYG: Revised text to clarify the situation that Cygnal is only bundled with a particular Windows build of TXR. * METALICENSE: Revised text. All references to modifications to the BSD license are removed. Gives pointers to the MPI and linenoise license files. Notes that linenoise is under the Two-Clause BSD also. Makes a note about Cygnal and points to LICENSE-CYG. * inst.nsi: Remove the text which tells the user that use of the program requires agreement with the license; refer only to redistribution. The "Agree" buttons are renamed "Acknowledge". * mpi/make-logtab, mpi/mpi.c, mpi/mpi.h, mpi/mplogic.c, mpi/mplogic.h: Remove copyright notices and "all rights reserved", since the author had placed this into the public domain, as made explicit in the README file.
* Fix out-of-bounds memory access in bit.Kaz Kylheku2016-06-081-1/+1
| | | | | | | * mpi/mpi.c (mp_bit): If the digit index is beyond the available digits in the number, report MP_NO rather than accessing undefined digit material or beyond the array entirely.
* Fix leaks in use of MPI and within MPI.Kaz Kylheku2016-06-081-11/+0
| | | | | | | | | | | | | | | | * arith.c (logand, logior, logxor): Use make_ubignum to create an uninitialized bignum, because mp_and, mp_or, and mp_xor expect argument c to be uninitialized, and clobber it by initializing. (comp_trunc): Use make_ubignum for b argument, because mp_trunk_comp initializes it. (lognot, logtrunc): Use make_ubignum for b, because mp_trunc initializes it. * mpi/mpi.c (mp_and, mp_or, mp_xor, mp_comp, mp_trunc_comp, mp_trunc, mp_shift, mp_bit): Do not initialize the tmp that is passed as argument b to mp_2comp, since that function initializes it.
* Fix broken bignum to int_ptr_t conversion.Kaz Kylheku2016-04-281-3/+2
| | | | | | | | | | | | | This one affects all platforms. The extra sign check and negation cancels out the one done in mp_get_uintptr, causing a positive value for a negative input value. * mpi/mpi.c (mp_get_intptr): Just coerce the uint_ptr_t result to int_ptr_t. That has the right semantics under that the bits are preserved (under two's complement, in every compiler I've ever used). The unsigned value from mp_get_uintptr already looks like the image of a two's complement value.
* Fix broken bignum to uint_ptr_t conversion.Kaz Kylheku2016-04-281-1/+1
| | | | | | | | | This applies only to some platforms, none of which are current targets on which TXR is tested and released. * mpi/mpi.c (mp_get_uinptr): Do not clobber output accumulator in the loop body: the bits must be OR-ed into it.
* Replace all stray C style casts with macros.Kaz Kylheku2016-03-291-29/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * gc.c (gc_report_copies): C style casts found in this function. * linenoise.c (strip_qual, convert, coerce): Copy and paste the macros here. (record_undo, compare_completions, lino_add_completion, history_search, ab_append, sync_data_to_buf, refresh_singleline, screen_rows, refresh_multiline, find_nearest_paren, paren_jump, yank_sel, edit_move_matching_paren, edit, lino_make, lino_copy, lino_hist_add, lino_hist_set_max_len): C style casts replaced. * mpi/mpi-types.h (MP_DIGIT_BIT, MP_DIGIT_MAX, MP_WORD_BIT, MP_WORD_MAX, RADIX): C style casts replaced. * mpi/mpi.c (convert, coerce): Copy and paste the macros here. (mp_init_size, mp_init_copy, mp_copy, mp_set_int, mp_div_d, mp_bit, mp_to_double, mp_to_signed_bin, mp_to_unsigned_bin, mp_to_unsigned_buf, mp_toradix_case, mp_grow, s_mp_set_bit, s_mp_mod_2d, s_mp_mul_2d, s_mp_div_2d, s_mp_mul_d, s_mp_mul, s_mp_sqr, s_mp_div, s_mp_2expt, s_mp_todigit): C style casts replaced. * mpi/mplogic (convert): Macro copy and pasted here. (mpl_num_set, mpl_num_clear): C style casts replaced. * parser.c (provide_completions): Likewise. * signal.c (small_sigfillset): Likewise. * stream.c (stdio_truncate, test_set_indent_mode, set_indent_mode): Likewise.
* Functions for converting between buffers and integers.Kaz Kylheku2016-02-261-0/+26
| | | | | | | | | | | | | | | | | These functions convert between positive integers, and fixed-size memory buffers representing pure binary numbers in big endian byte order. This functionality will be used in some upcoming networking code. * arith.c (num_from_buffer, num_to_buffer): New functions. * arith.h (num_from_buffer, num_to_buffer): Declared. * mpi/mpi.c (mp_to_unsigned_buf): New function. * mpi/mpi.h (mp_to_unsigned_buf): Declared.
* Reduce header pollution caused by mpi.h.Kaz Kylheku2016-01-221-1/+8
| | | | | | | | | | | | | * eval.c: include <assert.h> that was previously coming via "mpi.h". * mpi/mpi.c: Includes of <stdio.h>, <ctype.h> and <assert.h> moved here. * mpi/mpi.h: Remove include of <stdio.h>, <ctype.h> and <assert.h>. Keeping <limits.h> for now; needed for CHAR_BIT. * mpi/mplogic.c: Needs <assert.h>
* New random-state-get-vec function.Kaz Kylheku2016-01-181-11/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | * arith.c (UINT_PTR_MAX_MP): New static variable. (biggnum_from_uintptr): New function. (in_uint_ptr_range): New static function. (c_uint_ptr_num): New function. (arith_init): Initialize UINT_PTR_MAX_MP. * arith.h (bignum_from_uintptr, c_uint_ptr_num): Declared. * eval.c (eval_init): Register random-state-get-vec. * mpi/mpi.c (mp_set_uintptr, mp_get_uintptr): New functions. (mp_set_intptr, mp_get_intptr): Expressed in terms of mp_set_uintptr and mp_get_uintptr. * mpi/mpi.h (mp_set_uintptr, mp_get_uintptr): Declared. * rand.c (make_random_state): Handle vector seed. (random_state_get_vec): New function. * rand.h (random_state_get_vec): Declared. * txr.1: Documented new feature in make-random-state and new random-state-get-vec function.
* random: wrong mask width for power-of-two moduli.Kaz Kylheku2016-01-181-0/+5
| | | | | | | | | | | | | | | | | | | | | | | This mistake causes wasteful behavior for power-of-two moduli in the random function, in both the bignum and fixnum cases. For instance, the modulus 16 is taken to be 17 bits wide. But we really want the width 16: the number of bits needed for values in the range [0, 16). The result isn't wrong, but the loop generates 17-bit random numbers, and then throws away those which equal or exceed the modulus, which is wasteful. * mpi/mpi.c (mp_is_pow_two): New function. * mpi/mpi.h (mp_is_pow_two): Declared. * rand.c (random): In bignum case, after counting bits in the modulus, subtract 1 if the modulus is a power of two. In the fixnum case, subtract 1 from the modulus and then count the bits in the reduced value. * tests/013/maze.expected: regenerate due to different prng behavior.
* eliminate-locale-dependencies patchKaz Kylheku2015-04-221-9/+14
| | | | | | | Eliminating dependencies on locale-dependent C functions. * mpi/mpi.c (s_mp_tovalue, s_mp_todigit): Avoid tolower, toupper, islower and isupper.
* add-bitops patchKaz Kylheku2015-04-221-0/+428
| | | | | | | | | | | Adding bit operations to MPI. * mpi/mpi.c (MAX, MIN): New macros. (mp_2comp, mp_and, mp_or, mp_xor, mp_comp, mp_trunc, mp_shift, mp_bit): New functions. * mpi/mpi.h (mp_2comp, mp_and, mp_or, mp_xor, mp_comp, mp_trunc, mp_shift, mp_bit): Declared.
* fix-ctype-warnings patchKaz Kylheku2015-04-221-3/+3
| | | | | * mpi/mpi.c (s_mp_tovalue): Argument changes from char to int, fixing some compiler warnings.
* mpi-to-double patchKaz Kylheku2015-04-221-0/+24
| | | | | | * mpi/mpi.c (mp_to_double): New function. * mpi/mpi.h (mp_to_double): Declared.
* faster-square-root patchKaz Kylheku2015-04-221-74/+70
| | | | | * mpi/mpi.c (s_highest_bit_mp, s_mp_set_bit): New functions. (mp_sqrt): Rewrite with more efficient algorithm.
* bit-search-optimizations patchKaz Kylheku2015-04-221-30/+232
| | | | | * mpi/mpi.c (s_highest_bit): New static function. (s_mp_norm, s_mp_ispow2): Use s_highest_bit instead of looping over bits.
* fix-bad-shifts patchKaz Kylheku2015-04-221-5/+5
| | | | | | * mpi/mpi.c (mp_div_d, s_mp_mod_2d, s_mp_mul_2d, s_mp_div_2d, s_mp_2expt): Fixing incorrect digit-wide left shifts whre the operand is not widened to the mp_digit type.
* mpi-set-double-intptr patchKaz Kylheku2015-04-221-0/+30
| | | | | | * mpi/mpi.c (mp_set_double_intptr): New function. * mpi/mpi.h (mp_set_double_intptr): Declared.
* mpi-set-mpi-word patchKaz Kylheku2015-04-221-0/+9
| | | | | | * mpi/mpi.c (mp_set_word): New function. * mpi/mpi.h (mp_set_word): Declared.
* fix-mult-bug patchKaz Kylheku2015-04-221-6/+6
| | | | | | | | Fixing bugs in MPI whereby two digits are multiplied together, but neither operand is cast to the double digit type, so that the result is truncated. * mpi/mpi.c (s_mp_mul_d, s_mp_mul, s_mp_sqr): Add casts to achieve multiplication of the proper width.
* add-mpi-toradix-with-case patchKaz Kylheku2015-04-221-4/+9
| | | | | | | | * mpi/mpi.c (mp_toradix_case): New function based on mp_toradix. Takes an argument whether to use lower case digits. (mp_toradix): Reduced to wrapper for mp_toradix_case. * mpi/mpi.h (mp_toradix_case): Declared.
* add-mp-hash patchKaz Kylheku2015-04-221-0/+28
| | | | | | * mpi/mpi.c (mp_hash): New function. * mpi/mpi.c (mp_hash): Declared.
* export-mp-eq patchKaz Kylheku2015-04-221-8/+0
| | | | | | * mpi/mpi.c (MP_LT, MP_EQ, MP_GT): Preprocessor symbols removed. * mpi/mpi.h (MP_LT, MP_EQ, MP_GT): Preprocessor symbols added.
* add-mp-set-intptr patchKaz Kylheku2015-04-221-0/+53
| | | | | | * mpi/mpi.c (mp_set_intptr, mp_get_intptr): New functions. * mpi/mpi.h (mp_set_intptr, mp_get_intptr): Declared.
* use-txr-allocator patchKaz Kylheku2015-04-221-6/+9
| | | | | | | | | * mpi/mpi.c (mem_t): TXR's mem_t typedef repeated here. (chk_calloc): New external declaration, to avoid including our entire lib.h header. (s_mp_alloc): Macro retargetted to use chk_calloc. (mp_init_size, mp_init_copy, mp_copy, s_mp_grow, s_mp_copy): Return value casts added.
* fix-warnings patchKaz Kylheku2015-04-221-5/+5
| | | | | | | * mpi/mpi.c (mp_to_unsigned_bin, s_mp_mod_2d): Fix signed/unsigned warning. (mp_toradix): Fix shadowing local variable name warning. * mpi/mplogic.c (mpl_num_set, mpl_num_clear): Fix signed/unsigned warning.
* config-types patchKaz Kylheku2015-04-221-0/+1
| | | | | | | | * mpi/mpi-types.h: Rewritten by hand to use make use of information produced by TXR's configure script into config/config.h. * mpi/mpi.c, mpi/mplogic.c: Include the config.h header, now needed by mpi-types.h.
* Bringing MPI library out of tarball into GIT.Kaz Kylheku2015-04-221-0/+4001
Importing 1.8.6 upstream baseline, minus unwanted stuff.