From 7647a93d104494338f28c9e5370a673aef883533 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Sun, 18 Feb 2024 20:01:08 +0200 Subject: [PATCH 1/2] Add usage for secondary compressor for iccodec --- lib/icapp.c | 26 +++++++++++++++++++------- lib/iccodec.c | 31 +++++++++++++++++++++++++++++++ lib/include_/iccodec.h | 1 + 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/lib/icapp.c b/lib/icapp.c index 42646491..ce8a9124 100755 --- a/lib/icapp.c +++ b/lib/icapp.c @@ -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 @@ -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"); @@ -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, " -Es 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"); @@ -2214,13 +2232,7 @@ 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; + if(!scmd) scmd = zDefault; while(isspace(*scmd)) scmd++; char *q; int i; diff --git a/lib/iccodec.c b/lib/iccodec.c index 9fffe363..43f636d5 100644 --- a/lib/iccodec.c +++ b/lib/iccodec.c @@ -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]:""; } @@ -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" diff --git a/lib/include_/iccodec.h b/lib/include_/iccodec.h index 34995d50..aeeed246 100644 --- a/lib/include_/iccodec.h +++ b/lib/include_/iccodec.h @@ -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 } From 03da341d6738aeb7e29fc442ad1320625f292232 Mon Sep 17 00:00:00 2001 From: Pavel P Date: Sun, 18 Feb 2024 20:01:08 +0200 Subject: [PATCH 2/2] Add usage for secondary compressor for iccodec --- lib/icapp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/icapp.c b/lib/icapp.c index ce8a9124..d1615d6b 100755 --- a/lib/icapp.c +++ b/lib/icapp.c @@ -2224,7 +2224,7 @@ int main(int argc, char* argv[]) { //testrazor(); } } #ifdef _LZTURBO - beini(); + beini(); #endif if(argc - optind < 1) { usage(argv[0]); @@ -2232,7 +2232,9 @@ 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))); - if(!scmd) scmd = zDefault; + char _scmd[33]; + strcpy(_scmd, zDefault); + if(!scmd) scmd = _scmd; while(isspace(*scmd)) scmd++; char *q; int i;