firmware: refactor CACHEALIGN_BITS/SIZE defines

Mostly motivated by PP needing CACHEALIGN_SIZE in linker
scripts, which can't include system.h, so move these to
cpu.h instead. Also gets rid of the default 32 byte line
size that was used if the target didn't define alignment
itself. RK24xx, DM320, and JZ4740 were missing this but
have been confirmed (from datasheets) to use 32-byte cache
lines.

Add checks to make sure the macros are appropriately
(un)defined based on the HAVE_CPU_CACHE_ALIGN define,
and make sure their values are consistent when they
are defined.

Disable HAVE_CPU_CACHE_ALIGN for hosted targets since it
arguably doesn't matter if there's a cache, if we aren't
responsible for cache maintenance.

A few files in rbcodec use CACHEALIGN_SIZE, but these
can be converted to MEM_ALIGN_SIZE, which is identical
to CACHEALIGN_SIZE if the latter is defined. On other
targets, it aligns to at least sizeof(intptr_t).

Change-Id: If8cf8f6ec327dc3732f4cd5022a858546b9e63d6
This commit is contained in:
Aidan MacDonald 2026-02-05 15:17:15 +00:00
parent e61bf40542
commit 7eeb4e4302
23 changed files with 83 additions and 86 deletions

View file

@ -35,7 +35,7 @@ static unsigned char* mallocbuf = NULL;
int codec_init(void)
{
/* codec_get_buffer() aligns the resulting point to CACHEALIGN_SIZE. */
/* codec_get_buffer() aligns the resulting point to MEM_ALIGN_SIZE. */
mem_ptr = 0;
mallocbuf = (unsigned char *)ci->codec_get_buffer((size_t *)&bufsize);
@ -67,8 +67,8 @@ void* codec_malloc(size_t size)
x=&mallocbuf[mem_ptr];
/* Keep memory aligned to CACHEALIGN_SIZE. */
mem_ptr += (size + (CACHEALIGN_SIZE-1)) & ~(CACHEALIGN_SIZE-1);
/* Keep memory aligned to MEM_ALIGN_SIZE. */
mem_ptr += MEM_ALIGN_UP(size);
return(x);
}

View file

@ -72,8 +72,8 @@ void iram_malloc_init(void){
void *iram_malloc(size_t size){
void* x;
/* always ensure alignment to CACHEALIGN_SIZE byte */
size = (size + (CACHEALIGN_SIZE-1)) & ~(CACHEALIGN_SIZE-1);
/* align for best performance */
size = MEM_ALIGN_UP(size);
if(size>iram_remain)
return NULL;

View file

@ -117,9 +117,6 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
# define MEM_ALIGN_ATTR
#endif
#ifndef CACHEALIGN_SIZE
# define CACHEALIGN_SIZE 1
#endif
/*
#ifndef HAVE_CLIP_SAMPLE_16
static inline int32_t clip_sample_16(int32_t sample)

View file

@ -428,12 +428,9 @@ static void perform_config(void)
static void *ci_codec_get_buffer(size_t *size)
{
static char buffer[64 * 1024 * 1024];
char *ptr = buffer;
static char buffer[64 * 1024 * 1024] MEM_ALIGN_ATTR;
*size = sizeof(buffer);
if ((intptr_t)ptr & (CACHEALIGN_SIZE - 1))
ptr += CACHEALIGN_SIZE - ((intptr_t)ptr & (CACHEALIGN_SIZE - 1));
return ptr;
return buffer;
}
static void ci_pcmbuf_insert(const void *ch1, const void *ch2, int count)