From: David Flynn <[EMAIL PROTECTED]>
Instead of reseting the counter to zero and testing if it is 8,
set counter to 8; decrement and test if zero. This should eliminate
an instruction.
TODO: it is worth investigating if using the dec instruction is
better in this case than using the compiler generated sub $1,%0;
test %0, %0; jcc ...; The dec instruction partially updates the
registers -- may cause flags stall.
Signed-off-by: David Flynn <[EMAIL PROTECTED]>
---
schroedinger/schroarith.c | 15 ++++++---------
schroedinger/schroarith.h | 8 +++-----
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/schroedinger/schroarith.c b/schroedinger/schroarith.c
index 5d3ead4..793c232 100644
--- a/schroedinger/schroarith.c
+++ b/schroedinger/schroarith.c
@@ -147,6 +147,7 @@ schro_arith_decode_init (SchroArith *arith, SchroBuffer
*buffer)
arith->range[1] = 0xffff;
arith->range_size = arith->range[1] - arith->range[0];
arith->code = 0;
+ arith->cntr = 8;
arith->buffer = buffer;
@@ -207,7 +208,7 @@ schro_arith_estimate_init (SchroArith *arith)
void
schro_arith_decode_flush (SchroArith *arith)
{
- if (arith->cntr > 0) {
+ if (arith->cntr < 8) {
arith->offset++;
}
}
@@ -300,9 +301,7 @@ __schro_arith_decode_bit (SchroArith *arith, int i)
arith->code <<= 1;
arith->code |= arith->shift >> (7-arith->cntr)&1;
- arith->cntr++;
-
- if (arith->cntr == 8) {
+ if (!--arith->cntr) {
arith->offset++;
if (arith->offset < arith->buffer->length) {
arith->shift = arith->dataptr[arith->offset];
@@ -315,7 +314,7 @@ __schro_arith_decode_bit (SchroArith *arith, int i)
if (arith->code < arith->range[0]) {
arith->code |= (1<<16);
}
- arith->cntr = 0;
+ arith->cntr = 8;
}
}
@@ -353,9 +352,7 @@ __schro_arith_decode_bit (SchroArith *arith, int i)
arith->code <<= 1;
arith->code |= (arith->dataptr[arith->offset] >> (7-arith->cntr))&1;
- arith->cntr++;
-
- if (arith->cntr == 8) {
+ if (!--arith->cntr) {
arith->offset++;
arith->range[0] &= 0xffff;
arith->code &= 0xffff;
@@ -363,7 +360,7 @@ __schro_arith_decode_bit (SchroArith *arith, int i)
if (arith->code < arith->range[0]) {
arith->code |= (1<<16);
}
- arith->cntr = 0;
+ arith->cntr = 8;
}
}
diff --git a/schroedinger/schroarith.h b/schroedinger/schroarith.h
index 58ed48b..4af41fe 100644
--- a/schroedinger/schroarith.h
+++ b/schroedinger/schroarith.h
@@ -175,11 +175,9 @@ _schro_arith_decode_bit (SchroArith *arith, int i)
arith->range[1] <<= 1;
arith->code <<= 1;
- arith->code |= arith->shift >> (7-arith->cntr)&1;
+ arith->code |= (arith->shift >> (arith->cntr-1))&1;
- arith->cntr++;
-
- if (arith->cntr == 8) {
+ if (!--arith->cntr) {
arith->offset++;
if (arith->offset < arith->buffer->length) {
arith->shift = arith->dataptr[arith->offset];
@@ -192,7 +190,7 @@ _schro_arith_decode_bit (SchroArith *arith, int i)
if (arith->code < arith->range[0]) {
arith->code |= (1<<16);
}
- arith->cntr = 0;
+ arith->cntr = 8;
}
}
--
1.5.5
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Schrodinger-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/schrodinger-devel