From 4b86176659a85eaba918e776ad74d75016a747a8 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 2 Jan 2024 17:01:07 -0700 Subject: [PATCH] main: Replace MOD with bitwise AND This prevents `moduint` from being called for the superloop. A bitwise AND is used instead of using the equivalent `% 4` as an indication that modulo should not be used, as not using a power of 2 (which is optimized) will result in an expensive call to SDCC library functions. Signed-off-by: Tim Crawford --- src/board/system76/common/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/board/system76/common/main.c b/src/board/system76/common/main.c index 256425189..d94e9b03b 100644 --- a/src/board/system76/common/main.c +++ b/src/board/system76/common/main.c @@ -102,7 +102,7 @@ void main(void) { uint32_t last_time_fan = 0; for (main_cycle = 0;; main_cycle++) { - switch (main_cycle % 3U) { + switch (main_cycle & 3U) { case 0: // Handle USB-C events immediately before power states usbpd_event(); @@ -123,6 +123,11 @@ void main(void) { // Handle lid close/open lid_event(); break; + + case 3: + // We previously used modulo to limit when the logic for other + // cases ran, so this case is unused. + break; } if (main_cycle == 0) {