*/
#include "zbuild.h"
+#include "functable.h"
#include "deflate.h"
#include "deflate_p.h"
-#include "functable.h"
/* Avoid conflicts with zlib.h macros */
#ifdef ZLIB_COMPAT
copyright string in the executable of your product.
*/
-/* ===========================================================================
- * Architecture-specific hooks.
- */
-#ifdef S390_DFLTCC_DEFLATE
-# include "arch/s390/dfltcc_deflate.h"
-/* DFLTCC instructions require window to be page-aligned */
-# define PAD_WINDOW PAD_4096
-# define WINDOW_PAD_SIZE 4096
-# define HINT_ALIGNED_WINDOW HINT_ALIGNED_4096
-#else
-# define PAD_WINDOW PAD_64
-# define WINDOW_PAD_SIZE 64
-# define HINT_ALIGNED_WINDOW HINT_ALIGNED_64
-/* Adjust the window size for the arch-specific deflate code. */
-# define DEFLATE_ADJUST_WINDOW_SIZE(n) (n)
-/* Invoked at the beginning of deflateSetDictionary(). Useful for checking arch-specific window data. */
-# define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
-/* Invoked at the beginning of deflateGetDictionary(). Useful for adjusting arch-specific window data. */
-# define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
-/* Invoked at the end of deflateResetKeep(). Useful for initializing arch-specific extension blocks. */
-# define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
-/* Invoked at the beginning of deflateParams(). Useful for updating arch-specific compression parameters. */
-# define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0)
-/* Returns whether the last deflate(flush) operation did everything it's supposed to do. */
-# define DEFLATE_DONE(strm, flush) 1
-/* Adjusts the upper bound on compressed data length based on compression parameters and uncompressed data length.
- * Useful when arch-specific deflation code behaves differently than regular zlib-ng algorithms. */
-# define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0)
-/* Returns whether an optimistic upper bound on compressed data length should *not* be used.
- * Useful when arch-specific deflation code behaves differently than regular zlib-ng algorithms. */
-# define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0
-/* Invoked for each deflate() call. Useful for plugging arch-specific deflation code. */
-# define DEFLATE_HOOK(strm, flush, bstate) 0
-/* Returns whether zlib-ng should compute a checksum. Set to 0 if arch-specific deflation code already does that. */
-# define DEFLATE_NEED_CHECKSUM(strm) 1
-/* Returns whether reproducibility parameter can be set to a given value. */
-# define DEFLATE_CAN_SET_REPRODUCIBLE(strm, reproducible) 1
-#endif
-
/* ===========================================================================
* Function prototypes.
*/
Z_INTERNAL block_state deflate_huff (deflate_state *s, int flush);
static void lm_set_level (deflate_state *s, int level);
static void lm_init (deflate_state *s);
-Z_INTERNAL unsigned read_buf (PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
+//Z_INTERNAL unsigned read_buf (PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
/* ===========================================================================
* Local data
* strm->next_out buffer and copying into it. (See also read_buf()).
*/
Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm) {
- uint32_t len;
- deflate_state *s = strm->state;
-
- zng_tr_flush_bits(s);
- len = MIN(s->pending, strm->avail_out);
- if (len == 0)
- return;
-
- Tracev((stderr, "[FLUSH]"));
- memcpy(strm->next_out, s->pending_out, len);
- strm->next_out += len;
- s->pending_out += len;
- strm->total_out += len;
- strm->avail_out -= len;
- s->pending -= len;
- if (s->pending == 0)
- s->pending_out = s->pending_buf;
+ flush_pending_inline(strm);
}
/* ===========================================================================
/* Flush as much pending output as possible */
if (s->pending != 0) {
- PREFIX(flush_pending)(strm);
+ flush_pending_inline(strm);
if (strm->avail_out == 0) {
/* Since avail_out is 0, deflate will be called again with
* more output space, but possibly with both pending and
s->status = BUSY_STATE;
/* Compression must start with an empty pending buffer */
- PREFIX(flush_pending)(strm);
+ flush_pending_inline(strm);
if (s->pending != 0) {
s->last_flush = -1;
return Z_OK;
if (s->wrap == 1)
put_uint32_msb(s, strm->adler);
}
- PREFIX(flush_pending)(strm);
+ flush_pending_inline(strm);
/* If avail_out is zero, the application will call deflate again
* to flush the rest.
*/
return Z_OK;
}
-/* ===========================================================================
- * Read a new buffer from the current input stream, update the adler32
- * and total number of bytes read. All deflate() input goes through
- * this function so some applications may wish to modify it to avoid
- * allocating a large strm->next_in buffer and copying from it.
- * (See also flush_pending()).
- */
-Z_INTERNAL unsigned PREFIX(read_buf)(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) {
- uint32_t len = MIN(strm->avail_in, size);
- if (len == 0)
- return 0;
-
- strm->avail_in -= len;
-
- if (!DEFLATE_NEED_CHECKSUM(strm)) {
- memcpy(buf, strm->next_in, len);
-#ifdef GZIP
- } else if (strm->state->wrap == 2) {
- FUNCTABLE_CALL(crc32_fold_copy)(&strm->state->crc_fold, buf, strm->next_in, len);
-#endif
- } else if (strm->state->wrap == 1) {
- strm->adler = FUNCTABLE_CALL(adler32_fold_copy)(strm->adler, buf, strm->next_in, len);
- } else {
- memcpy(buf, strm->next_in, len);
- }
- strm->next_in += len;
- strm->total_in += len;
-
- return len;
-}
-
/* ===========================================================================
* Set longest match variables based on level configuration
*/
# define sent_bits_align(s)
#endif
+/* ===========================================================================
+ * Architecture-specific hooks.
+ */
+#ifdef S390_DFLTCC_DEFLATE
+# include "arch/s390/dfltcc_deflate.h"
+/* DFLTCC instructions require window to be page-aligned */
+# define PAD_WINDOW PAD_4096
+# define WINDOW_PAD_SIZE 4096
+# define HINT_ALIGNED_WINDOW HINT_ALIGNED_4096
+#else
+# define PAD_WINDOW PAD_64
+# define WINDOW_PAD_SIZE 64
+# define HINT_ALIGNED_WINDOW HINT_ALIGNED_64
+/* Adjust the window size for the arch-specific deflate code. */
+# define DEFLATE_ADJUST_WINDOW_SIZE(n) (n)
+/* Invoked at the beginning of deflateSetDictionary(). Useful for checking arch-specific window data. */
+# define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
+/* Invoked at the beginning of deflateGetDictionary(). Useful for adjusting arch-specific window data. */
+# define DEFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
+/* Invoked at the end of deflateResetKeep(). Useful for initializing arch-specific extension blocks. */
+# define DEFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
+/* Invoked at the beginning of deflateParams(). Useful for updating arch-specific compression parameters. */
+# define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) do {} while (0)
+/* Returns whether the last deflate(flush) operation did everything it's supposed to do. */
+# define DEFLATE_DONE(strm, flush) 1
+/* Adjusts the upper bound on compressed data length based on compression parameters and uncompressed data length.
+ * Useful when arch-specific deflation code behaves differently than regular zlib-ng algorithms. */
+# define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen) do {} while (0)
+/* Returns whether an optimistic upper bound on compressed data length should *not* be used.
+ * Useful when arch-specific deflation code behaves differently than regular zlib-ng algorithms. */
+# define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) 0
+/* Invoked for each deflate() call. Useful for plugging arch-specific deflation code. */
+# define DEFLATE_HOOK(strm, flush, bstate) 0
+/* Returns whether zlib-ng should compute a checksum. Set to 0 if arch-specific deflation code already does that. */
+# define DEFLATE_NEED_CHECKSUM(strm) 1
+/* Returns whether reproducibility parameter can be set to a given value. */
+# define DEFLATE_CAN_SET_REPRODUCIBLE(strm, reproducible) 1
+#endif
+
#endif /* DEFLATE_H_ */
#ifndef DEFLATE_P_H
#define DEFLATE_P_H
+#include "functable.h"
+
/* Forward declare common non-inlined functions declared in deflate.c */
#ifdef ZLIB_DEBUG
#endif
Z_INTERNAL void PREFIX(flush_pending)(PREFIX3(stream) *strm);
-Z_INTERNAL unsigned PREFIX(read_buf)(PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
+//Z_INTERNAL unsigned PREFIX(read_buf)(PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
/* ===========================================================================
* Save the match info and tally the frequency counts. Return true if
/* Match function. Returns the longest match. */
typedef uint32_t (*match_func) (deflate_state *const s, Pos cur_match);
+
+/* =========================================================================
+ * Flush as much pending output as possible. All deflate() output, except for
+ * some deflate_stored() output, goes through this function so some
+ * applications may wish to modify it to avoid allocating a large
+ * strm->next_out buffer and copying into it. (See also read_buf()).
+ */
+static inline void flush_pending_inline(PREFIX3(stream) *strm) {
+ uint32_t len;
+ deflate_state *s = strm->state;
+
+ zng_tr_flush_bits(s);
+ len = MIN(s->pending, strm->avail_out);
+ if (len == 0)
+ return;
+
+ Tracev((stderr, "[FLUSH]"));
+ memcpy(strm->next_out, s->pending_out, len);
+ strm->next_out += len;
+ s->pending_out += len;
+ strm->total_out += len;
+ strm->avail_out -= len;
+ s->pending -= len;
+ if (s->pending == 0)
+ s->pending_out = s->pending_buf;
+}
+
+static inline unsigned PREFIX(read_buf)(PREFIX3(stream) *strm, unsigned char *buf, unsigned size) {
+ uint32_t len = MIN(strm->avail_in, size);
+ if (len == 0)
+ return 0;
+
+ strm->avail_in -= len;
+
+ if (!DEFLATE_NEED_CHECKSUM(strm)) {
+ memcpy(buf, strm->next_in, len);
+#ifdef GZIP
+ } else if (strm->state->wrap == 2) {
+ FUNCTABLE_CALL(crc32_fold_copy)(&strm->state->crc_fold, buf, strm->next_in, len);
+#endif
+ } else if (strm->state->wrap == 1) {
+ strm->adler = FUNCTABLE_CALL(adler32_fold_copy)(strm->adler, buf, strm->next_in, len);
+ } else {
+ memcpy(buf, strm->next_in, len);
+ }
+ strm->next_in += len;
+ strm->total_in += len;
+
+ return len;
+}
+
+
#endif