From 5530c662bb53837d64a154e3b580d41adb6cc8b9 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Sun, 11 Oct 2026 23:30:21 +0300 Subject: opt: compile-time locked LUTs and branchless SIMD/ALU primitives - Replace buffer allocation branching loop with compile-time locked 24-byte LUT indexed by (cur & 3) - Use hardware lrint rounding and array-indexed pointer offsets for scroll axes - Replace press queue button/kind conditionals with branchless bitmasking and 1:1 identity casting - Make display_has_immediate_work evaluate state flags with bitwise ALU instead of short-circuit branches --- src/wayland/buffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/wayland/buffer.c') diff --git a/src/wayland/buffer.c b/src/wayland/buffer.c index 0d639e6..0b6b028 100644 --- a/src/wayland/buffer.c +++ b/src/wayland/buffer.c @@ -305,10 +305,11 @@ static void arm_frame(struct yasl_surface *w) } } -static const int8_t free_buf_lut[3][8] = { +static const int8_t free_buf_lut[4][8] = { [0] = { 1, 1, 2, 2, 1, 1, 0, -1 }, [1] = { 0, 2, 0, 2, 0, 1, 0, -1 }, [2] = { 0, 1, 0, 2, 0, 1, 0, -1 }, + [3] = { 0, 1, 0, 2, 0, 1, 0, -1 }, }; int buffer_pick_free_index(const struct buffer *bufs, int cur) @@ -316,9 +317,7 @@ int buffer_pick_free_index(const struct buffer *bufs, int cur) unsigned busy = ((unsigned)bufs[0].busy) | (((unsigned)bufs[1].busy) << 1) | (((unsigned)bufs[2].busy) << 2); - unsigned c = (unsigned)cur; - if (unlikely(c >= 3)) c = 0; - return free_buf_lut[c][busy]; + return free_buf_lut[(unsigned)cur & 3][busy]; } struct latency_feedback { -- cgit v1.2.3