Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend snrt_dma_memset #200

Open
colluca opened this issue Dec 18, 2024 · 0 comments
Open

Extend snrt_dma_memset #200

colluca opened this issue Dec 18, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@colluca
Copy link
Collaborator

colluca commented Dec 18, 2024

The snrt_memset function in alloc.h:

// TODO colluca: optimize by using DMA
inline void *snrt_memset(void *ptr, int value, size_t num) {
for (uint32_t i = 0; i < num; ++i)
*((uint8_t *)ptr + i) = (unsigned char)value;
return ptr;
}

And the snrt_dma_memset function in dma.h are to some extent redundant:

/**
* @brief Fast memset function performed by DMA.
* @param ptr Pointer to the start of the region.
* @param value Value to set.
* @param len Number of bytes, must be a multiple of the DMA bus width.
*/
inline void snrt_dma_memset(void *ptr, uint8_t value, uint32_t len) {
// set first 64bytes to value
// memset(ptr, value, 64);
uint8_t *p = ptr;
uint32_t nbytes = 64;
while (nbytes--) {
*p++ = value;
}
// DMA copy the the rest
snrt_dma_txid_t memset_txid =
snrt_dma_start_2d(ptr, ptr, 64, 64, 0, len / 64);
snrt_dma_wait_all();
}

Merge them and also handle specific case of a memset to zero by taking advantage of the cluster's zero memory. See the following as an example:

snrt_dma_start_1d((void*)(tls_ptr + i * tls_offset),
(void*)(snrt_zero_memory_ptr()), size);

@colluca colluca added the enhancement New feature or request label Dec 18, 2024
@colluca colluca self-assigned this Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant