summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2023-04-21 18:30:00 +0200
committerBad Diode <bd@badd10de.dev>2023-04-21 18:30:00 +0200
commitedc24cc2cf127c86245b3488d5405e021ae2e63f (patch)
tree4b95b197a6fe79a59faf143a53bff3f40d668b1d
parentfc449a2f2c10e443472cda62e1044264a09fe051 (diff)
downloadgba-renderers-edc24cc2cf127c86245b3488d5405e021ae2e63f.tar.gz
gba-renderers-edc24cc2cf127c86245b3488d5405e021ae2e63f.zip
Add minor optimization removing branching
-rw-r--r--src/renderer_m0.c21
-rw-r--r--src/renderer_m4.c36
2 files changed, 13 insertions, 44 deletions
diff --git a/src/renderer_m0.c b/src/renderer_m0.c
index eaf4658..7e598c3 100644
--- a/src/renderer_m0.c
+++ b/src/renderer_m0.c
@@ -472,10 +472,7 @@ draw_2bpp_row(size_t x, size_t y, u8 a, u8 b, u8 flip_x) {
472 472
473 u32 *dst = &backbuf[start_row + (tile_x + tile_y * 32) * 8]; 473 u32 *dst = &backbuf[start_row + (tile_x + tile_y * 32) * 8];
474#if DEC_BIG_LUT 474#if DEC_BIG_LUT
475 u32 *lut = dec_byte; 475 u32 *lut = flip_x ? dec_byte_flip_x : dec_byte;
476 if (flip_x) {
477 lut = dec_byte_flip_x;
478 }
479 u32 clr_a = lut[a]; 476 u32 clr_a = lut[a];
480 u32 clr_b = lut[b]; 477 u32 clr_b = lut[b];
481#else 478#else
@@ -486,12 +483,8 @@ draw_2bpp_row(size_t x, size_t y, u8 a, u8 b, u8 flip_x) {
486 u32 mask_b = (clr_b * 0xF); 483 u32 mask_b = (clr_b * 0xF);
487 u32 mask = (mask_a | mask_b); 484 u32 mask = (mask_a | mask_b);
488 u32 color = clr_a + (clr_b << 1); 485 u32 color = clr_a + (clr_b << 1);
489 if (start_col == 0) { 486 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
490 dst[0] = (dst[0] & ~mask) | color; 487 dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right);
491 } else {
492 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
493 dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right);
494 }
495 488
496 // TODO: different blend modes? 489 // TODO: different blend modes?
497} 490}
@@ -513,12 +506,8 @@ draw_1bpp_row(size_t x, size_t y, u8 a, u8 clr, u8 flip_x) {
513 u32 color = decode_1bpp(a, flip_x); 506 u32 color = decode_1bpp(a, flip_x);
514 u32 mask = (color * 0xF); 507 u32 mask = (color * 0xF);
515 color *= clr; 508 color *= clr;
516 if (start_col == 0) { 509 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
517 dst[0] = (dst[0] & ~mask) | color; 510 dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right);
518 } else {
519 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
520 dst[8] = (dst[8] & ~(mask >> shift_right)) | (color >> shift_right);
521 }
522 511
523 // TODO: different blend modes? 512 // TODO: different blend modes?
524} 513}
diff --git a/src/renderer_m4.c b/src/renderer_m4.c
index 2a5e9fe..73b51d5 100644
--- a/src/renderer_m4.c
+++ b/src/renderer_m4.c
@@ -449,10 +449,7 @@ draw_2bpp_row(size_t x, size_t y, u8 a, u8 b, u8 flip_x) {
449 449
450 u64 *dst = &backbuf[(y * 30 + tile_x) * 8 / 2]; 450 u64 *dst = &backbuf[(y * 30 + tile_x) * 8 / 2];
451#if DEC_BIG_LUT 451#if DEC_BIG_LUT
452 u64 *lut = dec_byte; 452 u64 *lut = flip_x ? dec_byte_flip_x : dec_byte;
453 if (flip_x) {
454 lut = dec_byte_flip_x;
455 }
456 u64 clr_a = lut[a]; 453 u64 clr_a = lut[a];
457 u64 clr_b = lut[b]; 454 u64 clr_b = lut[b];
458#else 455#else
@@ -463,15 +460,8 @@ draw_2bpp_row(size_t x, size_t y, u8 a, u8 b, u8 flip_x) {
463 u64 mask_b = (clr_b * 0xF); 460 u64 mask_b = (clr_b * 0xF);
464 u64 mask = (mask_a | mask_b); 461 u64 mask = (mask_a | mask_b);
465 u64 color = clr_a + (clr_b << 1); 462 u64 color = clr_a + (clr_b << 1);
466 if (start_col == 0) { 463 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
467 dst[0] = (dst[0] & ~mask) | color; 464 dst[1] = (dst[1] & ~(mask >> shift_right)) | (color >> shift_right);
468 } else {
469 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
470 if ((x + 7) > (SCREEN_WIDTH)) {
471 return;
472 }
473 dst[1] = (dst[1] & ~(mask >> shift_right)) | (color >> shift_right);
474 }
475 465
476 // TODO: different blend modes? 466 // TODO: different blend modes?
477} 467}
@@ -488,21 +478,11 @@ draw_1bpp_row(size_t x, size_t y, u8 a, u8 clr, u8 flip_x) {
488 size_t shift_right = (8 - start_col) * 8; 478 size_t shift_right = (8 - start_col) * 8;
489 479
490 u64 *dst = &backbuf[(y * 30 + tile_x) * 8 / 2]; 480 u64 *dst = &backbuf[(y * 30 + tile_x) * 8 / 2];
491 if (start_col == 0) { 481 u64 color = decode_1bpp(a, flip_x);
492 u64 color = decode_1bpp(a, flip_x); 482 u64 mask = (color * 0xF);
493 u64 mask = (color * 0xF); 483 color *= clr;
494 color *= clr; 484 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
495 dst[0] = (dst[0] & ~mask) | color; 485 dst[1] = (dst[1] & ~(mask >> shift_right)) | (color >> shift_right);
496 } else {
497 u64 color = decode_1bpp(a, flip_x);
498 u64 mask = (color * 0xF);
499 color *= clr;
500 dst[0] = (dst[0] & ~(mask << shift_left)) | (color << shift_left);
501 if ((x + 7) > (SCREEN_WIDTH)) {
502 return;
503 }
504 dst[1] = (dst[1] & ~(mask >> shift_right)) | (color >> shift_right);
505 }
506 486
507 // TODO: different blend modes? 487 // TODO: different blend modes?
508} 488}