diff options
author | Erik Hallnor <ehallnor@umich.edu> | 2004-03-24 04:41:19 -0500 |
---|---|---|
committer | Erik Hallnor <ehallnor@umich.edu> | 2004-03-24 04:41:19 -0500 |
commit | 81882c0d10ee7a29181eea89ab56953049c86e00 (patch) | |
tree | a6ab3ef99222cb5055eb79c5e16d6298db549866 /base/compression/lzss_compression.cc | |
parent | b18a36a6f2034db838d3a8013a460b7f59c802a4 (diff) | |
download | gem5-81882c0d10ee7a29181eea89ab56953049c86e00.tar.xz |
A few memory system performance enhancements.
base/compression/lzss_compression.cc:
base/compression/lzss_compression.hh:
Rework for better performance
--HG--
extra : convert_revision : b13d706e0e23cbe7122b611258354c66cf5f3c70
Diffstat (limited to 'base/compression/lzss_compression.cc')
-rw-r--r-- | base/compression/lzss_compression.cc | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/base/compression/lzss_compression.cc b/base/compression/lzss_compression.cc index 8f235b808..2f6c5d338 100644 --- a/base/compression/lzss_compression.cc +++ b/base/compression/lzss_compression.cc @@ -36,21 +36,32 @@ #include "base/misc.hh" //for fatal -int -LZSSCompression::findSubString(uint8_t *src, int front, int back, int size) +void +LZSSCompression::findSubString(uint8_t *src, int back, int size, uint16_t &L, + uint16_t &P) { - int subSize = 0; - int max_length = 2048; - if (size - back < max_length) { - max_length = size - back; - } - for (int i = 0; i < max_length; ++i) { - if (src[front+i] != src[back+i]) { - return subSize; + int front = 0; + int max_length = size - back; + L = 0; + P = back - 1; + while (front < back) { + while (src[front] != src[back] && front < back) ++front; + if (front >= back) { + return; + } + int i = 1; + while (src[front+i] == src[back+i] && i < max_length) ++i; + if (i >= L) { + L = i; + P = front; + } + if (src[front+i] != src[back+i-1]) { + // can't find a longer substring until past this point. + front += i; + } else { + ++front; } - ++subSize; } - return subSize; } int @@ -106,13 +117,7 @@ LZSSCompression::compress(uint8_t *dest, uint8_t *src, int size) ++i; continue; } - for (int j = 0; j < i; ++j) { - int sub_size = findSubString(src, j, i, size); - if (sub_size >= L) { - L = sub_size; - P = j; - } - } + findSubString(src, i, size, L, P); if (L > 1) { // Output the string reference emitString(&dest[dest_index], P, L); |