Skip to content
Permalink
Browse files

lib/lzo: Optimize code for CPUs with inefficient unaligned access

Some code paths are only benefical on machines with fast unaligned
loads, so only use these if CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
defined.

Signed-off-by: Markus F.X.J. Oberhumer <markus@oberhumer.com>
  • Loading branch information
markus-oberhumer committed Aug 21, 2012
1 parent 10f6781 commit 5f702781f158cb59075cfa97e5c21f52275057f1
Showing with 15 additions and 6 deletions.
  1. +2 −2 lib/lzo/lzo1x_compress.c
  2. +12 −3 lib/lzo/lzo1x_decompress_safe.c
  3. +1 −1 lib/lzo/lzodefs.h
@@ -90,7 +90,7 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len,

m_len = 4;
{
#if defined(LZO_USE_CTZ64)
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(LZO_USE_CTZ64)
u64 v;
v = get_unaligned((const u64 *) (ip + m_len)) ^
get_unaligned((const u64 *) (m_pos + m_len));
@@ -110,7 +110,7 @@ lzo1x_1_do_compress(const unsigned char *in, size_t in_len,
# else
# error "missing endian definition"
# endif
#elif defined(LZO_USE_CTZ32)
#elif defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) && defined(LZO_USE_CTZ32)
u32 v;
v = get_unaligned((const u32 *) (ip + m_len)) ^
get_unaligned((const u32 *) (m_pos + m_len));
@@ -64,6 +64,7 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
}
t += 3;
copy_literal_run:
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
if (likely(HAVE_IP(t + 15) && HAVE_OP(t + 15))) {
const unsigned char *ie = ip + t;
unsigned char *oe = op + t;
@@ -77,7 +78,9 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
} while (ip < ie);
ip = ie;
op = oe;
} else {
} else
#endif
{
NEED_OP(t);
NEED_IP(t + 3);
do {
@@ -148,6 +151,7 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
m_pos -= 0x4000;
}
TEST_LB(m_pos);
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
if (op - m_pos >= 8) {
unsigned char *oe = op + t;
if (likely(HAVE_OP(t + 15))) {
@@ -173,7 +177,9 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
*op++ = *m_pos++;
} while (op < oe);
}
} else {
} else
#endif
{
unsigned char *oe = op + t;
NEED_OP(t);
op[0] = m_pos[0];
@@ -187,11 +193,14 @@ int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
match_next:
state = next;
t = next;
#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
if (likely(HAVE_IP(6) && HAVE_OP(4))) {
COPY4(op, ip);
op += t;
ip += t;
} else {
} else
#endif
{
NEED_IP(t + 3);
NEED_OP(t);
while (t > 0) {
@@ -29,7 +29,7 @@
#define LZO_USE_CTZ32 1
#elif defined(__i386__) || defined(__powerpc__)
#define LZO_USE_CTZ32 1
#else
#elif defined(__arm__) && (__LINUX_ARM_ARCH__ >= 5)
#define LZO_USE_CTZ32 1
#endif

0 comments on commit 5f70278

Please sign in to comment.
You can’t perform that action at this time.