]> git.ipfire.org Git - thirdparty/coreutils.git/log
thirdparty/coreutils.git
18 hours agodoc: mention copy_file_range data corruption avoidance master
Pádraig Brady [Sat, 2 Aug 2025 08:52:17 +0000 (09:52 +0100)] 
doc: mention copy_file_range data corruption avoidance

* NEWS: Mention this important data corruption issue.

27 hours agobuild: update gnulib submodule to latest
Paul Eggert [Fri, 1 Aug 2025 23:55:31 +0000 (16:55 -0700)] 
build: update gnulib submodule to latest

39 hours agomaint: date: refactor to be entirely bottom-up
Bruno Haible [Thu, 31 Jul 2025 16:45:45 +0000 (18:45 +0200)] 
maint: date: refactor to be entirely bottom-up

* src/date.c (show_date_helper): Move function. Remove forward
declaration.

46 hours agodate: fix calendar-related test failures on macOS and OpenBSD
Bruno Haible [Thu, 31 Jul 2025 16:42:02 +0000 (18:42 +0200)] 
date: fix calendar-related test failures on macOS and OpenBSD

* bootstrap.conf (gnulib_modules): Add xsetenv.
* src/date.c: Include xsetenv.h.
(set_LC_TIME): New function.
(show_date_helper): Call set_LC_TIME instead of setlocale.
* po/POTFILES.in: Add lib/xsetenv.c.
Fixes https://bugs.gnu.org/79118

46 hours agobuild: update gnulib submodule to latest
Collin Funk [Fri, 1 Aug 2025 04:43:55 +0000 (21:43 -0700)] 
build: update gnulib submodule to latest

2 days agobuild: fix previous commit
Collin Funk [Fri, 1 Aug 2025 00:57:59 +0000 (17:57 -0700)] 
build: fix previous commit

* src/local.mk (src/speedlist.h): Pass correct arguments $(COMPILE). Use
tabs consistently.

3 days agobuild: don't use '$<' in non-suffix rules
Collin Funk [Wed, 30 Jul 2025 23:33:24 +0000 (16:33 -0700)] 
build: don't use '$<' in non-suffix rules

* src/local.mk (src/speedlist.h): Use the file name instead of '$<'
which is not supported by OpenBSD make.

4 days agodu: improve diagnostics for --time-style
Pádraig Brady [Mon, 28 Jul 2025 22:05:49 +0000 (23:05 +0100)] 
du: improve diagnostics for --time-style

* src/system.h (x_timestyle_args): A new function refactored from ...
* src/ls.c (decode_switches): ... here.
* src/du.c: Use refactored x_timestyle_args() to output a custom error.
Addresses https://bugs.gnu.org/79113

4 days agodoc: use consistent references to standard files
Pádraig Brady [Mon, 28 Jul 2025 10:05:25 +0000 (11:05 +0100)] 
doc: use consistent references to standard files

* cfg.mk (sc_standard_outputs): A new syntax check to
enforce standard references.
* doc/coreutils.texi: s/stderr/standard error/ etc.
* src/date.c: Likewise.
* src/dd.c: Likewise.
* src/env.c: Likewise.
* src/sort.c: Likewise.
* src/split.c: Likewise.
* src/stty.c: Likewise.
* src/timeout.c: Likewise.
* src/who.c: Likewise.

6 days agodoc: update git version documented in HACKING
Collin Funk [Sun, 27 Jul 2025 18:53:42 +0000 (11:53 -0700)] 
doc: update git version documented in HACKING

* HACKING: Mention that git version 1.6.4 or later is required since
'./bootstrap' will fail otherwise.

6 days agodoc: mention 2025 speedup on large composites
Paul Eggert [Sun, 27 Jul 2025 14:30:29 +0000 (07:30 -0700)] 
doc: mention 2025 speedup on large composites

7 days agomaint: avoid :> pattern in tests
Pádraig Brady [Sat, 26 Jul 2025 19:06:42 +0000 (20:06 +0100)] 
maint: avoid :> pattern in tests

This was seen to trigger the EXIT trap on cygwin

* cfg.mk (sc_prohibit_colon_redirection): Disallow all
cases of :> in tests/
* tests/cksum/md5sum-bsd.sh: Adjust to avoid more
stringent syntax check.

7 days agotests: avoid a false failure on Cygwin
Collin Funk [Sat, 26 Jul 2025 18:29:02 +0000 (11:29 -0700)] 
tests: avoid a false failure on Cygwin

* tests/cksum/md5sum-bsd.sh: Use 'echo' instead of ':' to redirect to
the file. Otherwise 'Exit $fail' is not called on Cygwin.

7 days agomaint: avoid syntax-check failure from previous commit
Collin Funk [Sat, 26 Jul 2025 07:17:16 +0000 (00:17 -0700)] 
maint: avoid syntax-check failure from previous commit

* src/test.c (binary_operator): Place string argument on a separate line
to avoid sc_error_quotes syntax-check failure.

8 days agotest: simplify for clarity
Paul Eggert [Fri, 25 Jul 2025 18:56:00 +0000 (11:56 -0700)] 
test: simplify for clarity

This should help avoid further audit confusion,
such as was just fixed by removing a FIXME.
* src/test.c (enum binop): New type.
(get_mtime): Return a struct timespec instead of returning
a bool and storing a struct timespec.  All callers changed.
(binop): Return an int recording either success (an enum binop)
or failure (-1).  All callers changed.
(binary_operator): Accept an enum binop, so that we need
not recompute the op type.  All callers changed.  Simplify.

8 days agotest: removed dead code for unrecognised binary operators
Harry Fellowes [Fri, 25 Jul 2025 13:26:38 +0000 (14:26 +0100)] 
test: removed dead code for unrecognised binary operators

the fallback error in binary_operator() was unreachable, since invalid
binary operators are rejected in three_arguments() via binop() which
returns false and prevents entry into binary_operator().

this dead code was unreachable and safe to remove

ref: line 636 where "binary operator expected" is generated.

Signed-off-by: Harry Fellowes <harryfellowes1@gmail.com>
Copyright-paperwork-exempt: Yes

10 days agotests: date: add tests for the Ethiopian calendar
Collin Funk [Wed, 23 Jul 2025 03:30:49 +0000 (20:30 -0700)] 
tests: date: add tests for the Ethiopian calendar

* tests/date/date-ethiopia.sh: New file.
* tests/local.mk (all_tests): Add the test.

10 days agotests: date: add tests for the Solar Hijri calendar
Collin Funk [Wed, 23 Jul 2025 03:14:35 +0000 (20:14 -0700)] 
tests: date: add tests for the Solar Hijri calendar

* tests/date/date-iran.sh: New file.
* tests/local.mk (all_tests): Add the test.

11 days agoinstall: with -d, use more accurate diagnostics
Pádraig Brady [Tue, 22 Jul 2025 19:34:50 +0000 (20:34 +0100)] 
install: with -d, use more accurate diagnostics

* gnulib: Update to latest to get the fix to
propagate the appropriate error message.
* tests/install/basic-1.sh: Add a test case.
* NEWS: Mention the bug fix.
Addresses https://bugs.gnu.org/79072

11 days agotests: date: add tests for the Thai solar calendar
Collin Funk [Fri, 18 Jul 2025 02:42:30 +0000 (19:42 -0700)] 
tests: date: add tests for the Thai solar calendar

* tests/date/date-thailand.sh: New file.
* tests/local.mk (all_tests): Add the test.

12 days agodoc: NEWS: mention that 'date' now supports non-Gregorian calendars
Collin Funk [Mon, 21 Jul 2025 21:47:30 +0000 (14:47 -0700)] 
doc: NEWS: mention that 'date' now supports non-Gregorian calendars

Suggested by Bruno Haible in:
<https://lists.gnu.org/r/bug-gnulib/2025-07/msg00091.html>.

* NEWS: Mention the improvement.

12 days agobuild: update gnulib submodule to latest
Collin Funk [Mon, 21 Jul 2025 21:43:59 +0000 (14:43 -0700)] 
build: update gnulib submodule to latest

* bootstrap: Update using './bootstrap --bootstrap-sync'.

12 days agodate: update documentation regarding non-Gregorian calendars
Bruno Haible [Thu, 17 Jul 2025 14:30:57 +0000 (16:30 +0200)] 
date: update documentation regarding non-Gregorian calendars

* doc/coreutils.texi (Calendars): New section.

12 days agodate: force a Gregorian calendar for options --iso-8601 and --rfc-3339
Bruno Haible [Thu, 17 Jul 2025 14:29:05 +0000 (16:29 +0200)] 
date: force a Gregorian calendar for options --iso-8601 and --rfc-3339

* src/date.c (show_date_helper): Add a use_c_locale parameter.
(batch_convert): Add a format_in_c_locale parameter.
(main): Set format_in_c_locale to true if any of the options --rfc-3339,
--iso-8601, -R is seen.

3 weeks agotests: sort: add a test for equivalent floats
Pádraig Brady [Sat, 12 Jul 2025 18:58:06 +0000 (19:58 +0100)] 
tests: sort: add a test for equivalent floats

* tests/sort/sort-float.sh: Ensure equivalent floats
are treated as such.

3 weeks agotests: fix fraction comparison in sort-float
Paul Eggert [Fri, 11 Jul 2025 21:43:32 +0000 (14:43 -0700)] 
tests: fix fraction comparison in sort-float

Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985#13>.
* tests/sort/sort-float.sh: At top level, use C locale at first.
(dbl_minima_order): Assume C locale.
Use string comparison for the fractional parts.

2025-07-10  Paul Eggert  <eggert@cs.ucla.edu>

tests: fix integer overflow in sort-float
Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985>.
* tests/sort/sort-float.sh (dbl_minima_order):
Use expr instead of test, to avoid problems with integers
too large for the shell.

3 weeks agotests: fix integer overflow in sort-float
Paul Eggert [Thu, 10 Jul 2025 17:17:29 +0000 (10:17 -0700)] 
tests: fix integer overflow in sort-float

Problem reported by Cosima Neidahl <https://bugs.gnu.org/78985>.
* tests/sort/sort-float.sh (dbl_minima_order):
Use expr instead of test to compare fractions,
to avoid problems with integers too large for the shell.

3 weeks agofactor: remove SINGLE_WORKS
Paul Eggert [Thu, 10 Jul 2025 05:26:39 +0000 (22:26 -0700)] 
factor: remove SINGLE_WORKS

* src/factor.c (SINGLE_WORKS): Remove, and remove its use,
as the buggy code that it is referring to has been removed.

3 weeks agofactor: use 64-bit internal counters
Paul Eggert [Thu, 10 Jul 2025 04:59:50 +0000 (21:59 -0700)] 
factor: use 64-bit internal counters

* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2, mp_factor_using_pollard_rho):
Use int_fast64_t for internal counters rather than int, as int
could overflow on some somewhat-practical examples.  Problem
discovered on a hypothetical platform where W_TYPE_SIZE is neither
32 nor 64, when factoring 0x7ffffffffffffeab7fffffffffff7369 ==
170141183460469225450570946617781744489, causing k to overflow in
mp_factor_using_pollard_rho.  Presumably a similar problem exists
in the previous stable coreutils 9.7, too, on 32-bit platforms
with somewhat-larger test cases, though I haven’t take the
somewhat-extensive CPU time to discover it.

3 weeks agofactor: fix mp_factor_using_pollard_rho aliasing
Paul Eggert [Thu, 10 Jul 2025 04:22:12 +0000 (21:22 -0700)] 
factor: fix mp_factor_using_pollard_rho aliasing

* src/factor.c (mp_factor_using_pollard_rho):
Fix recently-introduced aliasing bug by computing q
before g gets updated in place.  Problem discovered
on a hypothetical platform where W_TYPE_SIZE
is neither 32 nor 64.

3 weeks agomaint: fix apostrophe in old NEWS
Paul Eggert [Wed, 9 Jul 2025 22:20:17 +0000 (15:20 -0700)] 
maint: fix apostrophe in old NEWS

3 weeks agofactor: speed up converting strings to uuint
Paul Eggert [Wed, 9 Jul 2025 17:36:04 +0000 (10:36 -0700)] 
factor: speed up converting strings to uuint

* src/factor.c: Do not include c-ctype.h.
(strtouuint): Don’t bother generating a number on
error; just return a strtol_error value other than LONGINT_OK.
Speed up overflow checking.

3 weeks agofactor: simplify primes table
Paul Eggert [Wed, 9 Jul 2025 16:48:21 +0000 (09:48 -0700)] 
factor: simplify primes table

* src/factor.c (primes_ptab): New table of primes, replacing
primes_diff and primes_diff8.  All uses changed.  This is simpler
and should improve performance slightly.  Although this limits the
table’s primes to 2**15 instead of to 668221, the limit can easily
grow to 2**32 by changing the type of ‘prime’, without hurting
performance significantly compared to the primes_diff and
primes_diff8 approach.
* src/make-prime-list.c (output_primes):
For each prime p, output p instead of two differences.

3 weeks agofactor: prefer false for boolean 0
Paul Eggert [Wed, 9 Jul 2025 04:23:20 +0000 (21:23 -0700)] 
factor: prefer false for boolean 0

* src/factor.c: Prefer false to 0 for booleans.

3 weeks agomaint: port speedgen to FreeBSD 15
Paul Eggert [Mon, 7 Jul 2025 07:26:40 +0000 (00:26 -0700)] 
maint: port speedgen to FreeBSD 15

* src/speedgen: Avoid ‘trap 'command' ERR’, as ERR
does not conform to POSIX and does not work in
FreeBSD 15 sh.

3 weeks agofactor: speed up Pollard-rho loop counters
Paul Eggert [Mon, 7 Jul 2025 03:18:10 +0000 (20:18 -0700)] 
factor: speed up Pollard-rho loop counters

* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2, mp_factor_using_pollard_rho):
Use int, not unsigned long int, for counters that won’t go above
2**31 on practical platforms.  This yields a significant speedup
on GCC 15 x86-64, and using signed values allows for automatic
checks for overflow when using gcc -fsanitize=undefined.

3 weeks agofactor: avoid an mpz init+clear
Paul Eggert [Sun, 6 Jul 2025 20:59:56 +0000 (13:59 -0700)] 
factor: avoid an mpz init+clear

* src/factor.c (mp_factor_insert_ui): Rename fom
mp_factor_insert_ui, and change arg type from unsigned long int to
mp_limb_t.  All uses changed.  This avoids creating and freeing a
small mpz_t.
(mp_factor_using_division): Add a static assert requiring that
that mp_limb_t be wide enough, which it should be (and is in
standard GMP).

3 weeks agofactor: Pollard-rho a is now mp_limb_t
Paul Eggert [Sun, 6 Jul 2025 16:34:00 +0000 (09:34 -0700)] 
factor: Pollard-rho a is now mp_limb_t

* src/factor.c (factor_using_pollard_rho)
(factor_using_pollard_rho2): Use mp_limb_t, not unsigned long int,
for a parameter.  This avoids some casts, and avoids a theoretical
bug where converting to mp_limb_t loses info.

3 weeks agofactor: redo ge2 in terms of lt2
Paul Eggert [Sun, 6 Jul 2025 05:12:22 +0000 (22:12 -0700)] 
factor: redo ge2 in terms of lt2

lt2 a bit more natural, given the current implementation.
* src/factor.c (lt2): New function.
(ge2): Rewrite in terms of lt2.
(gt2): Remove.  All callers changed to use lt2.

3 weeks agofactor: speed up umul_ppmm when !USE_LONGLONG_H
Paul Eggert [Sat, 5 Jul 2025 18:04:54 +0000 (11:04 -0700)] 
factor: speed up umul_ppmm when !USE_LONGLONG_H

* src/factor.c (umul_ppmm): When !USE_LONGLONG_H so we need to
define this, speed things up if there is an unsigned type uuroom_t
wide enough to hold two words.  Do not make a similar change for
udiv_qrnnd, as it is not performance critical and anyway on GCC 15
x86-64 that would mean a subroutine call.

3 weeks agofactor: streamline gcd2_odd
Paul Eggert [Sat, 5 Jul 2025 15:45:17 +0000 (08:45 -0700)] 
factor: streamline gcd2_odd

* src/factor.c (gcd2_odd): Omit a gt2 and adjusts other
tests accordingly.  Omit duplicate code that makes A odd.

3 weeks agofactor: faster gcd_odd since 2nd is odd
Paul Eggert [Sat, 5 Jul 2025 14:07:25 +0000 (07:07 -0700)] 
factor: faster gcd_odd since 2nd is odd

* src/factor.c (gcd_odd, gcd2_odd): Speed up, given that the
second argument is always odd.
(gcd_odd): Avoid recomputing a temporary.
(gcd2_odd): Test for zero only if a multiple of B.
This saves an ‘assume’.

3 weeks agodoc: update ‘factor’ benchmarks
Paul Eggert [Thu, 3 Jul 2025 16:24:27 +0000 (09:24 -0700)] 
doc: update ‘factor’ benchmarks

3 weeks agofactor: prefer exact division
Paul Eggert [Fri, 4 Jul 2025 06:11:26 +0000 (23:11 -0700)] 
factor: prefer exact division

* src/factor.c (mp_factor_using_division, mp_factor_using_pollard_rho):
Use exact division when it suffices, as it’s typically faster.

3 weeks agofactor: tune submod2
Paul Eggert [Wed, 2 Jul 2025 21:46:00 +0000 (14:46 -0700)] 
factor: tune submod2

* src/factor.c (submod2): Use ckd_sub to subtract by hand rather
than using sub_ddmmss plus a compare.  This speeds things up a
bit, on x86-64 with GCC 15 anyway.

3 weeks agofactor: DELIM and DIVBLOCK no longer macros
Paul Eggert [Wed, 2 Jul 2025 20:09:55 +0000 (13:09 -0700)] 
factor: DELIM and DIVBLOCK no longer macros

* src/factor.c (DELIM): Now a constant, not a macro.
(divblock): Now a static inline function, not a macro DIVBLOCK.
All uses changed.

3 weeks agofactor: simplify by assuming !PROVE_PRIMALITY
Paul Eggert [Wed, 2 Jul 2025 14:48:54 +0000 (07:48 -0700)] 
factor: simplify by assuming !PROVE_PRIMALITY

* src/factor.c (PROVE_PRIMALITY, mp_millerrabin): Remove.
All uses removed, and surrounding code simplified.

3 weeks agofactor: simplify by assuming USE_BAILLIE_PSW
Paul Eggert [Wed, 2 Jul 2025 02:56:53 +0000 (19:56 -0700)] 
factor: simplify by assuming USE_BAILLIE_PSW

* src/factor.c (make_uuint2, powm, powm2, millerrabin)
(millerrabin2, USE_BAILLIE_PSW): Remove; no longer used.
(prime_p, prime2_p): Simplify by assuming USE_BAILLIE_PSW.

3 weeks agofactor: prime comments
Paul Eggert [Tue, 1 Jul 2025 19:59:17 +0000 (12:59 -0700)] 
factor: prime comments

* src/factor.c: Add comments re prime functions.

3 weeks agofactor: no ferror+fclose
Paul Eggert [Tue, 1 Jul 2025 18:53:33 +0000 (11:53 -0700)] 
factor: no ferror+fclose

* src/make-prime-list.c (main): Avoid parallel calls
to ferror and fclose.

3 weeks agofactor: define SQUARE_OF_FIRST_OMITTED_PRIME
Paul Eggert [Tue, 1 Jul 2025 18:48:44 +0000 (11:48 -0700)] 
factor: define SQUARE_OF_FIRST_OMITTED_PRIME

* src/make-prime-list.c (output_primes): Output
SQUARE_OF_FIRST_OMITTED_PRIME, not FIRST_OMITTED_PRIME.  All uses
changed.  This way, the uses don’t need to worry about casts to
avoid overflow.

3 weeks agofactor: simplify add_ssaaaa default
Paul Eggert [Tue, 1 Jul 2025 10:34:21 +0000 (03:34 -0700)] 
factor: simplify add_ssaaaa default

* src/factor.c (add_ssaaaa): Simplify default implementation.

3 weeks agofactor: speed up ge2, gt2
Paul Eggert [Tue, 1 Jul 2025 10:33:27 +0000 (03:33 -0700)] 
factor: speed up ge2, gt2

* src/factor.c (ge2, gt2): Now branchless static functions.

3 weeks agofactor: improve millerrabin2 API
Paul Eggert [Tue, 1 Jul 2025 02:05:55 +0000 (19:05 -0700)] 
factor: improve millerrabin2 API

* src/factor.c (make_uuint2): New function.
(powm2, millerrabin2): Pass two-word args as uuints,
not as mp_limb_t const [2] pointers.  All uses changed.
(prime2_p): Rework to use the new API, fixing a FIXME.

3 weeks agofactor: put FACTORS first
Paul Eggert [Mon, 30 Jun 2025 14:34:53 +0000 (07:34 -0700)] 
factor: put FACTORS first

* src/factor.c (factor_using_division, mp_finish_up_in_single)
(mp_finish_in_single, factor_using_pollard_rho)
(factor_using_pollard_rho2, factor_up, factor):
Put FACTORS arg first, for consistency.
This is just a refactoring and should not affect speed.

3 weeks agofactor: use 1-word code only when tested
Paul Eggert [Mon, 23 Jun 2025 17:26:28 +0000 (10:26 -0700)] 
factor: use 1-word code only when tested

* src/factor.c (print_factors): Use single-precision code only
when word size is 32 or 64, as it isn't tested for other sizes and
is known to not work when it the size is 128.  This change does
not affect any known practical platforms.

3 weeks agofactor: decrement Miller-Rabin tests from 25 to 24
Paul Eggert [Mon, 23 Jun 2025 05:31:54 +0000 (22:31 -0700)] 
factor: decrement Miller-Rabin tests from 25 to 24

This avoids some seemingly-unnecessary code in mpz_probab_prime_p.
* src/factor.c (MR_REPS): Shrink from 25 to 24, and add commentary.

3 weeks agofactor: don’t prove primality
Paul Eggert [Sat, 21 Jun 2025 18:41:11 +0000 (11:41 -0700)] 
factor: don’t prove primality

Suggested for consideration by Torbjörn Granlund in:
https://lists.gnu.org/r/coreutils/2025-01/msg00000.html
* src/factor.c (PROVE_PRIMALITY): Now defaults to false.
(mp_prime_p): Help the compiler by telling it mpz_prob_prime_p
returns nonnegative.
* tests/factor/create-test.sh (bigprime): Test 2^400 - 593,
since that’s now practical.
* tests/local.mk (factor_tests): Add new test.

3 weeks agofactor: add comments to factor.c
Paul Eggert [Sat, 21 Jun 2025 00:16:06 +0000 (17:16 -0700)] 
factor: add comments to factor.c

3 weeks agofactor: always use Baillie-PSW
Paul Eggert [Sun, 15 Jun 2025 06:10:25 +0000 (23:10 -0700)] 
factor: always use Baillie-PSW

* src/factor.c (USE_BAILLIE_PSW): New constant.
(prime_p, prime2_p): Use it, i.e., always use Baillie-PSW.
Do so by using mp_prime_p.  Do not tell GCC these functions
are pure; the pure mark was present only to pacify GCC
and is no longer needed now that thes functions call mp_prime_p.

3 weeks agobuild: update gnulib submodule to latest
Paul Eggert [Sun, 15 Jun 2025 05:54:44 +0000 (22:54 -0700)] 
build: update gnulib submodule to latest

3 weeks agofactor: use mpz_probab_prime_p
Paul Eggert [Thu, 12 Jun 2025 20:51:46 +0000 (13:51 -0700)] 
factor: use mpz_probab_prime_p

Inspired by a proposal by Torbjörn Granlund in:
https://lists.gnu.org/r/coreutils/2025-01/msg00000.html
* src/factor.c (mp_prime_p): Use mpz_probab_prime_p rather than doing
it by hand, as mpz_probab_prime_p uses Baillie-PSW which is a win.
This removes the need for the ret2 label and goto.

3 weeks agofactor: don’t give up before last prime in table
Paul Eggert [Thu, 12 Jun 2025 20:45:57 +0000 (13:45 -0700)] 
factor: don’t give up before last prime in table

* src/factor.c (prime_p, prime2_p, mp_prime_p): Do not skip the
flag_prove_primality test for the last prime in the table, i.e.,
when r == PRIMES_PTAB_ENTRIES - 1.
(mp_prime_p): There is no longer a need for the ret1 label or goto.

3 weeks agofactor: move prime_p local in
Paul Eggert [Thu, 12 Jun 2025 20:38:59 +0000 (13:38 -0700)] 
factor: move prime_p local in

* src/factor.c (mp_prime_p): Refactor by moving local further in.

3 weeks agofactor: port back to mini-gmp
Paul Eggert [Fri, 4 Jul 2025 18:52:36 +0000 (11:52 -0700)] 
factor: port back to mini-gmp

mini-gmp lacs mpn_tdiv_qr, so supply an emulation of it
when using mini-gmp.
* src/factor.c (copy_mpn_from_mpz, mpn_tdiv_qr) [!mpn_tdiv_qr]:
New functions.

3 weeks agofactor: speed up multiprecision Pollard’s rho
Paul Eggert [Wed, 11 Jun 2025 00:40:34 +0000 (17:40 -0700)] 
factor: speed up multiprecision Pollard’s rho

These changes are taken from a proposal by Torbjörn Granlund in:
https://lists.gnu.org/r/coreutils/2025-01/msg00000.html
On my x86-64 platform, they improve speed by more than 8× when
factoring 340282366920938463463374607431768211457.
* src/factor.c (mp_modadd, mp_modsub, mp_modadd_1, mp_mulredc):
New functions.
(MP_FACTOR_USING_POLLARD_RHO_N_MAX): New macro.
(mp_factor_using_pollard_rho): Act on mpn not mpz, and on
mp_limb_t not unsigned long int.  Reorder args.  All uses changed.

3 weeks agofactor: use function for binv
Paul Eggert [Tue, 10 Jun 2025 03:51:56 +0000 (20:51 -0700)] 
factor: use function for binv

* src/factor.c (binv_limb): New function, replacing the old
binv macro.  All uses changed.

3 weeks agofactor: use a more functional style
Paul Eggert [Tue, 10 Jun 2025 00:28:34 +0000 (17:28 -0700)] 
factor: use a more functional style

This is mostly to make the code a bit easier to read.
It shrinks the size of factor.o by 0.7% on my x86-64 platform
though it doesn’t affect CPU performance significantly.
* src/factor.c (mp_no_factors): Rename from mp_factor_init.
(mp_no_factors, mp_factor_using_division, mp_factor):
Return struct mp_factors rather than modifying one passed by reference.
All uses changed.

3 weeks agofactor: use single vector in struct mp_factors
Paul Eggert [Mon, 9 Jun 2025 16:20:56 +0000 (09:20 -0700)] 
factor: use single vector in struct mp_factors

* src/factor.c (struct mp_factor): New type.
(struct mp_factors): Use it to replace P and E with F.
All uses changed.

3 weeks agofactor: omit unnecessary divisions by small primes
Paul Eggert [Sun, 8 Jun 2025 18:34:51 +0000 (11:34 -0700)] 
factor: omit unnecessary divisions by small primes

* src/factor.c (mp_factor_using_division):
When continuing in single precision, don’t divide by primes that
were already cast out in multiple precision.
On my platform this gave a 2.5% speedup when factoring
2**128 + 172261 = 4999 * 68070087401668026297934508388031283,
as W_TYPE_SIZE == 64 and 4999 is the last prime in the primes table.

3 weeks agofactor: use primes_diff more consistently
Paul Eggert [Sun, 8 Jun 2025 07:59:44 +0000 (00:59 -0700)] 
factor: use primes_diff more consistently

* src/factor.c (mp_factor_using_division): Use index into
primes_diff consistently with other uses.  This is mostly just a
style change, and likely doesn’t change the generated machine code.

3 weeks agofactor: refactor to for later performance speedup
Paul Eggert [Sun, 8 Jun 2025 05:29:54 +0000 (22:29 -0700)] 
factor: refactor to for later performance speedup

This does not affect performance much, but it should allow future
performance improvements.
* src/factor.c (factor_using_division): Two new args I and P,
which generalize this function.  All uses changed.
(mp_finish_up_in_single, factor_up): New functions, like the
non-*_up* versions but with two new args PRIME_IDX and PRIME.
They mostly just have the old body of the old non-*_up_ versions.
(mp_finish_in_single, factor): Rewrite in terms of the new functions.

3 weeks agofactor: switch from mp to single when doable
Paul Eggert [Wed, 4 Jun 2025 17:12:29 +0000 (10:12 -0700)] 
factor: switch from mp to single when doable

This significantly improves performance when a number exceeds
2**(W_TYPE_SIZE - 1) and is the product of a prime less than
FIRST_OMITTED_PRIME and another prime less than 2**(W_TYPE_SIZE - 1).
On my platform, for example, it doubled the speed of factoring
4999 * (2**128 - 159).
* src/factor.c (mp_size, mp_finish_in_single): New functions.
(mp_factor_using_division, mp_factor_using_pollard_rho):
Finish using single precision when possible.
* tests/factor/factor.pl (lt-5000-times-128-bit): New test.

3 weeks agofactor: primes_diff idx type consistency
Paul Eggert [Wed, 4 Jun 2025 15:07:23 +0000 (08:07 -0700)] 
factor: primes_diff idx type consistency

* src/factor.c (factor_insert_refind):
Use idx_t for indexes into primes_diff,
for consistency with other indexes into primes_diff.
This has no practical effect unless the primes_diff
table becomes unreasonably large.

3 weeks agofactor: omit q from mp_factor_using_division
Paul Eggert [Mon, 2 Jun 2025 17:03:34 +0000 (10:03 -0700)] 
factor: omit q from mp_factor_using_division

* src/factor.c (mp_factor_using_division): Remove unused local.

3 weeks agofactor: mp insert multiplicity too
Paul Eggert [Mon, 2 Jun 2025 17:02:14 +0000 (10:02 -0700)] 
factor: mp insert multiplicity too

Support a multiplicity argument in the mp case, too.
This helps keeps the two cases in sync, for maintenance.
* src/factor.c (mp_factor_insert, mp_factor_insert_ui):
New arg M, for multiplicity.  All callers changed.

3 weeks agofactor: prefer non-macros
Paul Eggert [Mon, 2 Jun 2025 05:47:36 +0000 (22:47 -0700)] 
factor: prefer non-macros

Use something other than a macro when that is easy and won’t hurt
performance.
* src/factor.c (__ll_B, __ll_lowpart, _ll_highpart) [!USE_LONGLONG_H]:
(MAX_NFACTS, highbit_to_mask, factor_insert, PRIMES_PTAB_ENTRIES):
Make these enums, or constants, or static functions instead of macros.
(highbit_to_mask): Rename from HIGHBIT_TO_MASK.  All uses changed.

3 weeks agofactor: let builder specify MR_REPS
Paul Eggert [Sat, 14 Jun 2025 02:48:16 +0000 (19:48 -0700)] 
factor: let builder specify MR_REPS

* src/factor.c (MR_REPS): Let the builder specify it
with -DMR_REPS=whatever.

3 weeks agofactor: add comments
Paul Eggert [Sat, 31 May 2025 20:09:02 +0000 (13:09 -0700)] 
factor: add comments

3 weeks agofactor: factor insertion simplifications
Paul Eggert [Sat, 31 May 2025 01:58:21 +0000 (18:58 -0700)] 
factor: factor insertion simplifications

* src/factor.c (factor_insert_multiplicity):
Adjust to keep in sync with mp_factor_insert changes below,
by adding 1 to the index and using memmove to move.
(mp_factor_insert): Omit redundant call to mpz_cmp.
Prefer idx_t (always nonnegative) to ptrdiff_t,
by adding 1 to the indexes.
Prefer mpz_init_set to mpz_init+mpz_set.
Use memmove to move, rather than doing it by hand.

3 weeks agofactor: check unsigned char counts
Paul Eggert [Sat, 24 May 2025 18:57:05 +0000 (11:57 -0700)] 
factor: check unsigned char counts

* src/factor.c (MAX_NFACTS): Allow word size of 128 bits,
even if this is only theoretical now.
Check that struct factors’s unsigned char counts won’t overflow.

3 weeks agofactor: fix comment
Paul Eggert [Sat, 24 May 2025 17:37:48 +0000 (10:37 -0700)] 
factor: fix comment

3 weeks agofactor: paren cleanup
Paul Eggert [Sat, 24 May 2025 17:25:21 +0000 (10:25 -0700)] 
factor: paren cleanup

* src/factor.c (umul_ppmm, udiv_qrnnd, addmod, addmod2, submod2)
(binv, divexact_21, redcify2, div_smallq): Omit unnecessary parens.

3 weeks agofactor: simplify longlong.h setup
Paul Eggert [Thu, 22 May 2025 22:35:22 +0000 (15:35 -0700)] 
factor: simplify longlong.h setup

* src/factor.c (USE_LONGLONG_H):
Default to false on unusual (but standard-conforming)
platforms that lack int64_t etc.
(UWtype, UHWtype): Now typedefs, not macros.
(UQItype): Remove.
(SItype, USItype, DItype, UDItype): Use standard C types.

3 weeks agofactor: prefer uuint to two words in a couple of places
Paul Eggert [Sun, 1 Jun 2025 23:28:47 +0000 (16:28 -0700)] 
factor: prefer uuint to two words in a couple of places

This simplifies things slightly by using uuint for
some two-word integers.
* src/factor.c (strtouuint): Accept uuint *, not two mp_limb_t *.
All callers changed.
(print_factors_single): Accept uuint, not two limbs.
All callers changed.
(print_factors): Use simpler test for high bit,
one that need not worry about promoting to int.

3 weeks agofactor: FALLTHROUGH instead of break
Paul Eggert [Sun, 1 Jun 2025 23:22:55 +0000 (16:22 -0700)] 
factor: FALLTHROUGH instead of break

* src/factor.c (print_factors): Use FALLTHROUGH
to make it clear that the "Use GMP" comment also applies here.

3 weeks agofactor: remove wide_uuint
Paul Eggert [Sun, 1 Jun 2025 23:18:09 +0000 (16:18 -0700)] 
factor: remove wide_uuint

Simplify by using GMP’s word type instead of pretending to roll our own.
* src/factor.c (wide_uuint): Remove.  All uses replaced by mp_limb_t.
(umul_ppmm) [!umul_ppmm]: Don’t assume unsigned long is at least half
as wide as mp_limb_t.  This simpler anyway.
(strtouuint): Rename from strto2wide_uint.  All uses changed.

3 weeks agofactor: use same word size as GMP
Paul Eggert [Sun, 1 Jun 2025 23:02:21 +0000 (16:02 -0700)] 
factor: use same word size as GMP

Remove experimental code for 128-bit words as it does not work and
we lack time to figure out why.  Instead, ensure that words are
the same size as with GMP.
* src/factor.c (USE_INT128): Remove.  All uses removed.
(wide_uint, W_TYPE_SIZE): Define to be the same as GMP.
(MP_LIMB_MAX): New macro.  Check that it matches W_TYPE_SIZE.
(USE_LONGLONG_H): Default to true.
(UHWtype) [USE_LONGLONG_H]: Define to unsigned int, same as GMP.
(prime_p): Go back to not worrying about 128-bit words,
since GMP doesn’t worry and doesn’t use them.
(lbuf_putbitcnt): New function, since we cannot assume
that bitcnt_t fits into mp_limb_t.
(print_factors): Use it.
* src/make-prime-list.c (output_primes):
Don’t assume that wide_uint’s maximum is UINTMAX_MAX.

3 weeks agofactor: unsigned long → mp_bitcnt_t
Paul Eggert [Mon, 2 Jun 2025 06:18:23 +0000 (23:18 -0700)] 
factor: unsigned long → mp_bitcnt_t

* src/factor.c (struct mp_factors): e (multiplicity) member
is now of type mp_bitcnt_t, not unsigned long int, since
its value is at most a bit count.  All uses changed.

3 weeks agofactor: fix test case name
Paul Eggert [Tue, 20 May 2025 21:15:01 +0000 (14:15 -0700)] 
factor: fix test case name

* tests/factor/factor.pl (bug-gmp-plus_2_sup_127_plus_1):
Rename from bug-gmp-plus_2_sup_128_plus_1, so that
it accurately reflects the test case.

3 weeks agofactor: generalize BIG_POWER_OF_10
Paul Eggert [Sun, 1 Jun 2025 22:55:27 +0000 (15:55 -0700)] 
factor: generalize BIG_POWER_OF_10

* src/factor.c (BIG_POWER_OF_10, LOG_BIG_POWER_OF_10):
Place fewer restrictions on BIG_POWER_OF_10.
This is only for currently-theoretical hosts;
it shouldn’t affect machine code on practical platforms.

3 weeks agofactor: remove wide_int
Paul Eggert [Sun, 1 Jun 2025 22:51:26 +0000 (15:51 -0700)] 
factor: remove wide_int

* src/factor.c (wide_int): Remove, since it gets in the
way of using mp_limb_t for words.  All uses removed.
(submod2, HIGHBIT_TO_MASK, divexact_21):
Rewrite without using wide_int.
This shouldn't change the machine code these days,
as compilers are pretty smart about isolating the
top bit of an unsigned int.

3 weeks agofactor: add platform sanity check
Paul Eggert [Sun, 1 Jun 2025 22:47:33 +0000 (15:47 -0700)] 
factor: add platform sanity check

* src/factor.c: Check against theoretical platform.

3 weeks agofactor: squfof cleanup
Paul Eggert [Sat, 24 May 2025 17:29:06 +0000 (10:29 -0700)] 
factor: squfof cleanup

* src/factor.c (USE_SQUFOF, STAT_SQUFOF):
Assume these are always false, and simplify the code accordingly.
We can bring it back later if needed be.

3 weeks agofactor: don’t used uninitialized uu[0]
Paul Eggert [Sun, 1 Jun 2025 01:17:34 +0000 (18:17 -0700)] 
factor: don’t used uninitialized uu[0]

In practice there’s no bug but we might as well avoid the
undefined behavior.
* src/factor.c (hi_is_set): New static function.
(factor_insert_large, prime2_p, print_factors_single): Use it.

4 weeks agobuild: avoid make distcheck error
Pádraig Brady [Sat, 5 Jul 2025 16:45:00 +0000 (17:45 +0100)] 
build: avoid make distcheck error

* src/local.mk: Similarly to commit v8.22-156-g09937e9d0
track speedlist.h with nodist_src_stty_SOURCES and DISTCLEANFILES
to ensure the make distcheck manifest comparison passes.
Addresses https://bug.gnu.org/78960

4 weeks agodoc: fix a dead link
Collin Funk [Sat, 5 Jul 2025 04:07:23 +0000 (21:07 -0700)] 
doc: fix a dead link

* doc/coreutils.texi (Block Size): Use an updated link to SI prefixes.

4 weeks agobuild: fix non parallel VPATH builds
Pádraig Brady [Sat, 5 Jul 2025 11:49:02 +0000 (12:49 +0100)] 
build: fix non parallel VPATH builds

* src/local.mk: Use the coarser BUILT_SOURCES mechanism
to generate speedlist.h, rather than a specific dependency
(which did seem to work for parallel builds).
Fixes https://bugs.gnu.org/78960

4 weeks agomaint: prefer endian.h macros to WORDS_BIGENDIAN, part 2
Collin Funk [Sat, 5 Jul 2025 03:52:37 +0000 (20:52 -0700)] 
maint: prefer endian.h macros to WORDS_BIGENDIAN, part 2

* src/blake2/blake2-impl.h: Include endian.h. Use BYTE_ORDER and
LITTLE_ENDIAN instead of WORDS_BIGENDIAN.

4 weeks agomaint: prefer endian.h macros to WORDS_BIGENDIAN
Collin Funk [Fri, 4 Jul 2025 17:59:39 +0000 (10:59 -0700)] 
maint: prefer endian.h macros to WORDS_BIGENDIAN

* src/od.c: Include endian.h.
(WORDS_BIGENDIAN): Remove definition.
(main): Use BYTE_ORDER, BIG_ENDIAN, LITTLE_ENDIAN instead of
WORDS_BIGENDIAN. Fix formatting.