Skip to content

Commit

Permalink
Faster now: stm32 100bytes message, now encode 124us and decode 112us
Browse files Browse the repository at this point in the history
  • Loading branch information
hit9 committed Jan 5, 2023
1 parent d58a2ac commit 7db7eef
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/c/bitproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ void BpCopyBufferBits(int n, unsigned char *dst, unsigned char *src, int di,
if (n >= 32) {
((uint32_t *)dst)[0] = ((uint32_t *)(src))[0] >> si;
if (si) dst[3] |= ((src[4] << d) & ~(0xff << d << si));

c = 32;

dst += 4;
src += 4;
n -= c;
continue;
} else if (b >= 32) {
// Copy as an uint32 integer.
// This way, performance faster x2 than bits copy approach.
Expand All @@ -238,6 +244,11 @@ void BpCopyBufferBits(int n, unsigned char *dst, unsigned char *src, int di,
if (si) dst[1] |= ((src[2] << d) & ~(0xff << d << si));

c = 16;

dst += 2;
src += 2;
n -= c;
continue;
} else if (b >= 16) {
// Copy as an uint16 integer.
((uint16_t *)dst)[0] = ((uint16_t *)(src))[0] >> si;
Expand All @@ -246,7 +257,13 @@ void BpCopyBufferBits(int n, unsigned char *dst, unsigned char *src, int di,
// Copy as an unsigned char.
dst[0] = (src[0] >> si) & 0xff;
if (si) dst[0] |= ((src[1] << d) & ~(0xff << d << si));

c = 8;

dst += 1;
src += 1;
n -= c;
continue;
} else if (b >= 8) {
// Copy as an unsigned char.
dst[0] = (src[0] >> si) & 0xff;
Expand Down

0 comments on commit 7db7eef

Please sign in to comment.