aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2008-03-22 14:39:34 +0200
committerLasse Collin <lasse.collin@tukaani.org>2008-03-22 14:39:34 +0200
commitad999efd279d95f1e7ac555b14170e8e9020488c (patch)
treecdce2697597ab1e52511ff336fe3819840a821c8
parentAdded autoconf check to detect if we can use arithmetic (diff)
downloadxz-ad999efd279d95f1e7ac555b14170e8e9020488c.tar.xz
Take advantage of arithmetic right shift in range decoder.
Diffstat (limited to '')
-rw-r--r--src/liblzma/rangecoder/range_decoder.h52
1 files changed, 37 insertions, 15 deletions
diff --git a/src/liblzma/rangecoder/range_decoder.h b/src/liblzma/rangecoder/range_decoder.h
index f3dcc84e..a6a92b0b 100644
--- a/src/liblzma/rangecoder/range_decoder.h
+++ b/src/liblzma/rangecoder/range_decoder.h
@@ -121,14 +121,26 @@ do { \
} while (0)
-#define rc_decode_direct(dest, count) \
-do { \
- rc_normalize(); \
- rc.range >>= 1; \
- rc_bound = (rc.code - rc.range) >> 31; \
- rc.code -= rc.range & (rc_bound - 1); \
- dest = ((dest) << 1) | (1 - rc_bound);\
-} while (--count > 0)
+#ifdef HAVE_ARITHMETIC_RSHIFT
+# define rc_decode_direct(dest, count) \
+ do { \
+ rc_normalize(); \
+ rc.range >>= 1; \
+ rc.code -= rc.range; \
+ rc_bound = (uint32_t)((int32_t)(rc.code) >> 31); \
+ dest = (dest << 1) + (rc_bound + 1); \
+ rc.code += rc.range & rc_bound; \
+ } while (--count > 0)
+#else
+# define rc_decode_direct(dest, count) \
+ do { \
+ rc_normalize(); \
+ rc.range >>= 1; \
+ rc_bound = (rc.code - rc.range) >> 31; \
+ rc.code -= rc.range & (rc_bound - 1); \
+ dest = ((dest) << 1) | (1 - rc_bound);\
+ } while (--count > 0)
+#endif
// Dummy versions don't update prob or dest.
@@ -143,13 +155,23 @@ do { \
} while (0)
-#define rc_decode_direct_dummy(count) \
-do { \
- rc_normalize(); \
- rc.range >>= 1; \
- rc_bound = (rc.code - rc.range) >> 31; \
- rc.code -= rc.range & (rc_bound - 1); \
-} while (--count > 0)
+#ifdef HAVE_ARITHMETIC_RSHIFT
+# define rc_decode_direct_dummy(count) \
+ do { \
+ rc_normalize(); \
+ rc.range >>= 1; \
+ rc.code -= rc.range; \
+ rc.code += rc.range & ((uint32_t)((int32_t)(rc.code) >> 31)); \
+ } while (--count > 0)
+#else
+# define rc_decode_direct_dummy(count) \
+ do { \
+ rc_normalize(); \
+ rc.range >>= 1; \
+ rc_bound = (rc.code - rc.range) >> 31; \
+ rc.code -= rc.range & (rc_bound - 1); \
+ } while (--count > 0)
+#endif
///////////////////////