DEBUG_PRINTF("sub %u: selected %s model for %s repeat\n", i,
repeatTypeName(rtype), pr.bounds.str().c_str());
- u32 subScratchStateSize;
- u32 subStreamStateSize;
-
SubCastle &sub = subs[i];
RepeatInfo &info = infos[i];
- // handle exclusive case differently
+ info.packedCtrlSize = rsi.packedCtrlSize;
+ u32 subStreamStateSize = verify_u32(rsi.packedCtrlSize + rsi.stateSize);
+
+ // Handle stream/scratch space alloc for exclusive case differently.
if (contains(groupId, i)) {
u32 id = groupId.at(i);
- maxStreamSize[id] = MAX(maxStreamSize[id], rsi.packedCtrlSize);
+ maxStreamSize[id] = max(maxStreamSize[id], subStreamStateSize);
+ // SubCastle full/stream state offsets are written in for the group
+ // below.
} else {
- subScratchStateSize = verify_u32(sizeof(RepeatControl));
- subStreamStateSize = verify_u32(rsi.packedCtrlSize + rsi.stateSize);
-
- info.packedCtrlSize = rsi.packedCtrlSize;
sub.fullStateOffset = scratchStateSize;
sub.streamStateOffset = streamStateSize;
-
- scratchStateSize += subScratchStateSize;
+ scratchStateSize += verify_u32(sizeof(RepeatControl));
streamStateSize += subStreamStateSize;
}
u32 top = j.first;
u32 id = j.second;
SubCastle &sub = subs[top];
- RepeatInfo &info = infos[top];
- info.packedCtrlSize = maxStreamSize[id];
if (!scratchOffset[id]) {
sub.fullStateOffset = scratchStateSize;
sub.streamStateOffset = streamStateSize;
/*
- * Copyright (c) 2015, Intel Corporation
+ * Copyright (c) 2015-2016, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
return REPEAT_NOMATCH;
}
+/** \brief True if the given value can be packed into len bytes. */
+static really_inline
+int fits_in_len_bytes(u64a val, u32 len) {
+ if (len >= 8) {
+ return 1;
+ }
+ return val <= (1ULL << (len * 8));
+}
+
static really_inline
void storePackedRelative(char *dest, u64a val, u64a offset, u64a max, u32 len) {
assert(val <= offset);
- assert(max < (1ULL << (8 * len)));
+ assert(fits_in_len_bytes(max, len));
u64a delta = offset - val;
if (delta >= max) {
delta = max;
}
DEBUG_PRINTF("delta %llu\n", delta);
+ assert(fits_in_len_bytes(delta, len));
partial_store_u64a(dest, delta, len);
}
DEBUG_PRINTF("packing %llu into %u bytes\n", bitmap, info->packedCtrlSize);
// Write out packed bitmap.
+ assert(fits_in_len_bytes(bitmap, info->packedCtrlSize));
partial_store_u64a(dest, bitmap, info->packedCtrlSize);
}
DEBUG_PRINTF("xs->first:%u xs->last:%u patch:%u\n",
xs->first, xs->last, patch);
DEBUG_PRINTF("value:%llu\n", val);
+ assert(fits_in_len_bytes(val, encoding_size));
partial_store_u64a(ring + encoding_size * idx, val, encoding_size);
mmbit_set(active, patch_count, idx);
}