esp-rs / esp32-hal

A hardware abstraction layer for the esp32 written in Rust.
Apache License 2.0
192 stars 28 forks source link

GlobalAlloc, AllocRef implementation and optimized versions of memcpy, etc. #22

Closed arjanmels closed 4 years ago

arjanmels commented 4 years ago

This PR implements global memory allocators. Allowing use of the heap, e.g. Box, Vec, etc. etc. It has seperate IRAM, DRAM and External RAM allocators and a merged/mixed allocator.

It builds further on #16. Best to merge that one first.

Features

memcpy, etc implementations

These have been heavily optimized for esp32. For large aligned memset and memcpy reaches ~88% of maximum memory bandwidth; for memcpy_reverse ~60%.

Discussion

I chose to implement the memcpy etc functions in the esp32-hal branch. The details of the optimizations are esp32 specific. So option 3 below, but then in esp32-hal. Could in principle be moved to xtensa-lx-rt crate. Open for discussion.

Options considered 1. don't use IRAM for heap at all 2. create improved versions of memcpy, etc and get this integrated into compiler-builtins crate

  1. create improved versions of memcpy etc. and add it to the xtensa-lx6-rt crate using the [package.metadata.cargo-xbuild] memcpy = true setting in Cargo.toml 4. add optimized memcpy, memfill support to the xtensa llvm branch, avoiding the rust implementations (as seems to be done on x86 etc.)