Skip to content

Commit 3b87ec4

Browse files
committed
+ SHIFT_AS_DIV
1 parent 818db7e commit 3b87ec4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/ram_page.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static uint16_t last_ram_page = 0;
8989
static uint32_t last_lba_page = 0;
9090

9191
uint32_t get_ram_page_for(const uint32_t addr32) {
92-
const register uint32_t lba_page = addr32 / RAM_PAGE_SIZE; // 4KB page idx
92+
const register uint32_t lba_page = addr32 >> SHIFT_AS_DIV; // page idx
9393
if (last_lba_page == lba_page) {
9494
return last_ram_page;
9595
}

src/ram_page.h

+3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515
#ifdef SWAP_BLOCK_1k
1616
#define RAM_PAGE_SIZE_KB 1ul
1717
#define RAM_IN_PAGE_ADDR_MASK (0x000003FF)
18+
#define SHIFT_AS_DIV 10
1819
#endif
1920
// --- select only one of 'em
2021
#ifdef SWAP_BLOCK_2k
2122
#define RAM_PAGE_SIZE_KB 2ul
2223
#define RAM_IN_PAGE_ADDR_MASK (0x000007FF)
24+
#define SHIFT_AS_DIV 11
2325
#endif
2426
// --- select only one of 'em
2527
#ifdef SWAP_BLOCK_4k
2628
#define RAM_PAGE_SIZE_KB 4ul
2729
#define RAM_IN_PAGE_ADDR_MASK (0x00000FFF)
30+
#define SHIFT_AS_DIV 12
2831
#endif
2932
// --- select only one of 'em ^
3033

0 commit comments

Comments
 (0)