diff libtwamr/bits2prm.c @ 254:f931e704adc5

libtwamr: bits and parameter packing
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 05 Apr 2024 07:41:31 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/bits2prm.c	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,28 @@
+/*
+ * A cleaner reimplementation of AMR Bits2prm() function.
+ */
+
+#include "typedef.h"
+#include "namespace.h"
+#include "bitno.h"
+#include "bits2prm.h"
+
+void Bits2prm(enum Mode mode, const Word16 bits[], Word16 prm[])
+{
+	const Word16 *p = bits;
+	const Word16 *t = bitno[mode];
+	unsigned nparam = prmno[mode];
+	unsigned n, m, acc;
+
+	for (n = 0; n < nparam; n++) {
+		acc = 0;
+		for (m = 0; m < *t; m++) {
+			acc <<= 1;
+			if (*p)
+				acc |= 1;
+			p++;
+		}
+		prm[n] = acc;
+		t++;
+	}
+}