From 4db50f3f7309c7e0041c0795ea0070a5653ac97f Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Mon, 22 Jul 2024 20:49:30 -0400 Subject: [PATCH] Manual loop unrolling --- main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index d7eace9..a1cd6d4 100644 --- a/main.c +++ b/main.c @@ -68,9 +68,9 @@ void drawTexInto(struct texture tex, struct texture buffer, struct rect texbound i32 bufi = 3 * (x + buffer.width * y); // You can get rid of this for loop for more performance, but probably // not a big deal with -O3, it'll be unrolled - for(int i = 0; i < 3; i++) { - buffer.data[bufi + i] = tex.data[texi + i]; - } + buffer.data[bufi] = tex.data[texi]; + buffer.data[bufi + 1] = tex.data[texi + 1]; + buffer.data[bufi + 2] = tex.data[texi + 2]; texx += stepx; } texy += stepy; @@ -98,10 +98,10 @@ int main() { // We actually stretch a texture here struct rect texrect = { 0, 0, 16, 16 }; - struct rect bufrect = { 10, 13, 502, 509 }; + struct rect bufrect = { 10, 10, 26, 26 }; clock_t start = clock(); - for(int i = 0; i < 50; i++) { //overdraw factor + for(int i = 0; i < 50000; i++) { //overdraw factor drawTexInto(tex, fb, texrect, bufrect); } clock_t end = clock();