@@ -1209,20 +1209,23 @@ void fpstat(unsigned char *in, size_t n, unsigned char *out, int s, unsigned cha
1209
1209
eamin = DBL_MAX , eamax = DBL_MIN , easum = 0 , easumsqr = 0 , //absolute error : abs(input-output)
1210
1210
ermin = DBL_MAX , ermax = DBL_MIN , ersum = 0 , ersumsqr = 0 , //relative error : abs(input-output)/abs(input)
1211
1211
osum = 0 ; //transformed lossy data (output) : sum
1212
- long long xtb = 0 , xlb = 0 , zlb = 0 , tb = 0 , lb = 0 , elb = 0 , mtb = 0 , itb = 0 ;
1212
+ long long xtb = 0 , xlb = 0 , zlb = 0 , tb = 0 , lb = 0 , elb = 0 , mtb = 0 , itb = 0 ;
1213
1213
size_t idn = 0 ;
1214
1214
unsigned char * ip , * op ;
1215
- unsigned esize = s < 0 ?- s :s ,t = 0 , dup = 0 ,zero = 0 ;
1215
+ unsigned esize = s < 0 ?- s :s , t = 0 , dup = 0 ,zero = 0 ;
1216
1216
long long mant = 0 ;
1217
1217
int expo = 0 ,e ;
1218
- unsigned char * tmp = _tmp ;
1219
- if (!tmp ) { tmp = malloc (n * esize ); if (!tmp ) die ("malloc failed\n" ); } memcpy (tmp , out , n * esize );
1220
- switch (esize ) {
1221
- case 2 : { uint16_t * p ,* t = tmp ; qsort (tmp , n , 2 , cmpua16 ); for (dup = 0 ,p = t ; p < t + n - 1 ; p ++ ) { if (p [0 ] == p [1 ]) dup ++ ; if (!p [0 ]) zero ++ ; } } break ;
1222
- case 4 : { uint32_t * p ,* t = tmp ; qsort (tmp , n , 4 , cmpua32 ); for (dup = 0 ,p = t ; p < t + n - 1 ; p ++ ) { if (p [0 ] == p [1 ]) dup ++ ; if (!p [0 ]) zero ++ ; } } break ;
1223
- case 8 : { uint64_t * p ,* t = tmp ; qsort (tmp , n , 8 , cmpua64 ); for (dup = 0 ,p = t ; p < t + n - 1 ; p ++ ) { if (p [0 ] == p [1 ]) dup ++ ; if (!p [0 ]) zero ++ ; } } break ;
1218
+ if (_tmp || verbose > 4 ) {
1219
+ unsigned char * tmp = _tmp ;
1220
+ if (!tmp ) { tmp = malloc (n * esize ); if (!tmp ) die ("malloc failed\n" ); } memcpy (tmp , out , n * esize );
1221
+ switch (esize ) {
1222
+ case 2 : { uint16_t * p ,* t = tmp ; qsort (tmp , n , 2 , cmpua16 ); for (dup = 0 ,p = t ; p < t + n - 1 ; p ++ ) { if (p [0 ] != p [1 ]) dup ++ ; if (!p [0 ]) zero ++ ; } } break ;
1223
+ case 4 : { uint32_t * p ,* t = tmp ; qsort (tmp , n , 4 , cmpua32 ); for (dup = 0 ,p = t ; p < t + n - 1 ; p ++ ) { if (p [0 ] != p [1 ]) dup ++ ; if (!p [0 ]) zero ++ ; } } break ;
1224
+ case 8 : { uint64_t * p ,* t = tmp ; qsort (tmp , n , 8 , cmpua64 ); for (dup = 0 ,p = t ; p < t + n - 1 ; p ++ ) { if (p [0 ] != p [1 ]) dup ++ ; if (!p [0 ]) zero ++ ; } } break ;
1225
+ default : die ("#fpstat" );
1226
+ }
1227
+ if (!_tmp ) free (tmp );
1224
1228
}
1225
- if (!_tmp ) free (tmp );
1226
1229
for (ip = in , op = out ; ip < in + n * esize ; ip += esize , op += esize )
1227
1230
switch (s ) {
1228
1231
#if defined(FLT16_BUILTIN )
@@ -1287,8 +1290,8 @@ void fpstat(unsigned char *in, size_t n, unsigned char *out, int s, unsigned cha
1287
1290
double mse = easumsqr /n , irange = imax - imin ;
1288
1291
if (verbose >= 2 ) printf ("\n" );
1289
1292
//printf("Leading/Trailing bits [%.2f%%,%.2f%%=%.2f%%]. XOR[%.2f%%,%.2f%%=%.2f%%] Zigzag[%.2f%%]\n", BR(lb), BR(tb), BR(lb+tb), BR(xlb), BR(xtb), BR(xlb+xtb), BR(zlb)/*BR(elb), BR(mtb), BR(elb+mtb)*/ );
1290
- if (verbose >= 2 ) printf ("Range: [min=%g / max=%g] = %g. zeros=% .2f%%, Duplicate=% .4f%% ctz=%.1f%%\n" , imin , imax , irange , ( double ) zero * 100.0 /( double ) n ,
1291
- (double )dup * 100.0 /(double )n , (double )((tb - itb )/8 )* 100.0 /(double )(n * esize ));
1293
+ if (verbose >= 2 ) printf ("Range: [min=%g / max=%g] = %g. zeros=[%u,% .2f%%], Distinct=[%u=% .4f%%] ctz=%.1f%%\n" , imin , imax , irange );
1294
+ if ( verbose > 3 || _tmp ) printf ( "zeros=[%u,%.2f%%], Distinct=[%u=%.4f%%] ctz=%.1f%%\n" , zero ,( double ) zero * 100.0 /( double ) n , dup , (double )dup * 100.0 /(double )n , (double )((tb - itb )/8 )* 100.0 /(double )(n * esize ));
1292
1295
//printf("Min error: Absolute = %.12f, Relative = %f, pointwise relative = %f\n", eamin, eamin/irange, eamax/irange, ermax);
1293
1296
//printf("Avg error: Absolute = %.12f, Relative = %f, pointwise relative = %f\n", easum/idn, (easum/idn)/irange, ersum/idn);
1294
1297
if (verbose > 2 ) printf ("Max error: Absolute = %g, Relative = %g, pointwise relative = %g\n" , eamax , eamax /irange , ermax ); else if (verbose == 2 ) printf ("e=%g " , ermax );
@@ -2115,7 +2118,7 @@ testrazor() {
2115
2118
}
2116
2119
#endif
2117
2120
int main (int argc , char * argv []) { //testrazor();
2118
- unsigned b = 1 << 31 , lz = 0 , fno ,m = 1000000 , bsize = (unsigned )-1 ;
2121
+ unsigned b = 1 << 31 , lz = 0 , fno ,m = 1000000 , bsize = (unsigned )-1 , quantb = 0 ;
2119
2122
int isize = 4 ,dfmt = 0 ,kid = 1 ,skiph = 0 ,decs = 0 ,divs = 1 ,dim0 = 0 ;
2120
2123
uint64_t be_mindelta = 0 ;
2121
2124
unsigned char * in = NULL , * out , * cpy ;
@@ -2130,10 +2133,11 @@ int main(int argc, char* argv[]) { //testrazor();
2130
2133
int c , digit_optind = 0 , this_option_optind = optind ? optind : 1 , option_index = 0 ;
2131
2134
static struct option long_options [] = { {"blocsize" , 0 , 0 , 'b' }, {0 , 0 , 0 } };
2132
2135
for (;;) {
2133
- 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:R:s:v:V:w:W:yz:" , long_options , & option_index )) == -1 ) break ;
2136
+ 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 ;
2134
2137
switch (c ) {
2135
2138
case 0 : printf ("Option %s" , long_options [option_index ].name ); if (optarg ) printf (" with arg %s" , optarg ); printf ("\n" ); break ;
2136
2139
case 'b' : bsize = argtoi (optarg ,1 ); break ;
2140
+ case 'B' : b = argtoi (optarg ,1 ); break ;
2137
2141
case 'C' : cmp = atoi (optarg ); break ;
2138
2142
case 'e' : icmd = optarg ; break ;
2139
2143
case 'E' : scmd = optarg ; break ;
@@ -2170,7 +2174,6 @@ int main(int argc, char* argv[]) { //testrazor();
2170
2174
case 'I' : if ((tm_Rep = atoi (optarg ))<=0 ) tm_rep = tm_Rep = 1 ; break ;
2171
2175
case 'J' : if ((tm_Rep2 = atoi (optarg ))<=0 ) tm_rep = tm_Rep2 = 1 ; break ;
2172
2176
case 's' : isize = argtoi (optarg ,1 ); break ;
2173
- case 'B' : b = argtoi (optarg ,1 ); break ;
2174
2177
//case 'c': cmp++; break;
2175
2178
case 'l' : codlev = atoi (optarg ); break ;
2176
2179
case 'y' : mcpy = 0 ; break ;
@@ -2181,6 +2184,7 @@ int main(int argc, char* argv[]) { //testrazor();
2181
2184
case 'm' : rm = argtoi (optarg ,1 ); break ;
2182
2185
case 'M' : rx = argtoi (optarg ,1 ); break ;
2183
2186
case 'p' : { unsigned m = atoi (optarg ); if (m == 4 || m == 8 ) tpmodeset (m );else die ("transpose mode (option -p) must be 4 or 8\n" ); } break ;
2187
+ case 'q' : quantb = atoi (optarg ); if (quantb < 8 ) quantb = 8 ; break ;
2184
2188
case 'f' : isize = - argtoi (optarg ,1 ); break ;
2185
2189
case 'R' : { char * p ; nx = strtoul (optarg , & p , 10 ); if (!nx ) dim0 ++ ;
2186
2190
if (* p ) ny = strtoul (p + 1 , & p , 10 );
@@ -2279,24 +2283,36 @@ int main(int argc, char* argv[]) { //testrazor();
2279
2283
2280
2284
//if(fno == optind)
2281
2285
tm_init (tm_Rep , tm_verbose /* 2 print id */ );
2282
-
2283
- if (errlim > DBL_EPSILON /*|| nsd >= 0*/ ) { // convert input for lossy floating point compression
2284
- if (errlim < 0.0000009999 ) errlim = 0.000001 ;
2285
- if (isize == -4 ) { printf ("Lossy compression float32\n" );
2286
- fprazor32 (in ,n /4 ,out ,errlim ); if (verbose > 0 ) fpstat (in , n /4 , out , -4 , NULL ); //if(nsd >= 0) fprnd32(in,n/4,out,nsd); else //
2287
- fprazor32 (in ,n /4 , in ,errlim ); /*if(nsd >= 0) fprnd32(in,n/4,in, nsd); else */
2288
- } else if (isize == -8 ) { printf ("Lossy compression float64\n" );
2289
- fprazor64 (in ,n /8 ,out ,errlim ); if (verbose > 0 ) fpstat (in , n /8 , out , -8 , NULL ); /*if(nsd>=0) fprnd64(in,n/8,out,nsd); else*/
2290
- fprazor64 (in ,n /8 , in ,errlim ); /*if(nsd>=0) fprnd64(in,n/8, in,nsd); else*/
2291
- }
2292
- #if defined(FLT16_BUILTIN )
2293
- else if (isize == -2 ) { printf ("Lossy compression float16\n" );
2294
- fprazor16 (in ,n /2 ,out ,errlim ); if (verbose > 0 ) fpstat (in , n /2 , out , -2 , NULL ); /*if(nsd>=0) fprnd64(in,n/8,out,nsd); else*/
2295
- fprazor16 (in ,n /2 , in ,errlim ); /*if(nsd>=0) fprnd64(in,n/8, in,nsd); else*/
2296
- }
2297
- #endif
2298
- }
2299
- be_mindelta = mindelta (in , n /abs (isize ), abs (isize ));
2286
+
2287
+ if (errlim > DBL_EPSILON /*|| nsd >= 0*/ ) { // convert input for lossy floating point compression
2288
+ if (errlim > DBL_EPSILON && errlim < 0.0000009999 ) errlim = 0.000001 ; if (verbose > 0 ) printf ("Lossy compression float\n" );
2289
+ if (isize == -4 ) fprazor32 (in ,n /4 ,out ,errlim );
2290
+ else if (isize == -8 ) fprazor64 (in ,n /8 ,out ,errlim );
2291
+ #if defined(FLT16_BUILTIN )
2292
+ else if (isize == -2 ) fprazor16 (in ,n /2 ,out ,errlim );
2293
+ #endif
2294
+ if (verbose > 0 ) fpstat (in , n /abs (isize ), out , isize , cpy ); memcpy (in ,out ,n );
2295
+ } else if (isize < 0 && quantb > 0 ) { if (verbose > 0 ) printf ("Quantization=%d float\n" , quantb );
2296
+ if (isize == -4 ) {
2297
+ float fmin ,fmax ;
2298
+ if (quantb > 32 ) quantb = 32 ;
2299
+ fpquant32e32 (in , n /4 , out , quantb , & fmin , & fmax ); if (verbose > 0 ) fpquant32d32 (out , n /4 , cpy , quantb , fmin , fmax );
2300
+ } else if (isize == -8 ) {
2301
+ double fmin ,fmax ;
2302
+ if (quantb > 32 ) quantb = 32 ;
2303
+ fpquant64e64 (in , n /8 , out , quantb , & fmin , & fmax ); if (verbose > 0 ) fpquant64d64 (out ,n /8 ,cpy , quantb , fmin , fmax );
2304
+ }
2305
+ #if defined(FLT16_BUILTIN )
2306
+ else if (isize == -2 ) { _Float16 fmin ,fmax ;
2307
+ if (quantb > 16 ) quantb = 16 ;
2308
+ fpquant16e16 (in ,n /2 ,out , quantb , & fmin , & fmax ); if (verbose > 0 ) { printf ("Range=[%g-%g]=%g " , (double )fmin , (double )fmax , (double )fmax - (double )fmin );
2309
+ fpquant16d16 (out ,n /2 ,cpy , quantb , fmin , fmax );
2310
+ }
2311
+ }
2312
+ #endif
2313
+ if (verbose > 0 ) fpstat (in , n /abs (isize ), cpy , isize , NULL ); memcpy (in , out , n );
2314
+ }
2315
+ be_mindelta = mindelta (in , n /abs (isize ), abs (isize ));
2300
2316
2301
2317
if (fi && verbose > 1 ) {
2302
2318
unsigned l ; // Calculate bits distributions
0 commit comments