lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

debug.h (1713B)


      1 #ifndef DEBUG_H
      2 #define DEBUG_H
      3 
      4 #include <inttypes.h>
      5 #include <stdio.h>
      6 
      7 
      8 extern FILE *DUMP; /* Define this variable somewhere (eg with DUMP = stderr). */
      9 
     10 
     11 static inline void debug_dump_lanes(const char *header, size_t len, const uint8_t buf[len], int indent)
     12 {
     13     fprintf(DUMP, "%s\n", header);
     14 
     15     for (size_t line=0; line<len/8; line++)
     16     {
     17         fprintf(DUMP, "%*s", indent, "");
     18         for (size_t b=0; b<8; b++)
     19         {
     20             fprintf(DUMP, "%*s%02x", 5, "", buf[line*8+b]);
     21         }
     22         fprintf(DUMP, "\n");
     23     }
     24     fprintf(DUMP, "\n");
     25 }
     26 
     27 static inline void debug_dump_buffer(const char *header, size_t len, const uint8_t buf[len], int indent)
     28 {
     29     fprintf(DUMP, "%*s%s\n", indent, "", header);
     30 
     31     for (size_t line=0; line<len/8; line++)
     32     {
     33         fprintf(DUMP, "%*s[0x%02zx] ", indent, "", line*8);
     34         for (size_t b=0; b<8; b++)
     35         {
     36             /* fprintf(DUMP, "[%zu / %zu => %zu]", line, b, line*8+b); */
     37             fprintf(DUMP, "%02x ", buf[line*8+b]);
     38         }
     39         fprintf(DUMP, "\n");
     40     }
     41 
     42     size_t rest = len%8;
     43     if (rest != 0)
     44     {
     45         fprintf(DUMP, "%*s[0x%02zx] ", indent, "", len-rest);
     46         for (size_t b=0; b<rest; b++)
     47         {
     48             fprintf(DUMP, "%02x ", buf[len-rest+b]);
     49         }
     50         fprintf(DUMP, "\n");
     51     }
     52 
     53     fprintf(DUMP, "\n");
     54 }
     55 
     56 static inline void debug_open_dump(const char *folder, const char *suite, const char *vector_name)
     57 {
     58     size_t namelen = snprintf(
     59         NULL, 0, "%s/traces-%s-%s.txt", folder, suite, vector_name
     60     );
     61     char name[namelen+1];
     62     snprintf(name, sizeof(name), "%s/traces-%s-%s.txt", folder, suite, vector_name);
     63     DUMP = fopen(name, "w");
     64 }
     65 
     66 
     67 #endif /* DEBUG_H */