]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: add --debug to diagnose which implementation used
authorPádraig Brady <P@draigBrady.com>
Sat, 13 Mar 2021 18:10:12 +0000 (18:10 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 15 Mar 2021 12:44:27 +0000 (12:44 +0000)
* src/cksum.c: (main): Use getopt_long to parse options,
and handle the new --debug option.
(pclmul_supported): Diagnose various failures and attempts.
* NEWS: Mention the new option.

NEWS
src/cksum.c

diff --git a/NEWS b/NEWS
index aad05df6db629bd10c2c72ecfe52aaaba13849bd..89f60d28fed0625a0bf29bd5ffc3fa835ce2cd0a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -70,7 +70,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   cat --show-ends will now show \r\n as ^M$.  Previously the \r was taken
   literally, thus overwriting the first character in the line with '$'.
 
-  cksum is now up to 4 times faster by using a slice by 8 algorithm.
+  cksum is now up to 4 times faster by using a slice by 8 algorithm,
+  and at least 8 times faster where pclmul instructions are supported.
+  A new --debug option will indicate if pclmul is being used.
 
   df now recognizes these file systems as remote:
   acfs, coda, fhgfs, gpfs, ibrix, ocfs2, and vxfs.
index a38f03ca86b5a6d21efc84ee7fdc6039b83c5ef1..f3d41666bddee1c9a1d0c3f31c5c3e289484e3a9 100644 (file)
@@ -39,6 +39,7 @@
 
 #define AUTHORS proper_name ("Q. Frank Xia")
 
+#include <getopt.h>
 #include <stdio.h>
 #include <sys/types.h>
 #include <stdint.h>
@@ -141,7 +142,6 @@ main (void)
 
 #else /* !CRCTAB */
 
-# include "long-options.h"
 # include "die.h"
 # include "error.h"
 
@@ -153,6 +153,21 @@ main (void)
 /* Number of bytes to read at once.  */
 # define BUFLEN (1 << 16)
 
+static bool debug;
+
+enum
+{
+  DEBUG_PROGRAM_OPTION = CHAR_MAX + 1,
+};
+
+static struct option const longopts[] =
+{
+  {"debug", no_argument, NULL, DEBUG_PROGRAM_OPTION},
+  {GETOPT_HELP_OPTION_DECL},
+  {GETOPT_VERSION_OPTION_DECL},
+  {NULL, 0, NULL, 0},
+};
+
 /* Nonzero if any of the files read were the standard input. */
 static bool have_read_stdin;
 
@@ -173,13 +188,21 @@ pclmul_supported (void)
   unsigned int edx = 0;
 
   if (! __get_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return false;
+    {
+      if (debug)
+        error (0, 0, "%s", _("failed to get cpuid"));
+      return false;
+    }
 
-  if (! (ecx & bit_PCLMUL))
-    return false;
+  if (! (ecx & bit_PCLMUL) || ! (ecx & bit_AVX))
+    {
+      if (debug)
+        error (0, 0, "%s", _("pclmul support not detected"));
+      return false;
+    }
 
-  if (! (ecx & bit_AVX))
-    return false;
+  if (debug)
+    error (0, 0, "%s", _("using pclmul hardware support"));
 
   return true;
 }
@@ -330,7 +353,7 @@ Print CRC checksum and byte counts of each FILE.\n\
 int
 main (int argc, char **argv)
 {
-  int i;
+  int i, c;
   bool ok;
 
   initialize_main (&argc, &argv);
@@ -345,8 +368,22 @@ main (int argc, char **argv)
      so that processes running in parallel do not intersperse their output.  */
   setvbuf (stdout, NULL, _IOLBF, 0);
 
-  parse_gnu_standard_options_only (argc, argv, PROGRAM_NAME, PACKAGE, Version,
-                                   true, usage, AUTHORS, (char const *) NULL);
+  while ((c = getopt_long (argc, argv, "", longopts, NULL)) != -1)
+    {
+      switch (c)
+        {
+        case DEBUG_PROGRAM_OPTION:
+          debug = true;
+          break;
+
+        case_GETOPT_HELP_CHAR;
+
+        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
+
+        default:
+          usage (EXIT_FAILURE);
+        }
+    }
 
   have_read_stdin = false;