Skip to content

Commit

Permalink
main: Replace MOD with bitwise AND
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
crawfxrd committed Jan 5, 2024
1 parent 766fb73 commit 4b86176
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/board/system76/common/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 4b86176

Please sign in to comment.