Skip to content

Commit f257445

Browse files
committed
Add ability to specify secondary compressor for iccodec
1 parent 06d6aad commit f257445

File tree

3 files changed

+55
-7
lines changed

3 files changed

+55
-7
lines changed

lib/icapp.c

+23-7
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,7 @@ char *codstr(unsigned codecid) { return ""; }
787787
void tpsizeset(unsigned _tpbsize) {}
788788
void tpmodeset(unsigned _tpmode) {}
789789
int lzidget(char *scmd) { return 0; }
790+
unsigned* getAvailableLzs() { return NULL; }
790791
#endif
791792

792793
#ifdef _QCOMPRESS
@@ -2049,11 +2050,26 @@ unsigned bench64(unsigned char *in, unsigned n, unsigned char *out, unsigned cha
20492050
return l;
20502051
}
20512052

2053+
const char* printLzs(char buf[256]) {
2054+
buf[0] = 0;
2055+
for (unsigned* lzs = getAvailableLzs(); lzs && *lzs != ICC_LAST; ++lzs){
2056+
strcat(buf, codstr(*lzs));
2057+
strcat(buf, " ");
2058+
}
2059+
return buf;
2060+
}
2061+
20522062
typedef struct len_t { unsigned id,cnt; uint64_t len; } len_t;
20532063
#define CMPSA(_a_,_b_, _t_, _v_) (((((_t_ *)_a_)->_v_) > (((_t_ *)_b_)->_v_)) - ((((_t_ *)_a_)->_v_) < (((_t_ *)_b_)->_v_)))
20542064
static int cmpsna(const void *a, const void *b) { return CMPSA(a, b, len_t, len); }
2065+
#ifdef _LZ4
2066+
static const char zDefault[] = "lz4,1";
2067+
#else
2068+
static const char zDefault[] = "memcpy";
2069+
#endif
20552070

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

2155+
char _scmd[33];
2156+
strcpy(_scmd, zDefault);
2157+
21372158
int c, digit_optind = 0, this_option_optind = optind ? optind : 1, option_index = 0;
21382159
static struct option long_options[] = { {"blocsize", 0, 0, 'b'}, {0, 0, 0} };
21392160
for(;;) {
2140-
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;
2161+
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;
21412162
switch(c) {
21422163
case 0 : printf("Option %s", long_options[option_index].name); if(optarg) printf (" with arg %s", optarg); printf ("\n"); break;
21432164
case 'b': bsize = argtoi(optarg,1); break;
@@ -2200,6 +2221,7 @@ int main(int argc, char* argv[]) { //testrazor();
22002221
case 'V': tm_verbose = atoi(optarg); break;
22012222
case 'W': divs = atoi(optarg); break;
22022223
case 'z': zerrlim = strtod(optarg, NULL); break;
2224+
case 'Z': strncpy(_scmd, optarg, sizeof(_scmd)-1); break;
22032225
default:
22042226
fprintf(stderr, "type icapp -h for help\n");
22052227
exit(0);
@@ -2214,12 +2236,6 @@ int main(int argc, char* argv[]) { //testrazor();
22142236
}
22152237
isa = cpuisa();
22162238
cpuini(0); if(verbose>1) printf("detected simd id=%x, %s\n\n", cpuini(0), cpustr(cpuini(0)));
2217-
char _scmd[33];
2218-
#ifdef _LZ4
2219-
strcpy(_scmd, "lz4,1");
2220-
#else
2221-
strcpy(_scmd, "memcpy");
2222-
#endif
22232239
if(!scmd) scmd = _scmd;
22242240
while(isspace(*scmd)) scmd++;
22252241
char *q;

lib/iccodec.c

+31
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ extern int bwtx, forcelzp;
4444
//------------------------------------------------------------------------------------------------------------------------------
4545
#define powof2(n) !((n)&((n)-1))
4646

47+
static unsigned availableLzs[] = {
48+
#ifdef _LZTURBO
49+
ICC_LZTURBO,
50+
#endif
51+
#ifdef _LZ4
52+
ICC_LZ4,
53+
#endif
54+
#ifdef _ZLIB
55+
ICC_ZLIB,
56+
#endif
57+
#ifdef _ZSTD
58+
ICC_ZSTD,
59+
#endif
60+
#ifdef _FSE
61+
ICC_FSE,
62+
#endif
63+
#ifdef _FSEHUF
64+
ICC_FSEH,
65+
#endif
66+
#ifdef _LZTURBO // _TURBOANX is enabled by _LZTURBO
67+
ICC_LZTANS,
68+
#endif
69+
#ifdef _TURBORC
70+
ICC_TURBORC,
71+
#endif
72+
ICC_MEMCPY,
73+
ICC_LAST
74+
};
75+
4776
char *_codstr[] = { "none", "lzturbo", "lz4", "zlib", "zstd", "fse", "fsehuf", "turboanx", "turborc", "memcpy", NULL };
4877
char *codstr(unsigned cid) { return (cid < ICC_LAST)?_codstr[cid]:""; }
4978

@@ -54,6 +83,8 @@ int lzidget(char *scmd) {
5483
if(!_codstr[i]) die("compressor '%s' not implemented\n", scmd);
5584
return i;
5685
}
86+
unsigned* getAvailableLzs() { return availableLzs; }
87+
5788
#ifdef _LZTURBO
5889
#define _TURBOANX
5990
#include "../lz/ans.h"

lib/include_/iccodec.h

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void tpmodeset(unsigned _tpmode);
108108
void tpsizeset(unsigned _tpsize);
109109
int lzidget(char *scmd);
110110
char *codstr(unsigned cid);
111+
unsigned* getAvailableLzs(); // ICC_LAST will be the last entry
111112

112113
#ifdef __cplusplus
113114
}

0 commit comments

Comments
 (0)