aboutsummaryrefslogtreecommitdiff
path: root/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'utils.h')
-rw-r--r--utils.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/utils.h b/utils.h
index 715294e..9b9db2a 100644
--- a/utils.h
+++ b/utils.h
@@ -92,4 +92,11 @@ static int scalei_rem(int x, int srcmax, int dstmax, short *rem);
__value [ax] \
__modify [ax cx dx si]
+/** Sign extend x from b bits to 16. */
+static inline int16_t sign_extend(int16_t x, int b)
+{
+ int m = 16 - b;
+ return (x << m) >> m;
+}
+
#endif