Skip to content

Commit

Permalink
Adapt DFLTCC code to the new memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
iii-i committed May 21, 2024
1 parent 50b2ff2 commit 0578415
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 78 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,6 @@ if(WITH_OPTIM)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/s390_features.c)
endif()
endif()
if(WITH_DFLTCC_DEFLATE OR WITH_DFLTCC_INFLATE)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/dfltcc_common.c)
endif()
if(WITH_DFLTCC_DEFLATE)
add_definitions(-DS390_DFLTCC_DEFLATE)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/dfltcc_deflate.c)
Expand Down
6 changes: 0 additions & 6 deletions arch/s390/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ s390_features.o:
s390_features.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/s390_features.c

dfltcc_common.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_common.c

dfltcc_common.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_common.c

dfltcc_deflate.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_deflate.c

Expand Down
7 changes: 4 additions & 3 deletions arch/s390/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ integrated with the rest of zlib-ng using hook macros.

DFLTCC takes as arguments a parameter block, an input buffer, an output
buffer, and a window. Parameter blocks are stored alongside zlib states;
buffers are forwarded from the caller; and window (which must be page-aligned)
is managed using `ZALLOC_WINDOW()`, `ZCOPY_WINDOW()` and `TRY_FREE_WINDOW()`
macros.
buffers are forwarded from the caller; and window - which must be
4k-aligned and is always 64k large, is managed using the `PAD_WINDOW()`,
`WINDOW_PAD_SIZE`, `HINT_ALIGNED_WINDOW` and `DEFLATE_ADJUST_WINDOW_SIZE()`
and `INFLATE_ADJUST_WINDOW_SIZE()` hooks.

Software and hardware window formats do not match, therefore,
`deflateSetDictionary()`, `deflateGetDictionary()`, `inflateSetDictionary()`
Expand Down
40 changes: 0 additions & 40 deletions arch/s390/dfltcc_common.c

This file was deleted.

19 changes: 8 additions & 11 deletions arch/s390/dfltcc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,15 @@ typedef struct {
struct dfltcc_state common;
} arch_inflate_state;

void Z_INTERNAL *PREFIX(dfltcc_alloc_window)(PREFIX3(streamp) strm, uInt items, uInt size);
void Z_INTERNAL PREFIX(dfltcc_copy_window)(void *dest, const void *src, size_t n);
void Z_INTERNAL PREFIX(dfltcc_free_window)(PREFIX3(streamp) strm, void *w);

#define ZALLOC_WINDOW PREFIX(dfltcc_alloc_window)

#define ZCOPY_WINDOW PREFIX(dfltcc_copy_window)

#define ZFREE_WINDOW PREFIX(dfltcc_free_window)

#define TRY_FREE_WINDOW PREFIX(dfltcc_free_window)
/*
History buffer size.
*/
#define HB_BITS 15
#define HB_SIZE (1 << HB_BITS)

/*
Sizes of deflate block parts.
*/
#define DFLTCC_BLOCK_HEADER_BITS 3
#define DFLTCC_HLITS_COUNT_BITS 5
#define DFLTCC_HDISTS_COUNT_BITS 5
Expand Down
2 changes: 2 additions & 0 deletions arch/s390/dfltcc_deflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ int Z_INTERNAL PREFIX(dfltcc_deflate_get_dictionary)(PREFIX3(streamp) strm, unsi

#define DEFLATE_CAN_SET_REPRODUCIBLE PREFIX(dfltcc_can_set_reproducible)

#define DEFLATE_ADJUST_WINDOW_SIZE(n) MAX(n, HB_SIZE)

#endif
2 changes: 0 additions & 2 deletions arch/s390/dfltcc_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ typedef enum {
#define DFLTCC_XPND 4
#define HBT_CIRCULAR (1 << 7)
#define DFLTCC_FN_MASK ((1 << 7) - 1)
#define HB_BITS 15
#define HB_SIZE (1 << HB_BITS)

/* Return lengths of high (starting at param->ho) and low (starting at 0) fragments of the circular history buffer. */
static inline void get_history_lengths(struct dfltcc_param_v0 *param, size_t *hl_high, size_t *hl_low) {
Expand Down
2 changes: 2 additions & 0 deletions arch/s390/dfltcc_inflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ int Z_INTERNAL PREFIX(dfltcc_inflate_get_dictionary)(PREFIX3(streamp) strm,
return PREFIX(dfltcc_inflate_get_dictionary)((strm), (dict), (dict_len)); \
} while (0)

#define INFLATE_ADJUST_WINDOW_SIZE(n) MAX(n, HB_SIZE)

#endif
5 changes: 0 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1832,11 +1832,6 @@ EOF
ARCH_SHARED_OBJS="${ARCH_SHARED_OBJS} s390_features.lo"
fi

if test $builddfltccdeflate -eq 1 -o $builddfltccinflate -eq 1; then
ARCH_STATIC_OBJS="${ARCH_STATIC_OBJS} dfltcc_common.o"
ARCH_SHARED_OBJS="${ARCH_SHARED_OBJS} dfltcc_common.lo"
fi

if test $builddfltccdeflate -eq 1; then
CFLAGS="${CFLAGS} -DS390_DFLTCC_DEFLATE"
SFLAGS="${SFLAGS} -DS390_DFLTCC_DEFLATE"
Expand Down
8 changes: 5 additions & 3 deletions deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ const char PREFIX(deflate_copyright)[] = " deflate 1.3.1 Copyright 1995-2024 Jea
# 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
/* Adjust the window size for the arch-specific deflate code. */
# define DEFLATE_ADJUST_WINDOW_SIZE(n) (n)
#endif

/* ===========================================================================
Expand Down Expand Up @@ -201,15 +203,15 @@ Z_INTERNAL deflate_allocs* alloc_deflate(PREFIX3(stream) *strm, int windowBits,
int curr_size = 0;

/* Define sizes */
int window_size = (1 << windowBits) * 2;
int window_size = DEFLATE_ADJUST_WINDOW_SIZE((1 << windowBits) * 2);
int prev_size = (1 << windowBits) * sizeof(Pos);
int head_size = HASH_SIZE * sizeof(Pos);
int pending_size = lit_bufsize * LIT_BUFS;
int state_size = sizeof(deflate_state);
int alloc_size = sizeof(deflate_allocs);

/* Calculate relative buffer positions and paddings */
LOGSZP("window", window_size, PAD_WINDOW(curr_size), PADSZ(curr_size,WINDOW_PAD_SIZE));
LOGSZP("window", window_size, PAD_WINDOW(curr_size), PADSZ(curr_size, WINDOW_PAD_SIZE));
int window_pos = PAD_WINDOW(curr_size);
curr_size = window_pos + window_size;

Expand Down Expand Up @@ -1158,7 +1160,7 @@ int32_t Z_EXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
return Z_MEM_ERROR;
}

memcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(unsigned char));
memcpy(ds->window, ss->window, DEFLATE_ADJUST_WINDOW_SIZE(ds->w_size * 2 * sizeof(unsigned char)));
memcpy((void *)ds->prev, (void *)ss->prev, ds->w_size * sizeof(Pos));
memcpy((void *)ds->head, (void *)ss->head, HASH_SIZE * sizeof(Pos));
memcpy(ds->pending_buf, ss->pending_buf, ds->lit_bufsize * LIT_BUFS);
Expand Down
6 changes: 3 additions & 3 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ Z_INTERNAL inflate_allocs* alloc_inflate(PREFIX3(stream) *strm) {
int curr_size = 0;

/* Define sizes */
int window_size = (1 << MAX_WBITS) + 64; /* 64B padding for chunksize */
int window_size = INFLATE_ADJUST_WINDOW_SIZE((1 << MAX_WBITS) + 64); /* 64B padding for chunksize */
int state_size = sizeof(inflate_state);
int alloc_size = sizeof(inflate_allocs);

/* Calculate relative buffer positions and paddings */
LOGSZP("window", window_size, PAD_WINDOW(curr_size), PADSZ(curr_size,WINDOW_PAD_SIZE));
LOGSZP("window", window_size, PAD_WINDOW(curr_size), PADSZ(curr_size, WINDOW_PAD_SIZE));
int window_pos = PAD_WINDOW(curr_size);
curr_size = window_pos + window_size;

Expand Down Expand Up @@ -1418,7 +1418,7 @@ int32_t Z_EXPORT PREFIX(inflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
copy->window = alloc_bufs->window;

/* window */
ZCOPY_WINDOW(copy->window, state->window, (size_t)state->wsize);
memcpy(copy->window, state->window, INFLATE_ADJUST_WINDOW_SIZE((size_t)state->wsize));

dest->state = (struct internal_state *)copy;
return Z_OK;
Expand Down
4 changes: 2 additions & 2 deletions inflate_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
# define PAD_WINDOW PAD_64
# define WINDOW_PAD_SIZE 64
# define HINT_ALIGNED_WINDOW HINT_ALIGNED_64
/* Memory management for the window. Useful for allocation the aligned window. */
# define ZCOPY_WINDOW(dest, src, n) memcpy(dest, src, n)
/* Invoked at the end of inflateResetKeep(). Useful for initializing arch-specific extension blocks. */
# define INFLATE_RESET_KEEP_HOOK(strm) do {} while (0)
/* Invoked at the beginning of inflatePrime(). Useful for updating arch-specific buffers. */
Expand All @@ -38,6 +36,8 @@
# define INFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
/* Invoked at the beginning of inflateGetDictionary(). Useful for adjusting arch-specific window data. */
# define INFLATE_GET_DICTIONARY_HOOK(strm, dict, dict_len) do {} while (0)
/* Adjust the window size for the arch-specific inflate code. */
# define INFLATE_ADJUST_WINDOW_SIZE(n) (n)
#endif

/*
Expand Down

0 comments on commit 0578415

Please sign in to comment.