From: Paul Eggert Date: Wed, 14 Jun 2023 21:52:37 +0000 (-0700) Subject: cksum,wc: clean up hw capability checking X-Git-Tag: v9.4~105 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f780a85985f5b069ba8597aaeac49eb74864926a;p=thirdparty%2Fcoreutils.git cksum,wc: clean up hw capability checking * src/cksum.c (cksum_pclmul) [!CRCTAB && !USE_PCLMUL_CRC32]: Remove macro. (cksum_fp): No longer file-scope. (pclmul_supported): Define only if USE_PCLMUL_CRC32. This omits the debug output "using generic hardware support" for simplicity and consistency with wc’s output. (crc_sum_stream) [!USE_PCLMUL_32]: No need for static function pointer. * src/wc.c (wc_lines_p) [USE_AVX2_WC_LINECOUNT]: No longer file-scope. (wc) [USE_AVX2_WC_LINECOUNT]: Check for avx2 support at most once, which was surely the code’s original intent. (wc) [!USE_AVX2_WC_LINECOUNT]: No need for static function pointer. --- diff --git a/src/cksum.c b/src/cksum.c index 352a0ba3af..26bb29bdb6 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -141,23 +141,14 @@ main (void) # include "error.h" # include "cksum.h" -# if !USE_PCLMUL_CRC32 -# define cksum_pclmul cksum_slice8 -# endif /* USE_PCLMUL_CRC32 */ /* Number of bytes to read at once. */ # define BUFLEN (1 << 16) - -static bool -cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out); -static bool - (*cksum_fp)(FILE *, uint_fast32_t *, uintmax_t *); - +# if USE_PCLMUL_CRC32 static bool pclmul_supported (void) { -# if USE_PCLMUL_CRC32 bool pclmul_enabled = (0 < __builtin_cpu_supports ("pclmul") && 0 < __builtin_cpu_supports ("avx")); @@ -168,12 +159,8 @@ pclmul_supported (void) : _("pclmul support not detected"))); return pclmul_enabled; -# else - if (cksum_debug) - error (0, 0, "%s", _("using generic hardware support")); - return false; -# endif /* USE_PCLMUL_CRC32 */ } +# endif /* USE_PCLMUL_CRC32 */ static bool cksum_slice8 (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out) @@ -238,13 +225,13 @@ crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length) uintmax_t total_bytes = 0; uint_fast32_t crc = 0; +# if USE_PCLMUL_CRC32 + static bool (*cksum_fp) (FILE *, uint_fast32_t *, uintmax_t *); if (! cksum_fp) - { - if (pclmul_supported ()) - cksum_fp = cksum_pclmul; - else - cksum_fp = cksum_slice8; - } + cksum_fp = pclmul_supported () ? cksum_pclmul : cksum_slice8; +#else + bool (*cksum_fp) (FILE *, uint_fast32_t *, uintmax_t *) = cksum_slice8; +#endif if (! cksum_fp (stream, &crc, &total_bytes)) return -1; diff --git a/src/wc.c b/src/wc.c index ebe83af4df..30214655c7 100644 --- a/src/wc.c +++ b/src/wc.c @@ -54,18 +54,12 @@ /* Size of atomic reads. */ #define BUFFER_SIZE (16 * 1024) -static bool -wc_lines (char const *file, int fd, uintmax_t *lines_out, - uintmax_t *bytes_out); #ifdef USE_AVX2_WC_LINECOUNT /* From wc_avx2.c */ extern bool wc_lines_avx2 (char const *file, int fd, uintmax_t *lines_out, uintmax_t *bytes_out); #endif -static bool -(*wc_lines_p) (char const *file, int fd, uintmax_t *lines_out, - uintmax_t *bytes_out) = wc_lines; static bool debug; @@ -441,8 +435,12 @@ wc (int fd, char const *file_x, struct fstatus *fstatus, off_t current_pos) else if (!count_chars && !count_complicated) { #ifdef USE_AVX2_WC_LINECOUNT - if (avx2_supported ()) - wc_lines_p = wc_lines_avx2; + static bool (*wc_lines_p) (char const *, int, uintmax_t *, uintmax_t *); + if (!wc_lines_p) + wc_lines_p = avx2_supported () ? wc_lines_avx2 : wc_lines; +#else + bool (*wc_lines_p) (char const *, int, uintmax_t *, uintmax_t *) + = wc_lines; #endif /* Use a separate loop when counting only lines or lines and bytes --