From 422d4798521f0654cb77a8d8ac0615ec5f9d6778 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 14 Apr 2021 19:42:22 +0200 Subject: [PATCH] Added CRC match function and optimised byte packing --- lib/include/srsran/phy/fec/crc.h | 3 +++ lib/src/phy/fec/crc.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/include/srsran/phy/fec/crc.h b/lib/include/srsran/phy/fec/crc.h index 11ee824a5..1e16011c7 100644 --- a/lib/include/srsran/phy/fec/crc.h +++ b/lib/include/srsran/phy/fec/crc.h @@ -24,6 +24,7 @@ #define SRSRAN_CRC_H #include "srsran/config.h" +#include #include typedef struct SRSRAN_API { @@ -73,4 +74,6 @@ SRSRAN_API uint32_t srsran_crc_checksum_byte(srsran_crc_t* h, const uint8_t* dat SRSRAN_API uint32_t srsran_crc_checksum(srsran_crc_t* h, uint8_t* data, int len); +SRSRAN_API bool srsran_crc_match(srsran_crc_t* h, uint8_t* data, int len); + #endif // SRSRAN_CRC_H diff --git a/lib/src/phy/fec/crc.c b/lib/src/phy/fec/crc.c index 6c4da1d8e..f42d0877a 100644 --- a/lib/src/phy/fec/crc.c +++ b/lib/src/phy/fec/crc.c @@ -14,6 +14,10 @@ #include "srsran/phy/utils/bit.h" #include "srsran/phy/utils/debug.h" +#ifdef LV_HAVE_SSE +#include +#endif // LV_HAVE_SSE + static void gen_crc_table(srsran_crc_t* h) { uint32_t pad = (h->order < 8) ? (8 - h->order) : 0; @@ -104,7 +108,18 @@ uint32_t srsran_crc_checksum(srsran_crc_t* h, uint8_t* data, int len) byte |= ((uint8_t) * (pter + k)) << (7 - k); } } else { +#ifdef LV_HAVE_SSE + // Get 8 Bit + __m64 mask = _mm_cmpgt_pi8(*((__m64*)pter), _mm_set1_pi8(0)); + + // Reverse + mask = _mm_shuffle_pi8(mask, _mm_set_pi8(0, 1, 2, 3, 4, 5, 6, 7)); + + // Get mask and write + byte = (uint8_t)_mm_movemask_pi8(mask); +#else /* LV_HAVE_SSE */ byte = (uint8_t)(srsran_bit_pack(&pter, 8) & 0xFF); +#endif /* LV_HAVE_SSE */ } srsran_crc_checksum_put_byte(h, byte); } @@ -159,3 +174,11 @@ uint32_t srsran_crc_attach(srsran_crc_t* h, uint8_t* data, int len) srsran_bit_unpack(checksum, &ptr, h->order); return checksum; } + +bool srsran_crc_match(srsran_crc_t* h, uint8_t* data, int len) +{ + uint8_t* ptr = &data[len]; + uint32_t checksum1 = srsran_crc_checksum(h, data, len); + uint32_t checksum2 = srsran_bit_pack(&ptr, h->order); + return (checksum1 == checksum2); +}