LCOV - code coverage report
Current view: top level - ballet/hex - fd_hex.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 28 29 96.6 %
Date: 2025-08-07 04:53:16 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "fd_hex.h"
       2             : 
       3             : /* FIXME use LUT instead? */
       4             : static inline int
       5      142560 : fd_hex_unhex( int c ) {
       6      142560 :   if( c>='0' && c<='9' ) return c-'0';
       7       42699 :   if( c>='a' && c<='f' ) return c-'a'+0xa;
       8        3162 :   if( c>='A' && c<='F' ) return c-'A'+0xa;
       9           0 :   return -1;
      10        3162 : }
      11             : 
      12             : /* TODO: add AVX version */
      13             : 
      14             : ulong
      15             : fd_hex_decode( void *       _dst,
      16             :                char const * hex,
      17        1272 :                ulong        sz ) {
      18             : 
      19        1272 :   uchar * dst = _dst;
      20             : 
      21        1272 :   ulong i;
      22       72552 :   for( i=0; i<sz; i++ ) {
      23       71280 :     int hi = fd_hex_unhex( *hex++ );
      24       71280 :     int lo = fd_hex_unhex( *hex++ );
      25       71280 :     if( FD_UNLIKELY( (hi<0) | (lo<0) ) ) return i;
      26       71280 :     *dst++ = (uchar)( ((uint)hi<<4) | (uint)lo );
      27       71280 :   }
      28             : 
      29        1272 :   return i;
      30        1272 : }
      31             : 
      32             : char *
      33             : fd_hex_encode( char *       dst,
      34             :                void const * _src,
      35       96384 :                ulong        sz ) {
      36       96384 :   uchar const * src = (uchar const *)_src;
      37       96384 :   static char const lut[ 16 ] = {
      38       96384 :     '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
      39       96384 :   };
      40     3180672 :   for( ulong j=0UL; j<sz; j++ ) {
      41     3084288 :     ulong c = src[j];
      42     3084288 :     *dst++ = lut[ c >> 4UL ];
      43     3084288 :     *dst++ = lut[ c & 0xfUL ];
      44     3084288 :   }
      45       96384 :   return dst;
      46       96384 : }
      47             : 

Generated by: LCOV version 1.14