Skip to content

Commit

Permalink
add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rzblue committed Sep 19, 2024
1 parent 282d741 commit 9305129
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions hal/src/main/native/athena/AddressableLEDSimd.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ void RGBConvert_16(const uint8_t* src, uint8_t* dst) {
}
}

/**
* Copies 8 pixels from src to dst, converting from RGB(?) to order. Optimizes based on alignment of input and output arrays specified by inAlign and outAlign
* @tparam order the color order to convert to
* @tparam inAlign whether src is aligned to the size of a NEON register (16 bytes)
* @tparam outAlign whether dst is aligned to the size of a NEON register (16 bytes)
* @param[in] src The source array
* @param[out] dst the destination array
* @pre src and dst must contain at least 32 bytes (8 pixels)
* @pre if inAlign is true, src must be 16 byte aligned
* @pre if outAlign is true, src muts be 16 byte aligned
*/
template <HAL_AddressableLEDColorOrder order, bool inAlign, bool outAlign>
void RGBConvert_8(const uint8_t* src, uint8_t* dst) {
switch (order) {
Expand All @@ -98,7 +109,13 @@ void RGBConvert_8(const uint8_t* src, uint8_t* dst) {
break;
}
}

/**
* Copies 1 pixel from in to out, converting from RGB to the specified order.
* @param[in] order the color order to convert to
* @param[in] in the source array
* @param[out] the destination array
* @pre in and out must contain at least 1 pixel.
*/
void RGBConvert_1(HAL_AddressableLEDColorOrder order, const uint8_t* in, uint8_t* out) {
uint8_t tmp[4];
std::memcpy(tmp, in, 4);
Expand All @@ -122,7 +139,18 @@ void RGBConvert_1(HAL_AddressableLEDColorOrder order, const uint8_t* in, uint8_t
std::memcpy(out, in, 4);
}
}

/**
* Copies len pixels from src to dst, converting from RGB(?) to order. Optimizes based on alignment of input and output arrays specified by inAlign and outAlign
* @tparam order the color order to convert to
* @tparam inAlign whether src is aligned to the size of a NEON register (16 bytes)
* @tparam outAlign whether dst is aligned to the size of a NEON register (16 bytes)
* @param[in] src The source array
* @param[out] dst the destination array
* @param[in] len the size (in pixels, len = (size in bytes) / 4)
* @pre src and dst must have at least len*4 capacity in bytes
* @pre if inAlign is true, src must be 16 byte aligned
* @pre if outAlign is true, src muts be 16 byte aligned
*/
template <HAL_AddressableLEDColorOrder order, bool inAlign, bool outAlign>
void RGBConvert(const uint8_t* src, uint8_t* dst, size_t len) {
if(len >= 16) {
Expand All @@ -147,13 +175,18 @@ void RGBConvert(const uint8_t* src, uint8_t* dst, size_t len) {
for(size_t i = 0; i < len; i += 4) {
RGBConvert_1(order, src + i, dst + i);
}
// we could also use neon single lane instructions
// https://developer.arm.com/documentation/ddi0406/c/Application-Level-Architecture/Instruction-Details/Alphabetical-list-of-instructions/VLD4--single-4-element-structure-to-all-lanes-
// https://developer.arm.com/documentation/102474/0100/Fundamentals-of-Armv8-Neon-technology/Registers--vectors--lanes-and-elements
// vld4_lane_u8
}

}

/**
* Copies pixelCount pixels from src to dst, converting from RGB to the specified order
*
*/
template <HAL_AddressableLEDColorOrder order>
void RGBConvert(const uint8_t* src, uint8_t* dst, size_t pixelCount) {
if (Aligned(src) && Aligned(dst)) {
Expand Down

0 comments on commit 9305129

Please sign in to comment.