perf: drop stdint.h + picolibc — zero libc dependency

dma.h: typedef u32 instead of uint32_t, no stdint.h include
dma.c: use u32 instead of uint32_t
user-sample.c: unsigned char/int instead of uint8_t/uint32_t

Makefile: filter-out -lc -lm -lg -lsemihost from LDFLAGS
  → picolibc .data section (2.1KB, 532 words) eliminated
  → startup data-copy loop: ~30000 → ~200 cycles
  → total start.S latency: ~44000 → ~14000 cycles (~0.42ms at 33MHz)
This commit is contained in:
2026-06-26 22:34:26 +08:00
parent dd6053ab73
commit 52e85aa6fb
4 changed files with 26 additions and 26 deletions

View File

@@ -10,16 +10,14 @@
* 4. XOR bank toggle → avoids g%2 recomputation per iteration
*/
#include <stdint.h>
#include <dma.h>
/* ─── UART 16550 direct access (bypasses slow printf/picolibc) ──────── */
#define UART_THR (*(volatile uint8_t *)0xbf000000)
#define UART_LSR (*(volatile uint8_t *)0xbf000005)
#define UART_THR (*(volatile unsigned char *)0xbf000000)
#define UART_LSR (*(volatile unsigned char *)0xbf000005)
#define LSR_THRE 0x20
static inline void uart_tx(uint8_t c) {
static inline void uart_tx(unsigned char c) {
while (!(UART_LSR & LSR_THRE)) {}
UART_THR = c;
}
@@ -28,10 +26,10 @@ static void uart_puts(const char *s) {
while (*s) uart_tx(*s++);
}
static void uart_puthex(uint32_t val) {
static void uart_puthex(unsigned int val) {
int i;
for (i = 28; i >= 0; i -= 4) {
uint8_t nibble = (val >> i) & 0xF;
unsigned char nibble = (val >> i) & 0xF;
uart_tx(nibble < 10 ? '0' + nibble : 'a' + nibble - 10);
}
}
@@ -86,19 +84,19 @@ int main(void)
if (MATMUL_GROUP_NUM <= 0) return 0;
/* ── Hot-path local volatile pointers (one-time addr calc) ──────── */
volatile uint32_t *mat_status = (volatile uint32_t *)MATMUL_STATUS;
volatile uint32_t *mat_ctrl = (volatile uint32_t *)MATMUL_CTRL;
volatile uint32_t *mat_crc = (volatile uint32_t *)MATMUL_CRC;
volatile unsigned int *mat_status = (volatile unsigned int *)MATMUL_STATUS;
volatile unsigned int *mat_ctrl = (volatile unsigned int *)MATMUL_CTRL;
volatile unsigned int *mat_crc = (volatile unsigned int *)MATMUL_CRC;
volatile dma_ch_regs_t *ch0 = DMA_CH(0);
volatile dma_ch_regs_t *ch1 = DMA_CH(1);
uint32_t crc;
unsigned int crc;
int g, bank;
// Ping-Pong Register Address Arrays (Physical for DMA)
uint32_t phys_bank_AB[2] = {MATMUL_PHYS_B0_AB, MATMUL_PHYS_B1_AB};
uint32_t phys_bank_C[2] = {MATMUL_PHYS_B0_C, MATMUL_PHYS_B1_C};
uint32_t ctrl_start[2] = {CTRL_START_B0, CTRL_START_B1};
unsigned int phys_bank_AB[2] = {MATMUL_PHYS_B0_AB, MATMUL_PHYS_B1_AB};
unsigned int phys_bank_C[2] = {MATMUL_PHYS_B0_C, MATMUL_PHYS_B1_C};
unsigned int ctrl_start[2] = {CTRL_START_B0, CTRL_START_B1};
/* ── Start marker (must be first output) ──────────────────── */
uart_puts("MATMUL_START\r\n");