programs: move output_bitstream to test_util

This commit is contained in:
Eric Biggers 2018-12-28 10:25:44 -06:00
parent ce6a95f47b
commit c398e237b6
3 changed files with 25 additions and 22 deletions

View File

@ -7,28 +7,6 @@
#include "test_util.h"
struct output_bitstream {
unsigned long bitbuf;
int bitcount;
u8 *next;
u8 *end;
};
static bool
put_bits(struct output_bitstream *os, unsigned long bits, int num_bits)
{
os->bitbuf |= bits << os->bitcount;
os->bitcount += num_bits;
while (os->bitcount >= 8) {
if (os->next == os->end)
return false;
*os->next++ = os->bitbuf;
os->bitcount -= 8;
os->bitbuf >>= 8;
}
return true;
}
/*
* Generate a DEFLATE stream containing all empty "static Huffman" blocks.
*

View File

@ -202,3 +202,18 @@ u64 timer_KB_per_s(u64 bytes, u64 ticks)
{
return bytes * timer_frequency() / ticks / 1000;
}
bool
put_bits(struct output_bitstream *os, machine_word_t bits, int num_bits)
{
os->bitbuf |= bits << os->bitcount;
os->bitcount += num_bits;
while (os->bitcount >= 8) {
if (os->next == os->end)
return false;
*os->next++ = os->bitbuf;
os->bitcount -= 8;
os->bitbuf >>= 8;
}
return true;
}

View File

@ -52,4 +52,14 @@ extern u64 timer_ticks_to_ms(u64 ticks);
extern u64 timer_MB_per_s(u64 bytes, u64 ticks);
extern u64 timer_KB_per_s(u64 bytes, u64 ticks);
struct output_bitstream {
machine_word_t bitbuf;
int bitcount;
u8 *next;
u8 *end;
};
extern bool put_bits(struct output_bitstream *os, machine_word_t bits,
int num_bits);
#endif /* PROGRAMS_TEST_UTIL_H */