Skip to content

Commit

Permalink
Add ability to specify secondary compressor for iccodec
Browse files Browse the repository at this point in the history
  • Loading branch information
pps83 committed Feb 18, 2024
1 parent 06d6aad commit f257445
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
30 changes: 23 additions & 7 deletions lib/icapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ char *codstr(unsigned codecid) { return ""; }
void tpsizeset(unsigned _tpbsize) {}
void tpmodeset(unsigned _tpmode) {}
int lzidget(char *scmd) { return 0; }
unsigned* getAvailableLzs() { return NULL; }
#endif

#ifdef _QCOMPRESS
Expand Down Expand Up @@ -2049,11 +2050,26 @@ unsigned bench64(unsigned char *in, unsigned n, unsigned char *out, unsigned cha
return l;
}

const char* printLzs(char buf[256]) {
buf[0] = 0;
for (unsigned* lzs = getAvailableLzs(); lzs && *lzs != ICC_LAST; ++lzs){
strcat(buf, codstr(*lzs));
strcat(buf, " ");
}
return buf;
}

typedef struct len_t { unsigned id,cnt; uint64_t len; } len_t;
#define CMPSA(_a_,_b_, _t_, _v_) (((((_t_ *)_a_)->_v_) > (((_t_ *)_b_)->_v_)) - ((((_t_ *)_a_)->_v_) < (((_t_ *)_b_)->_v_)))
static int cmpsna(const void *a, const void *b) { return CMPSA(a, b, len_t, len); }
#ifdef _LZ4
static const char zDefault[] = "lz4,1";
#else
static const char zDefault[] = "memcpy";
#endif

void usage(char *pgm) {
char lzs[256];
fprintf(stderr, "\nIcApp Copyright (c) 2013-2023 Powturbo %s\n", __DATE__);
fprintf(stderr, "Usage: %s [options] [file]\n", pgm);
//fprintf(stderr, " -b#s # = blocksize (default filesize,). max=1GB\n");
Expand All @@ -2063,6 +2079,8 @@ void usage(char *pgm) {
fprintf(stderr, " -i#/-j# # = Minimum de/compression iterations per run (default=auto)\n");
fprintf(stderr, " -I#/-J# # = Number of de/compression runs (default=3)\n");
fprintf(stderr, " -e# # = function ids separated by ',' or ranges '#-#' (default='1-%d')\n", ID_MEMCPY);
fprintf(stderr, " -Zs s = secondary compressor with level separated by ',' (default %s)\n", zDefault);
fprintf(stderr, " available compressors: %s\n", printLzs(lzs));
fprintf(stderr, "File format:\n");
fprintf(stderr, " -F[Xx[k][H]][.d]\n");
fprintf(stderr, " X = file format:\n");
Expand Down Expand Up @@ -2134,10 +2152,13 @@ int main(int argc, char* argv[]) { //testrazor();
for(fno=0; fno < 255; fno++)
lens[fno].id = 0, lens[fno].len = (uint64_t)-1;

char _scmd[33];
strcpy(_scmd, zDefault);

int c, digit_optind = 0, this_option_optind = optind ? optind : 1, option_index = 0;
static struct option long_options[] = { {"blocsize", 0, 0, 'b'}, {0, 0, 0} };
for(;;) {
if((c = getopt_long(argc, argv, "a:B:b:C:d:D:d:e:E:f:F:g:G:I:J:k:K:hH:l:m:M:n:p:q:R:s:v:V:w:W:yz:", long_options, &option_index)) == -1) break;
if((c = getopt_long(argc, argv, "a:B:b:C:d:D:d:e:E:f:F:g:G:I:J:k:K:hH:l:m:M:n:p:q:R:s:v:V:w:W:yz:Z:", long_options, &option_index)) == -1) break;
switch(c) {
case 0 : printf("Option %s", long_options[option_index].name); if(optarg) printf (" with arg %s", optarg); printf ("\n"); break;
case 'b': bsize = argtoi(optarg,1); break;
Expand Down Expand Up @@ -2200,6 +2221,7 @@ int main(int argc, char* argv[]) { //testrazor();
case 'V': tm_verbose = atoi(optarg); break;
case 'W': divs = atoi(optarg); break;
case 'z': zerrlim = strtod(optarg, NULL); break;
case 'Z': strncpy(_scmd, optarg, sizeof(_scmd)-1); break;
default:
fprintf(stderr, "type icapp -h for help\n");
exit(0);
Expand All @@ -2214,12 +2236,6 @@ int main(int argc, char* argv[]) { //testrazor();
}
isa = cpuisa();
cpuini(0); if(verbose>1) printf("detected simd id=%x, %s\n\n", cpuini(0), cpustr(cpuini(0)));
char _scmd[33];
#ifdef _LZ4
strcpy(_scmd, "lz4,1");
#else
strcpy(_scmd, "memcpy");
#endif
if(!scmd) scmd = _scmd;
while(isspace(*scmd)) scmd++;
char *q;
Expand Down
31 changes: 31 additions & 0 deletions lib/iccodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ extern int bwtx, forcelzp;
//------------------------------------------------------------------------------------------------------------------------------
#define powof2(n) !((n)&((n)-1))

static unsigned availableLzs[] = {
#ifdef _LZTURBO
ICC_LZTURBO,
#endif
#ifdef _LZ4
ICC_LZ4,
#endif
#ifdef _ZLIB
ICC_ZLIB,
#endif
#ifdef _ZSTD
ICC_ZSTD,
#endif
#ifdef _FSE
ICC_FSE,
#endif
#ifdef _FSEHUF
ICC_FSEH,
#endif
#ifdef _LZTURBO // _TURBOANX is enabled by _LZTURBO
ICC_LZTANS,
#endif
#ifdef _TURBORC
ICC_TURBORC,
#endif
ICC_MEMCPY,
ICC_LAST
};

char *_codstr[] = { "none", "lzturbo", "lz4", "zlib", "zstd", "fse", "fsehuf", "turboanx", "turborc", "memcpy", NULL };
char *codstr(unsigned cid) { return (cid < ICC_LAST)?_codstr[cid]:""; }

Expand All @@ -54,6 +83,8 @@ int lzidget(char *scmd) {
if(!_codstr[i]) die("compressor '%s' not implemented\n", scmd);
return i;
}
unsigned* getAvailableLzs() { return availableLzs; }

#ifdef _LZTURBO
#define _TURBOANX
#include "../lz/ans.h"
Expand Down
1 change: 1 addition & 0 deletions lib/include_/iccodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void tpmodeset(unsigned _tpmode);
void tpsizeset(unsigned _tpsize);
int lzidget(char *scmd);
char *codstr(unsigned cid);
unsigned* getAvailableLzs(); // ICC_LAST will be the last entry

#ifdef __cplusplus
}
Expand Down

0 comments on commit f257445

Please sign in to comment.