This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ Fast div5 = idx / 5, without division | |
| @ div5 = (idx * 52) >> 8 | |
| @ Using 8 bit approximation of reciprocal value 1 / 5 | |
| @ (1 / 5) * 256 = 51.2 => magic5 = 52 | |
| @ (( 0 * 52) >> 8) = 0 >> 8 = 0 | |
| @ ... | |
| @ (( 4 * 52) >> 8) = 208 >> 8 = 0 | |
| @ (( 5 * 52) >> 8) = 260 >> 8 = 1 | |
| @ ... | |
| @ (( 9 * 52) >> 8) = 468 >> 8 = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Matrix Mx8 kbd scan with debouncing, depth = 4 | |
| // Mod n-history stage for different depth level | |
| #define M 7 // Number of columns in your matrix | |
| // 4-stage history and stable state per column | |
| typedef struct { | |
| uint8_t h0, h1, h2, h3; | |
| uint8_t state; | |
| } debounce_col_4_t; | |
| debounce_col_4_t matrix_state[M]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ ============================================================================== | |
| @ euc_div_mod | |
| @ ============================================================================== | |
| @ Calculates both a mathematically floored quotient and a strictly non-negative | |
| @ remainder concurrently using a high-velocity branchless bitmask workflow. | |
| @ | |
| @ Input / Output Arguments: | |
| @ \quot [Updated ] Destination register for the floored quotient output | |
| @ \rem [Updated ] Destination register for the non-negative remainder | |
| @ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| uint16_t fast_gamma_16b(uint32_t* l2_lut, uint32_t g_q24, int n) { | |
| if (n == 0) return 0; | |
| uint32_t p_q24 = ((uint64_t)l2_lut[n] * g_q24) >> 24; | |
| int32_t c_fixed = -(int32_t)p_q24; | |
| int i = c_fixed >> 24; | |
| uint32_t f_31 = (c_fixed & 0xFFFFFF) << 7; |