Squashed 'third_party/rawrtc/rawrtc-data-channel/' content from commit 7b1b8d57c
Change-Id: I84850720e2b51961981d55f67238f4d282314fff
git-subtree-dir: third_party/rawrtc/rawrtc-data-channel
git-subtree-split: 7b1b8d57c6d07da18cc0de8bbca8cc5e8bd06eae
diff --git a/src/crc32c/crc32c.c b/src/crc32c/crc32c.c
new file mode 100644
index 0000000..d22550e
--- /dev/null
+++ b/src/crc32c/crc32c.c
@@ -0,0 +1,36 @@
+#include "crc32c.h"
+#include "software.h"
+#include "../main/main.h"
+#include <rawrtcdc/config.h>
+#include <re.h>
+
+#if RAWRTCDC_ENABLE_SSE42_CRC32C
+# include "sse42.h"
+#endif
+
+#define DEBUG_MODULE "crc32c"
+//#define RAWRTC_DEBUG_MODULE_LEVEL 7 // Note: Uncomment this to debug this module only
+#include <rawrtcc/debug.h>
+
+/*
+ * Initialise CRC32-C.
+ */
+void rawrtc_crc32c_init(void) {
+#if RAWRTCDC_ENABLE_SSE42_CRC32C
+ if (rawrtc_crc32c_sse42_supported()) {
+ rawrtc_crc32c_init_sse42();
+ rawrtcdc_global.crc32c_handler = rawrtc_crc32c_sse42;
+ DEBUG_PRINTF("Initialised CRC32-C (sse42)\n");
+ return;
+ }
+#endif
+ rawrtcdc_global.crc32c_handler = rawrtc_crc32c_software;
+ DEBUG_PRINTF("Initialised CRC32-C (software)\n");
+}
+
+/*
+ * Compute CRC-32C using whatever method has been established.
+ */
+uint32_t rawrtc_crc32c(void const* buffer, size_t length) {
+ return rawrtcdc_global.crc32c_handler(buffer, length);
+}