]> git.sesse.net Git - fjl/blobdiff - bitsource.h
Add a stupid integerization of the AA&N IDCT -- 30% faster or so, mostly
[fjl] / bitsource.h
index e5bdd282ae104de0c9017f651efa6a7d60dd3751..bb3a6d246e62016665e5560ac048397b15f7f8e9 100644 (file)
@@ -7,6 +7,8 @@
 #include <sys/types.h>
 #include <arpa/inet.h>
 
+#include "input.h"
+
 // Optimize for 64 bits. We might want to replace this for 32-bit machines
 // (benchmark later).
 typedef uint64_t bitreservoir_t;
@@ -21,11 +23,6 @@ static const unsigned BITRESERVOIR_SIZE = 8 * sizeof(bitreservoir_t);
 static const unsigned BITRESERVOIR_FILL_SIZE = 8 * sizeof(bitreservoir_fill_t);
 static const unsigned BYTERESERVOIR_SIZE = 4096;
 
-// A function to read bytes from some input source. The bytes should be
-// already unstuffed (and thus without markers).
-// A return value of -1 indicates error, a return value of 0 indicates EOF.
-typedef ssize_t (input_func_t)(void*, uint8_t*, size_t);
-
 // A data source for efficient reading of bit-level data.
 struct bit_source {
        // Short-term bit reservoir; holds up to 64 bits. When it's empty,
@@ -37,6 +34,7 @@ struct bit_source {
        // When this is empty, it needs to be refilled from the input
        // stream.
        uint8_t* bytes;
+       uint8_t* byte_read_ptr;
        unsigned bytes_available;
 
        // Data source.
@@ -65,8 +63,8 @@ static inline void possibly_refill(struct bit_source* source, unsigned num_bits)
        // Slower path (~99% of remaining invocations?)
        assert(source->bits_available + BITRESERVOIR_FILL_SIZE < BITRESERVOIR_SIZE);
        if (source->bytes_available >= sizeof(bitreservoir_fill_t)) {
-               bitreservoir_fill_t fill = read_bitreservoir_fill(source->bytes);
-               source->bytes += sizeof(bitreservoir_fill_t);
+               bitreservoir_fill_t fill = read_bitreservoir_fill(source->byte_read_ptr);
+               source->byte_read_ptr += sizeof(bitreservoir_fill_t);
                source->bytes_available -= sizeof(bitreservoir_fill_t);
                source->bits |= (bitreservoir_t)fill << (BITRESERVOIR_SIZE - BITRESERVOIR_FILL_SIZE - source->bits_available);
                source->bits_available += BITRESERVOIR_FILL_SIZE;