From ac5d4608a4bc3b7e29c6e7c48595a61443b00931 Mon Sep 17 00:00:00 2001 From: ratchov Date: Tue, 25 May 2021 08:06:12 +0000 Subject: [PATCH] Drop assembly for 24-bit fixed-point operations Now i386 compiler is smart enough to generate a single imul instruction per fixed-point multiplication. This change also allows 24-bit precision to be used on all archs (if -DADATA_BITS=24 is used). Tested on arm64 by Doug Moss , thanks Suggested and ok naddy@ --- usr.bin/aucat/dsp.h | 45 +------------------------------------------- usr.bin/sndiod/dsp.h | 45 +------------------------------------------- 2 files changed, 2 insertions(+), 88 deletions(-) diff --git a/usr.bin/aucat/dsp.h b/usr.bin/aucat/dsp.h index 2758147ce69..925ccf23abb 100644 --- a/usr.bin/aucat/dsp.h +++ b/usr.bin/aucat/dsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsp.h,v 1.7 2021/01/12 15:46:53 naddy Exp $ */ +/* $OpenBSD: dsp.h,v 1.8 2021/05/25 08:06:12 ratchov Exp $ */ /* * Copyright (c) 2012 Alexandre Ratchov * @@ -34,56 +34,13 @@ #if ADATA_BITS == 16 #define ADATA_MUL(x,y) (((int)(x) * (int)(y)) >> (ADATA_BITS - 1)) -#define ADATA_MULDIV(x,y,z) ((int)(x) * (int)(y) / (int)(z)) typedef short adata_t; #elif ADATA_BITS == 24 -#if defined(__i386__) && defined(__GNUC__) - -static inline int -fp24_mul(int x, int a) -{ - int res; - - asm volatile ( - "imull %2\n\t" - "shrdl $23, %%edx, %%eax\n\t" - : "=a" (res) - : "a" (x), "r" (a) - : "%edx" - ); - return res; -} - -static inline int -fp24_muldiv(int x, int a, int b) -{ - int res; - - asm volatile ( - "imull %2\n\t" - "idivl %3\n\t" - : "=a" (res) - : "a" (x), "d" (a), "r" (b) - ); - return res; -} - -#define ADATA_MUL(x,y) fp24_mul(x, y) -#define ADATA_MULDIV(x,y,z) fp24_muldiv(x, y, z); - -#elif defined(__amd64__) || defined(__sparc64__) - #define ADATA_MUL(x,y) \ ((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1))) -#define ADATA_MULDIV(x,y,z) \ - ((int)((long long)(x) * (long long)(y) / (long long)(z))) - -#else -#error "no 24-bit code for this architecture" -#endif typedef int adata_t; diff --git a/usr.bin/sndiod/dsp.h b/usr.bin/sndiod/dsp.h index 71cae26d9fe..539889c7f2e 100644 --- a/usr.bin/sndiod/dsp.h +++ b/usr.bin/sndiod/dsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dsp.h,v 1.9 2021/01/12 15:46:53 naddy Exp $ */ +/* $OpenBSD: dsp.h,v 1.10 2021/05/25 08:06:12 ratchov Exp $ */ /* * Copyright (c) 2012 Alexandre Ratchov * @@ -34,56 +34,13 @@ #if ADATA_BITS == 16 #define ADATA_MUL(x,y) (((int)(x) * (int)(y)) >> (ADATA_BITS - 1)) -#define ADATA_MULDIV(x,y,z) ((int)(x) * (int)(y) / (int)(z)) typedef short adata_t; #elif ADATA_BITS == 24 -#if defined(__i386__) && defined(__GNUC__) - -static inline int -fp24_mul(int x, int a) -{ - int res; - - asm volatile ( - "imull %2\n\t" - "shrdl $23, %%edx, %%eax\n\t" - : "=a" (res) - : "a" (x), "r" (a) - : "%edx" - ); - return res; -} - -static inline int -fp24_muldiv(int x, int a, int b) -{ - int res; - - asm volatile ( - "imull %2\n\t" - "idivl %3\n\t" - : "=a" (res) - : "a" (x), "d" (a), "r" (b) - ); - return res; -} - -#define ADATA_MUL(x,y) fp24_mul(x, y) -#define ADATA_MULDIV(x,y,z) fp24_muldiv(x, y, z); - -#elif defined(__amd64__) || defined(__sparc64__) - #define ADATA_MUL(x,y) \ ((int)(((long long)(x) * (long long)(y)) >> (ADATA_BITS - 1))) -#define ADATA_MULDIV(x,y,z) \ - ((int)((long long)(x) * (long long)(y) / (long long)(z))) - -#else -#error "no 24-bit code for this architecture" -#endif typedef int adata_t; -- 2.20.1