LCOV - code coverage report
Current view: top level - ballet/reedsol - fd_reedsol.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 38 48 79.2 %
Date: 2024-11-13 11:58:15 Functions: 2 3 66.7 %

          Line data    Source code
       1             : #include "fd_reedsol_private.h"
       2             : 
       3             : /* Include the constants in one central spot */
       4             : 
       5             : #if FD_REEDSOL_ARITH_IMPL==0
       6             : FD_IMPORT_BINARY( fd_reedsol_arith_consts_generic_mul, "src/ballet/reedsol/constants/generic_constants.bin" );
       7             : #elif FD_REEDSOL_ARITH_IMPL==1
       8             : FD_IMPORT_BINARY( fd_reedsol_arith_consts_avx_mul, "src/ballet/reedsol/constants/avx2_constants.bin" );
       9             : #else
      10             : FD_IMPORT_BINARY( fd_reedsol_arith_consts_gfni_mul, "src/ballet/reedsol/constants/gfni_constants.bin" );
      11             : #endif
      12             : 
      13             : void
      14     1481274 : fd_reedsol_encode_fini( fd_reedsol_t * rs ) {
      15             : 
      16      493758 : # if FD_REEDSOL_ARITH_IMPL==3
      17      493758 :   if( FD_LIKELY( (rs->data_shred_cnt==32UL) & (rs->parity_shred_cnt==32UL ) ) )
      18      384634 :     fd_reedsol_private_encode_32_32( rs->shred_sz, rs->encode.data_shred, rs->encode.parity_shred, rs->scratch );
      19      109124 :   else
      20      109124 : # endif
      21     1096640 :   if( FD_UNLIKELY( rs->data_shred_cnt<=16UL ) )
      22       47760 :     fd_reedsol_private_encode_16 ( rs->shred_sz, rs->encode.data_shred, rs->data_shred_cnt, rs->encode.parity_shred, rs->parity_shred_cnt );
      23     1048880 :   else if( FD_LIKELY( rs->data_shred_cnt<=32UL ) )
      24      814052 :     fd_reedsol_private_encode_32 ( rs->shred_sz, rs->encode.data_shred, rs->data_shred_cnt, rs->encode.parity_shred, rs->parity_shred_cnt );
      25      234828 :   else if( FD_LIKELY( rs->data_shred_cnt<=64UL ) )
      26      227154 :     fd_reedsol_private_encode_64 ( rs->shred_sz, rs->encode.data_shred, rs->data_shred_cnt, rs->encode.parity_shred, rs->parity_shred_cnt );
      27        7674 :   else
      28        7674 :       fd_reedsol_private_encode_128( rs->shred_sz, rs->encode.data_shred, rs->data_shred_cnt, rs->encode.parity_shred, rs->parity_shred_cnt );
      29             : 
      30     1481274 :   rs->data_shred_cnt   = 0UL;
      31     1481274 :   rs->parity_shred_cnt = 0UL;
      32     1481274 : }
      33             : 
      34             : int
      35          90 : fd_reedsol_recover_fini( fd_reedsol_t * rs ) {
      36             : 
      37          90 :   ulong data_shred_cnt   = rs->data_shred_cnt;
      38          90 :   ulong parity_shred_cnt = rs->parity_shred_cnt;
      39             : 
      40          90 :   rs->data_shred_cnt   = 0UL;
      41          90 :   rs->parity_shred_cnt = 0UL;
      42             : 
      43             :   /* How many shreds do we need to consider in order to find
      44             :      rs->data_shred_cnt un-erased? */
      45             : 
      46          90 :   ulong unerased = 0UL;
      47          90 :   ulong i        = 0UL;
      48        4161 :   for( ; i<data_shred_cnt + parity_shred_cnt; i++ ) {
      49        4161 :     unerased += !rs->recover.erased[ i ];
      50        4161 :     if( unerased==data_shred_cnt ) break;
      51        4161 :   }
      52          90 :   if( FD_UNLIKELY( unerased!=data_shred_cnt ) ) return FD_REEDSOL_ERR_PARTIAL;
      53             : 
      54             : # if 0 /* TODO: Add first variant for slightly more performance */
      55             :   if( FD_LIKELY( i==data_shred_cnt ) ) {
      56             :     // Common case: we have all of the data shreds
      57             :     if( FD_UNLIKELY( i<=16UL ) )
      58             :       return fd_reedsol_private_recover_first_16( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt );
      59             :     if( FD_LIKELY( i<=32UL ) )
      60             :       return fd_reedsol_private_recover_first_32( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt );
      61             :     if( FD_LIKELY( i<=64UL ) )
      62             :       return fd_reedsol_private_recover_first_64( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt );
      63             :     return fd_reedsol_private_recover_first_128(  rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt );
      64             :   }
      65             : # endif
      66             : 
      67          90 :   if( FD_UNLIKELY( i<16UL ) )
      68          12 :     return fd_reedsol_private_recover_var_16( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt, rs->recover.erased );
      69          78 :   if( FD_LIKELY(   i<32UL ) )
      70          33 :     return fd_reedsol_private_recover_var_32( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt, rs->recover.erased );
      71          45 :   if( FD_LIKELY(   i<64UL ) )
      72          39 :     return fd_reedsol_private_recover_var_64( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt, rs->recover.erased );
      73           6 :   if( FD_LIKELY(   i<128UL ) )
      74           6 :     return fd_reedsol_private_recover_var_128( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt, rs->recover.erased );
      75             : 
      76           0 :   return fd_reedsol_private_recover_var_256( rs->shred_sz, rs->recover.shred, data_shred_cnt, parity_shred_cnt, rs->recover.erased );
      77           6 : }
      78             : 
      79             : char const *
      80           0 : fd_reedsol_strerror( int err ) {
      81           0 :   switch( err ) {
      82           0 :   case FD_REEDSOL_SUCCESS:     return "success";
      83           0 :   case FD_REEDSOL_ERR_CORRUPT: return "corrupt";
      84           0 :   case FD_REEDSOL_ERR_PARTIAL: return "partial";
      85           0 :   default: break;
      86           0 :   }
      87           0 :   return "unknown";
      88           0 : }

Generated by: LCOV version 1.14