From 86629431ce8f49d192bd5b55c7ff346e1a1d98cb Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sat, 26 Jan 2019 11:06:26 +0100 Subject: micro bunzip --- test/monniaux/clock.c | 15 +++++++++++ test/monniaux/clock.h | 5 ++++ test/monniaux/cycles.h | 6 ++--- test/monniaux/micro-bunzip/Makefile | 41 ++++++++++++++++++++----------- test/monniaux/micro-bunzip/micro-bunzip.c | 13 ++++++++-- 5 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 test/monniaux/clock.c create mode 100644 test/monniaux/clock.h (limited to 'test/monniaux') diff --git a/test/monniaux/clock.c b/test/monniaux/clock.c new file mode 100644 index 00000000..506dadc3 --- /dev/null +++ b/test/monniaux/clock.c @@ -0,0 +1,15 @@ +#include "cycles.h" + +static cycle_t total_clock, last_start; + +void clock_start(void) { + last_start = get_cycle(); +} + +void clock_stop(void) { + total_clock += get_cycle() - last_start; +} + +cycle_t get_total_clock(void) { + return total_clock; +} diff --git a/test/monniaux/clock.h b/test/monniaux/clock.h new file mode 100644 index 00000000..768985b4 --- /dev/null +++ b/test/monniaux/clock.h @@ -0,0 +1,5 @@ +typedef unsigned long long cycle_t; + +void clock_stop(void); +void clock_start(void); +cycle_t get_total_clock(void); diff --git a/test/monniaux/cycles.h b/test/monniaux/cycles.h index 212e65fc..34f5bae5 100644 --- a/test/monniaux/cycles.h +++ b/test/monniaux/cycles.h @@ -1,17 +1,17 @@ -typedef uint64_t cycle_t; +typedef unsigned long long cycle_t; #ifdef __K1C__ #include static inline void cycle_count_config(void) { /* config pmc for cycle count */ - uint64_t pmc_value = __builtin_k1_get(K1_SFR_PMC); + cycle_t pmc_value = __builtin_k1_get(K1_SFR_PMC); pmc_value &= ~(0xfULL); __builtin_k1_set(K1_SFR_PMC, pmc_value); } -static inline uint64_t get_cycle(void) +static inline cycle_t get_cycle(void) { return __builtin_k1_get(K1_SFR_PM0); } diff --git a/test/monniaux/micro-bunzip/Makefile b/test/monniaux/micro-bunzip/Makefile index 2b89c6c1..8916d61f 100644 --- a/test/monniaux/micro-bunzip/Makefile +++ b/test/monniaux/micro-bunzip/Makefile @@ -1,24 +1,35 @@ -all: testfile.txt testfile.txt.2 - cmp testfile.txt testfile.txt.2 +all: testfile.txt testfile.txt.2ccomp testfile.txt.2gcc + cmp testfile.txt testfile.txt.2ccomp + cmp testfile.txt testfile.txt.2gcc -micro-bunzip.k1c: micro-bunzip.c - ../../../ccomp -O3 $< -U __SIZEOF_INT128__ -D __SIZE_TYPE__='long long' -o $@ +../clock.gcc.k1c.o : ../clock.c ../cycles.h + k1-mbr-gcc -c -Wall -O3 $< -o $@ + +micro-bunzip.ccomp.k1c: micro-bunzip.c ../clock.gcc.k1c.o + ../../../ccomp -Wall -O3 $+ -U __SIZEOF_INT128__ -D __SIZE_TYPE__='unsigned long long' -o $@ + +# TODO: -O3 buggy?? +micro-bunzip.gcc.k1c: micro-bunzip.c ../clock.gcc.k1c.o + k1-mbr-gcc -Wall -O2 $+ -o $@ testfile.txt: micro-bunzip.c cat micro-bunzip.c > $@ sha1sum micro-bunzip.c >> $@ cat micro-bunzip.c >> $@ md5sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha224sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha256sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha384sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ - sha512sum micro-bunzip.c >> $@ - cat micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha224sum micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha256sum micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha384sum micro-bunzip.c >> $@ +# cat micro-bunzip.c >> $@ +# sha512sum micro-bunzip.c >> $@ +#x cat micro-bunzip.c >> $@ + +testfile.txt.2ccomp: testfile.txt micro-bunzip.ccomp.k1c + bzip2 $@ -testfile.txt.2: testfile.txt micro-bunzip.k1c - bzip2 $@ +testfile.txt.2gcc: testfile.txt micro-bunzip.gcc.k1c + bzip2 $@ diff --git a/test/monniaux/micro-bunzip/micro-bunzip.c b/test/monniaux/micro-bunzip/micro-bunzip.c index ef307cef..32a4a7a8 100644 --- a/test/monniaux/micro-bunzip/micro-bunzip.c +++ b/test/monniaux/micro-bunzip/micro-bunzip.c @@ -12,6 +12,8 @@ (LGPL) version 2, available at http://www.gnu.org/copyleft/lgpl.html */ +#include "../clock.h" + #include #include #include @@ -84,8 +86,10 @@ static unsigned int get_bits(bunzip_data *bd, char bits_wanted) while (bd->inbufBitCountinbufPos==bd->inbufCount) { + clock_stop(); if(!(bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE))) longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_INPUT_EOF); + clock_start(); bd->inbufPos=0; } /* Avoid 32-bit overflow (dump bit buffer to top of output) */ @@ -359,8 +363,10 @@ extern int read_bunzip_data(bunzip_data *bd) extern void flush_bunzip_outbuf(bunzip_data *bd, int out_fd) { if(bd->outbufPos) { + clock_stop(); if(write(out_fd, bd->outbuf, bd->outbufPos) != bd->outbufPos) longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_OUTPUT_EOF); + clock_start(); bd->outbufPos=0; } } @@ -498,11 +504,13 @@ extern char *uncompressStream(int src_fd, int dst_fd) bunzip_data *bd; int i; + clock_start(); if(!(i=start_bunzip(&bd,src_fd,0,0))) { i=write_bunzip_data(bd,dst_fd,0,0); if(i==RETVAL_LAST_BLOCK && bd->headerCRC==bd->totalCRC) i=RETVAL_OK; } flush_bunzip_outbuf(bd,dst_fd); + clock_stop(); if(bd->dbuf) free(bd->dbuf); free(bd); return bunzip_errors[-i]; @@ -511,6 +519,7 @@ extern char *uncompressStream(int src_fd, int dst_fd) /* Dumb little test thing, decompress stdin to stdout */ int main(int argc, char *argv[]) { - char *c=uncompressStream(0,1); - fprintf(stderr,"\n%s\n", c ? c : "Completed OK"); + char *c=uncompressStream(0,1); + fprintf(stderr, "%s\ncycles=%llu\n", c ? c : "Completed OK", get_total_clock()); + return 0; } -- cgit