Clean Up TODOs and Comments

This commit is contained in:
W. Felix Handte 2019-08-14 17:11:16 -04:00
parent 2abe0145b1
commit ebd162194f
2 changed files with 31 additions and 29 deletions

View File

@ -51,11 +51,16 @@ size_t ZSTD_compressBound(size_t srcSize) {
/** /**
* Align must be a power of 2. * Align must be a power of 2.
*/ */
static size_t ZSTD_workspace_align(size_t size, size_t align) { static size_t ZSTD_workspace_align(size_t size, size_t const align) {
return size + align - 1 - ((size - 1) & (align - 1)); size_t const mask = align - 1;
assert((align & mask) == 0);
return (size + mask) & ~mask;
} }
static void* ZSTD_workspace_reserve(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_workspace_alloc_phase_e phase) { /**
* Internal function, use wrappers instead.
*/
static void* ZSTD_workspace_reserve_internal(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_workspace_alloc_phase_e phase) {
/* TODO(felixh): alignment */ /* TODO(felixh): alignment */
void* alloc = (BYTE *)ws->allocStart - bytes; void* alloc = (BYTE *)ws->allocStart - bytes;
void* bottom = ws->tableEnd; void* bottom = ws->tableEnd;
@ -88,6 +93,21 @@ static void* ZSTD_workspace_reserve(ZSTD_CCtx_workspace* ws, size_t bytes, ZSTD_
return alloc; return alloc;
} }
/**
* Unaligned.
*/
static BYTE* ZSTD_workspace_reserve_buffer(ZSTD_CCtx_workspace* ws, size_t bytes) {
return (BYTE*)ZSTD_workspace_reserve_internal(ws, bytes, ZSTD_workspace_alloc_buffers);
}
/**
* Aligned on sizeof(unsigned).
*/
static void* ZSTD_workspace_reserve_aligned(ZSTD_CCtx_workspace* ws, size_t bytes) {
assert((bytes & (sizeof(U32)-1)) == 0); // TODO ???
return ZSTD_workspace_reserve_internal(ws, ZSTD_workspace_align(bytes, sizeof(U32)), ZSTD_workspace_alloc_aligned);
}
/** /**
* Aligned on sizeof(unsigned). These buffers have the special property that * Aligned on sizeof(unsigned). These buffers have the special property that
* their values remain constrained, allowing us to re-use them without * their values remain constrained, allowing us to re-use them without
@ -126,7 +146,8 @@ static void* ZSTD_workspace_reserve_object(ZSTD_CCtx_workspace* ws, size_t bytes
void* start = ws->objectEnd; void* start = ws->objectEnd;
void* end = (BYTE*)start + roundedBytes; void* end = (BYTE*)start + roundedBytes;
DEBUGLOG(3, "wksp: reserving %zd bytes object (rounded to %zd), %zd bytes remaining", bytes, roundedBytes, (BYTE *)ws->workspaceEnd - (BYTE *)end); DEBUGLOG(3, "wksp: reserving %zd bytes object (rounded to %zd), %zd bytes remaining", bytes, roundedBytes, (BYTE *)ws->workspaceEnd - (BYTE *)end);
assert((bytes & (sizeof(void*)-1)) == 0); // TODO ??? assert(((size_t)start & (sizeof(void*)-1)) == 0);
assert((bytes & (sizeof(void*)-1)) == 0);
if (ws->phase != ZSTD_workspace_alloc_objects || end > ws->workspaceEnd) { if (ws->phase != ZSTD_workspace_alloc_objects || end > ws->workspaceEnd) {
DEBUGLOG(3, "wksp: object alloc failed!"); DEBUGLOG(3, "wksp: object alloc failed!");
ws->allocFailed = 1; ws->allocFailed = 1;
@ -137,21 +158,6 @@ static void* ZSTD_workspace_reserve_object(ZSTD_CCtx_workspace* ws, size_t bytes
return start; return start;
} }
/**
* Aligned on sizeof(unsigned).
*/
static void* ZSTD_workspace_reserve_aligned(ZSTD_CCtx_workspace* ws, size_t bytes) {
assert((bytes & (sizeof(U32)-1)) == 0); // TODO ???
return ZSTD_workspace_reserve(ws, ZSTD_workspace_align(bytes, sizeof(U32)), ZSTD_workspace_alloc_aligned);
}
/**
* Unaligned.
*/
static BYTE* ZSTD_workspace_reserve_buffer(ZSTD_CCtx_workspace* ws, size_t bytes) {
return (BYTE*)ZSTD_workspace_reserve(ws, bytes, ZSTD_workspace_alloc_buffers);
}
// TODO // TODO
static int ZSTD_workspace_bump_oversized_duration(ZSTD_CCtx_workspace* ws) { static int ZSTD_workspace_bump_oversized_duration(ZSTD_CCtx_workspace* ws) {
(void)ws; (void)ws;
@ -185,11 +191,6 @@ static void ZSTD_workspace_clear(ZSTD_CCtx_workspace* ws) {
if (ws->phase > ZSTD_workspace_alloc_buffers) { if (ws->phase > ZSTD_workspace_alloc_buffers) {
ws->phase = ZSTD_workspace_alloc_buffers; ws->phase = ZSTD_workspace_alloc_buffers;
} }
// ws->table = NULL;
// ws->tableEnd = NULL;
// ws->bufferBegin = ws->workspaceEnd;
} }
static void ZSTD_workspace_init(ZSTD_CCtx_workspace* ws, void* start, size_t size) { static void ZSTD_workspace_init(ZSTD_CCtx_workspace* ws, void* start, size_t size) {
@ -1723,7 +1724,6 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
/* Statically sized space. /* Statically sized space.
* entropyWorkspace never moves, * entropyWorkspace never moves,
* though prev/next block swap places */ * though prev/next block swap places */
/* assert(((size_t)zc->workspace.workspace & 3) == 0); */ /* ensure correct alignment */ /* TODO(felixh): check elsewhere */
assert(ZSTD_workspace_check_available(&zc->workspace, 2 * sizeof(ZSTD_compressedBlockState_t))); assert(ZSTD_workspace_check_available(&zc->workspace, 2 * sizeof(ZSTD_compressedBlockState_t)));
zc->blockState.prevCBlock = (ZSTD_compressedBlockState_t*) ZSTD_workspace_reserve_object(&zc->workspace, sizeof(ZSTD_compressedBlockState_t)); zc->blockState.prevCBlock = (ZSTD_compressedBlockState_t*) ZSTD_workspace_reserve_object(&zc->workspace, sizeof(ZSTD_compressedBlockState_t));
RETURN_ERROR_IF(zc->blockState.prevCBlock == NULL, memory_allocation, "couldn't allocate prevCBlock"); RETURN_ERROR_IF(zc->blockState.prevCBlock == NULL, memory_allocation, "couldn't allocate prevCBlock");

View File

@ -273,7 +273,7 @@ typedef enum {
* Examples: * Examples:
* - Entropy Workspace * - Entropy Workspace
* - 2 x ZSTD_compressedBlockState_t * - 2 x ZSTD_compressedBlockState_t
* - CDict dictionary contents sometimes??? // TODO * - CDict dictionary contents
* *
* - Tables: these are any of several different datastructures (hash tables, * - Tables: these are any of several different datastructures (hash tables,
* chain tables, binary trees) that all respect a common format: they are * chain tables, binary trees) that all respect a common format: they are
@ -296,15 +296,17 @@ typedef enum {
* 2. Buffers * 2. Buffers
* 3. Aligned * 3. Aligned
* 4. Tables * 4. Tables
*
* Reusing Table Space:
*
* TODO(felixh): ...
*/ */
typedef struct { typedef struct {
void* workspace; void* workspace;
void* workspaceEnd; void* workspaceEnd;
void* objectEnd; void* objectEnd;
void* tableEnd; void* tableEnd;
void* allocStart; void* allocStart;
int allocFailed; int allocFailed;