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:
@@ -10,3 +10,6 @@ COMMON_DIR = ../../bsp
|
||||
GCC_DIR=../../../toolchains/loongson-gnu-toolchain-8.3-x86_64-loongarch32r-linux-gnusf-v2.0
|
||||
PICOLIBC_DIR=../../../toolchains/picolibc
|
||||
include ../../bsp/common.mk
|
||||
|
||||
# Strip picolibc: no -lc -lm -lg -lsemihost, keep -lgcc only
|
||||
LDFLAGS := $(filter-out -lc -lm -lg -lsemihost,$(LDFLAGS))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "dma.h"
|
||||
|
||||
void dma_start_transfer(int ch_id, uint32_t src, uint32_t dst, uint32_t bytes, uint32_t tag) {
|
||||
void dma_start_transfer(int ch_id, u32 src, u32 dst, u32 bytes, u32 tag) {
|
||||
volatile dma_ch_regs_t* ch = DMA_CH(ch_id);
|
||||
|
||||
// 检查通道是否空闲 防止覆盖正在运行的任务
|
||||
@@ -18,7 +18,7 @@ void dma_start_transfer(int ch_id, uint32_t src, uint32_t dst, uint32_t bytes, u
|
||||
// 置 Burst 属性并触发传输
|
||||
// AXI SIZE: 2 (代表 2^2 = 4 Bytes,与 32-bit 数据线匹配)
|
||||
// AXI LEN: 15 (代表 16 beats 突发传输,最高效)
|
||||
uint32_t ctrl_val = CTRL_BURST_SIZE(2) | CTRL_BURST_LEN(63);
|
||||
u32 ctrl_val = CTRL_BURST_SIZE(2) | CTRL_BURST_LEN(63);
|
||||
|
||||
// 写入 CTRL 并拉高 Bit 0 (Start)
|
||||
ch->CTRL = ctrl_val | CTRL_START_BIT;
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef unsigned int u32;
|
||||
|
||||
typedef struct {
|
||||
volatile uint32_t SRC_ADDR; // 0x00: 源地址
|
||||
volatile uint32_t DST_ADDR; // 0x04: 目的地址
|
||||
volatile uint32_t LENGTH; // 0x08: 传输总字节数
|
||||
volatile uint32_t TAG; // 0x0C: 软件 Tag (硬件不处理,留给软件标记任务用)
|
||||
volatile uint32_t CTRL; // 0x10: 控制寄存器 (配置 Burst 属性 + 启动)
|
||||
volatile uint32_t STATUS; // 0x14: 状态寄存器 (Busy, Done)
|
||||
volatile uint32_t RESV[10]; // 0x18 ~ 0x3C: 保留空间,凑齐 0x40 字节
|
||||
volatile u32 SRC_ADDR; // 0x00: source address
|
||||
volatile u32 DST_ADDR; // 0x04: destination address
|
||||
volatile u32 LENGTH; // 0x08: transfer byte count
|
||||
volatile u32 TAG; // 0x0C: software tag (ignored by HW)
|
||||
volatile u32 CTRL; // 0x10: control (burst config + start)
|
||||
volatile u32 STATUS; // 0x14: status (busy, done)
|
||||
volatile u32 RESV[10]; // 0x18 ~ 0x3C: padding to 0x40 bytes
|
||||
} dma_ch_regs_t;
|
||||
|
||||
// DMA 控制器基地址
|
||||
@@ -26,5 +25,5 @@ typedef struct {
|
||||
#define STATUS_BUSY_BIT (1 << 0)
|
||||
#define STATUS_DONE_BIT (1 << 1)
|
||||
|
||||
void dma_start_transfer(int ch_id, uint32_t src, uint32_t dst, uint32_t bytes, uint32_t tag);
|
||||
void dma_start_transfer(int ch_id, u32 src, u32 dst, u32 bytes, u32 tag);
|
||||
void dma_wait_polling(int ch_id);
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user