diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-05-08 22:25:24 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-05-08 22:25:24 +0200 |
| commit | e19ed379f9d86c8a21515095fd8725c68f7b4426 (patch) | |
| tree | ee0120ec1683acb284d3499c7465bcd4557ac2a7 /src | |
| parent | Improve performance and memory usage of blind-transpose (diff) | |
| download | blind-e19ed379f9d86c8a21515095fd8725c68f7b4426.tar.gz blind-e19ed379f9d86c8a21515095fd8725c68f7b4426.tar.bz2 blind-e19ed379f9d86c8a21515095fd8725c68f7b4426.tar.xz | |
Improve performance of blind-flop
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | src/blind-flop.c | 33 | ||||
| -rw-r--r-- | src/blind-transpose.c | 2 |
2 files changed, 26 insertions, 9 deletions
diff --git a/src/blind-flop.c b/src/blind-flop.c index 3401f7d..c5826be 100644 --- a/src/blind-flop.c +++ b/src/blind-flop.c @@ -8,12 +8,28 @@ USAGE("") +static struct stream stream; +static char *buf, *image; +static size_t n, m, ps; + +#define PROCESS(TYPE)\ + do {\ + size_t i, j, pst = ps / sizeof(TYPE);\ + size_t nt = n / sizeof(TYPE);\ + size_t mt = m / sizeof(TYPE);\ + for (i = 0; i < pst; i++)\ + for (j = 0; j < nt; j += pst)\ + ((TYPE *)image)[mt - j + i] = ((TYPE *)buf)[i + j];\ + } while (0) + +static void process_double(void) {PROCESS(double);} +static void process_float (void) {PROCESS(float);} +static void process_char (void) {PROCESS(char);} + int main(int argc, char *argv[]) { - struct stream stream; - char *buf, *image; - size_t i, j, n, m; + void (*process)(void); UNOFLAGS(argc); @@ -22,15 +38,16 @@ main(int argc, char *argv[]) efflush(stdout, "<stdout>"); echeck_frame_size(stream.width, 1, stream.pixel_size, 0, stream.file); - n = stream.width * stream.pixel_size; + n = stream.width * (ps = stream.pixel_size); buf = emalloc(n); image = emalloc(n); - m = n - stream.pixel_size; + process = !(ps % sizeof(double)) ? process_double : + !(ps % sizeof(float)) ? process_float : process_char; + + m = n - ps; while (eread_row(&stream, buf, n)) { - for (i = 0; i < stream.pixel_size; i++) - for (j = 0; j < n; j += stream.pixel_size) - image[m - j + i] = buf[i + j]; + process(); ewriteall(STDOUT_FILENO, image, n, "<stdout>"); } diff --git a/src/blind-transpose.c b/src/blind-transpose.c index 5c53a0d..cc7e7d3 100644 --- a/src/blind-transpose.c +++ b/src/blind-transpose.c @@ -33,7 +33,7 @@ main(int argc, char *argv[]) struct stream stream; char *buf, *image; size_t n, y; - void (*process)(char *col, char *row); + void (*process)(char *row, char *col); UNOFLAGS(argc); |
