From 36ed5d5a78a79fb2cc62bf974919ee071d685f62 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Thu, 5 Dec 2013 22:20:01 +0530 Subject: [PATCH] Use adapt2 as default compression in archive mode. Add more filter auto-selection by compression level in archive mode. Replace odd stride lengths in Delta2 with standard numeric type lengths and improve performance. --- Makefile.in | 2 +- filters/delta2/delta2.c | 7 ++++--- filters/dispack/dis.cpp | 19 +++++++++++++++++++ pcompress.c | 20 ++++++++++++++++++-- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Makefile.in b/Makefile.in index 59e17c8..88eaecd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -302,7 +302,7 @@ $(PJPGOBJS): $(PJPGSRCS) $(PJPGHDRS) $(VEC_FLAGS) -DBUILD_LIB $(COMMON_CPPFLAGS_cpp) $(@:.o=.cpp) -o $@ $(DISPACKOBJS): $(DISPACKSRCS) $(DISPACKHDRS) - $(COMPILE_cpp) $(COMMON_VEC_FLAGS) @SSE_OPT_FLAGS@ -O2 -fsched-spec-load \ + $(COMPILE_cpp) $(COMMON_VEC_FLAGS) $(DEBUG_STATS_CPPFLAGS) @SSE_OPT_FLAGS@ -O2 -fsched-spec-load \ -Wno-variadic-macros $(VEC_FLAGS) $(COMMON_CPPFLAGS_cpp) $(@:.o=.cpp) -o $@ $(SKEIN_BLOCK_OBJ): $(SKEIN_BLOCK_SRC) diff --git a/filters/delta2/delta2.c b/filters/delta2/delta2.c index 1bdcea8..9c9387f 100644 --- a/filters/delta2/delta2.c +++ b/filters/delta2/delta2.c @@ -91,10 +91,11 @@ /* * Stride values to be checked. As of this implementation strides only - * upto 8 bytes (uint64_t) are supported. + * upto 8 bytes (uint64_t) are supported and common type lengths only + * are checked. */ -#define NSTRIDES 4 -static uchar_t strides[NSTRIDES] = {3, 5, 7, 8}; +#define NSTRIDES 3 +static uchar_t strides[NSTRIDES] = {2, 4, 8}; static int delta2_encode_real(uchar_t *src, uint64_t srclen, uchar_t *dst, uint64_t *dstlen, diff --git a/filters/dispack/dis.cpp b/filters/dispack/dis.cpp index 3c66268..eb49b09 100644 --- a/filters/dispack/dis.cpp +++ b/filters/dispack/dis.cpp @@ -29,6 +29,9 @@ #include #include #include +#include + +using namespace std; /* Version history: * @@ -944,10 +947,16 @@ dispack_encode(uchar_t *from, uint64_t fromlen, uchar_t *to, uint64_t *dstlen) { uchar_t *pos, *hdr, type, *pos_to, *to_last; uint64_t len; +#ifdef DEBUG_STATS + double strt, en; +#endif if (fromlen < DISFILTER_BLOCK) return (-1); +#ifdef DEBUG_STATS + strt = get_wtime_millis(); +#endif pos = from; len = fromlen; pos_to = to; @@ -1009,9 +1018,19 @@ dispack_encode(uchar_t *from, uint64_t fromlen, uchar_t *to, uint64_t *dstlen) len -= sz; } *dstlen = pos_to - to; +#ifdef DEBUG_STATS + en = get_wtime_millis(); + cerr << "Dispack: Processed at " << get_mb_s(fromlen, strt, en) << " MB/s" << endl; +#endif if ((fromlen - *dstlen) < DIS_MIN_REDUCE) { +#ifdef DEBUG_STATS + cerr << "Dispack: Failed, reduction too less" << endl; +#endif return (-1); } +#ifdef DEBUG_STATS + cerr << "Dispack: srclen: " << fromlen << ", dstlen: " << *dstlen << endl; +#endif return (0); } diff --git a/pcompress.c b/pcompress.c index 724d661..2237fb5 100644 --- a/pcompress.c +++ b/pcompress.c @@ -2946,6 +2946,7 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[]) case 'a': pctx->archive_mode = 1; + pctx->do_compress = 1; break; case 'v': @@ -2978,6 +2979,19 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[]) return (2); } + if (pctx->archive_mode && pctx->do_uncompress) { + log_msg(LOG_ERR, 0, "'-a' flag is only for archive creation."); + return (1); + } + + /* + * Default compression algorithm during archiving is Adaptive2. + */ + if (pctx->archive_mode && pctx->algo == NULL) { + pctx->algo = "adapt2"; + init_algo(pctx, pctx->algo, 1); + } + if (pctx->level == -1 && pctx->do_compress) { if (memcmp(pctx->algo, "lz4", 3) == 0) { pctx->level = 1; @@ -3204,16 +3218,18 @@ init_pc_context(pc_ctx_t *pctx, int argc, char *argv[]) } /* - * Selectively enable filters while compressing. + * Selectively enable filters while archiving, depending on compression level. */ if (pctx->archive_mode) { struct filter_flags ff; ff.enable_packjpg = 0; - if (pctx->level > 9) ff.enable_packjpg = 1; + if (pctx->level > 10) ff.enable_packjpg = 1; init_filters(&ff); pctx->enable_packjpg = ff.enable_packjpg; if (pctx->level > 8) pctx->dispack_preprocess = 1; + if (pctx->level > 4) pctx->enable_delta2_encode = 1; + if (pctx->level > 9) pctx->lzp_preprocess = 1; } if (pctx->lzp_preprocess || pctx->enable_delta2_encode || pctx->dispack_preprocess) { pctx->preprocess_mode = 1;