From patchwork Tue Aug 11 18:16:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11709489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D6A4913 for ; Tue, 11 Aug 2020 18:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D91B20771 for ; Tue, 11 Aug 2020 18:16:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lh0rUF2n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726165AbgHKSQ0 (ORCPT ); Tue, 11 Aug 2020 14:16:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbgHKSQ0 (ORCPT ); Tue, 11 Aug 2020 14:16:26 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5A0C06174A for ; Tue, 11 Aug 2020 11:16:25 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id o1so7215218plk.1 for ; Tue, 11 Aug 2020 11:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AErl5Ugw7OMWv6KhOS8L/zGN7BNkongguRT2IWZuj04=; b=lh0rUF2nk897OhG50BJ5e4HTN9HUCmTaA9yrWCgqm8lQI9j9vSuYd9iQdWFIpiGXNt FDyObqlu6oeoqI/BHpoCvC+PaFDNQbn3UULND7E3MT4sOIK6ZKAn4OyuFa4p0NOlmeG5 VR9KhKZ+FxFIGaI6GkTn/tVJ8880fwZyjyIrAs6714ajMQN3CFdkxxbMsp7ELa/uVFkW RaIG0gqi8N4m+CIWJ4+ZR12bz9kBphWNDs5bZLsrCAjVZKlzBCo54pHb+xHlOaz/qOsC l3f4AExCkoWA9O+XiKAq/OxWsgBB9Vnmfwah2srewD0I1DJoYcUcm3t9Xi48v8tvZTSM QmNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=AErl5Ugw7OMWv6KhOS8L/zGN7BNkongguRT2IWZuj04=; b=c9d1JYNZmqlc+nMMWVkxtp0A4CkrVHL0aON17enjyglCnlLo2TGElFDm9hIXwcGCWW 2Lh+6Kgw9dspsbtOl8JdF4S0OT1PsggN4WPP4HUUpZN6SaBxnDmY5h7ES/eNFy/TjwJG lRPsx/cQXSARV7alDidCdZBf1eXBP1YAyWaaLlLGZk14LTEW7DZdLac9QhWuMIfDVhDV SV8Y/CkPNJBY4cF9qKJbXmfofqUkQlLk/f5awNoHU7r0fq9ZBXhxjG7J8gJg/qibFKUu KY5Mo2ebNOwwKp4rGXvqewlnPvHfDKagNpQDCJV+wVZdcHmdKTzKz25qvA3Ol9WTLH33 sQ4A== X-Gm-Message-State: AOAM531CLH4B1ls1WyZFZFiCo1s0+lrMVEm/ke+7OHQ1WbqJyP1qDLVZ Yqe7/+VcH0QrDL2mORMFbtCv3qMB X-Google-Smtp-Source: ABdhPJwR/imoicwYWXXAMCVwjLxAumOFbkTuPwhUVi+x8l5QI61vp1PYIPCyrQng66q7Ol10ixGv9A== X-Received: by 2002:a17:90a:3ac3:: with SMTP id b61mr2231912pjc.1.1597169784516; Tue, 11 Aug 2020 11:16:24 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b22sm27011519pfb.213.2020.08.11.11.16.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 11:16:23 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH SBC 1/3] sbc: Add initial code for SSE primitives Date: Tue, 11 Aug 2020 11:16:21 -0700 Message-Id: <20200811181623.3683374-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz --- Makefile.am | 1 + sbc/sbc_primitives.c | 20 ++- sbc/sbc_primitives_sse.c | 361 +++++++++++++++++++++++++++++++++++++++ sbc/sbc_primitives_sse.h | 38 +++++ 4 files changed, 417 insertions(+), 3 deletions(-) create mode 100644 sbc/sbc_primitives_sse.c create mode 100644 sbc/sbc_primitives_sse.h diff --git a/Makefile.am b/Makefile.am index 342043d..7ff0c7d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -14,6 +14,7 @@ sbc_headers = sbc/sbc.h sbc_sources = sbc/sbc.c sbc/sbc_private.h sbc/sbc_math.h sbc/sbc_tables.h \ sbc/sbc_primitives.h sbc/sbc_primitives.c \ + sbc/sbc_primitives_sse.h sbc/sbc_primitives_sse.c \ sbc/sbc_primitives_mmx.h sbc/sbc_primitives_mmx.c \ sbc/sbc_primitives_iwmmxt.h sbc/sbc_primitives_iwmmxt.c \ sbc/sbc_primitives_neon.h sbc/sbc_primitives_neon.c \ diff --git a/sbc/sbc_primitives.c b/sbc/sbc_primitives.c index ff343cf..97a75be 100644 --- a/sbc/sbc_primitives.c +++ b/sbc/sbc_primitives.c @@ -33,6 +33,7 @@ #include "sbc_tables.h" #include "sbc_primitives.h" +#include "sbc_primitives_sse.h" #include "sbc_primitives_mmx.h" #include "sbc_primitives_iwmmxt.h" #include "sbc_primitives_neon.h" @@ -590,6 +591,21 @@ static int sbc_calc_scalefactors_j( return joint; } +static void sbc_init_primitives_x86(struct sbc_encoder_state *state) +{ + __builtin_cpu_init(); + +#ifdef SBC_BUILD_WITH_MMX_SUPPORT + if (__builtin_cpu_supports("mmx")) + sbc_init_primitives_mmx(state); +#endif + +#ifdef SBC_BUILD_WITH_SSE_SUPPORT + if (__builtin_cpu_supports("sse4.2")) + sbc_init_primitives_sse(state); +#endif +} + /* * Detect CPU features and setup function pointers */ @@ -614,9 +630,7 @@ void sbc_init_primitives(struct sbc_encoder_state *state) state->implementation_info = "Generic C"; /* X86/AMD64 optimizations */ -#ifdef SBC_BUILD_WITH_MMX_SUPPORT - sbc_init_primitives_mmx(state); -#endif + sbc_init_primitives_x86(state); /* ARM optimizations */ #ifdef SBC_BUILD_WITH_ARMV6_SUPPORT diff --git a/sbc/sbc_primitives_sse.c b/sbc/sbc_primitives_sse.c new file mode 100644 index 0000000..c2b729a --- /dev/null +++ b/sbc/sbc_primitives_sse.c @@ -0,0 +1,361 @@ +/* + * + * Bluetooth low-complexity, subband codec (SBC) library + * + * Copyright (C) 2020 Intel Corporation + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include "sbc.h" +#include "sbc_math.h" +#include "sbc_tables.h" + +#include "sbc_primitives_sse.h" + +/* + * SSE optimizations + */ + +#ifdef SBC_BUILD_WITH_SSE_SUPPORT + +static inline void sbc_analyze_four_sse(const int16_t *in, int32_t *out, + const FIXED_T *consts) +{ + static const SBC_ALIGNED int32_t round_c[2] = { + 1 << (SBC_PROTO_FIXED4_SCALE - 1), + 1 << (SBC_PROTO_FIXED4_SCALE - 1), + }; + __asm__ volatile ( + "movq (%0), %%mm0\n" + "movq 8(%0), %%mm1\n" + "pmaddwd (%1), %%mm0\n" + "pmaddwd 8(%1), %%mm1\n" + "paddd (%2), %%mm0\n" + "paddd (%2), %%mm1\n" + "\n" + "movq 16(%0), %%mm2\n" + "movq 24(%0), %%mm3\n" + "pmaddwd 16(%1), %%mm2\n" + "pmaddwd 24(%1), %%mm3\n" + "paddd %%mm2, %%mm0\n" + "paddd %%mm3, %%mm1\n" + "\n" + "movq 32(%0), %%mm2\n" + "movq 40(%0), %%mm3\n" + "pmaddwd 32(%1), %%mm2\n" + "pmaddwd 40(%1), %%mm3\n" + "paddd %%mm2, %%mm0\n" + "paddd %%mm3, %%mm1\n" + "\n" + "movq 48(%0), %%mm2\n" + "movq 56(%0), %%mm3\n" + "pmaddwd 48(%1), %%mm2\n" + "pmaddwd 56(%1), %%mm3\n" + "paddd %%mm2, %%mm0\n" + "paddd %%mm3, %%mm1\n" + "\n" + "movq 64(%0), %%mm2\n" + "movq 72(%0), %%mm3\n" + "pmaddwd 64(%1), %%mm2\n" + "pmaddwd 72(%1), %%mm3\n" + "paddd %%mm2, %%mm0\n" + "paddd %%mm3, %%mm1\n" + "\n" + "psrad %4, %%mm0\n" + "psrad %4, %%mm1\n" + "packssdw %%mm0, %%mm0\n" + "packssdw %%mm1, %%mm1\n" + "\n" + "movq %%mm0, %%mm2\n" + "pmaddwd 80(%1), %%mm0\n" + "pmaddwd 88(%1), %%mm2\n" + "\n" + "movq %%mm1, %%mm3\n" + "pmaddwd 96(%1), %%mm1\n" + "pmaddwd 104(%1), %%mm3\n" + "paddd %%mm1, %%mm0\n" + "paddd %%mm3, %%mm2\n" + "\n" + "movq %%mm0, (%3)\n" + "movq %%mm2, 8(%3)\n" + : + : "r" (in), "r" (consts), "r" (&round_c), "r" (out), + "i" (SBC_PROTO_FIXED4_SCALE) + : "cc", "memory"); +} + +static inline void sbc_analyze_eight_sse(const int16_t *in, int32_t *out, + const FIXED_T *consts) +{ + static const SBC_ALIGNED int32_t round_c[2] = { + 1 << (SBC_PROTO_FIXED8_SCALE - 1), + 1 << (SBC_PROTO_FIXED8_SCALE - 1), + }; + __asm__ volatile ( + "movq (%0), %%mm0\n" + "movq 8(%0), %%mm1\n" + "movq 16(%0), %%mm2\n" + "movq 24(%0), %%mm3\n" + "pmaddwd (%1), %%mm0\n" + "pmaddwd 8(%1), %%mm1\n" + "pmaddwd 16(%1), %%mm2\n" + "pmaddwd 24(%1), %%mm3\n" + "paddd (%2), %%mm0\n" + "paddd (%2), %%mm1\n" + "paddd (%2), %%mm2\n" + "paddd (%2), %%mm3\n" + "\n" + "movq 32(%0), %%mm4\n" + "movq 40(%0), %%mm5\n" + "movq 48(%0), %%mm6\n" + "movq 56(%0), %%mm7\n" + "pmaddwd 32(%1), %%mm4\n" + "pmaddwd 40(%1), %%mm5\n" + "pmaddwd 48(%1), %%mm6\n" + "pmaddwd 56(%1), %%mm7\n" + "paddd %%mm4, %%mm0\n" + "paddd %%mm5, %%mm1\n" + "paddd %%mm6, %%mm2\n" + "paddd %%mm7, %%mm3\n" + "\n" + "movq 64(%0), %%mm4\n" + "movq 72(%0), %%mm5\n" + "movq 80(%0), %%mm6\n" + "movq 88(%0), %%mm7\n" + "pmaddwd 64(%1), %%mm4\n" + "pmaddwd 72(%1), %%mm5\n" + "pmaddwd 80(%1), %%mm6\n" + "pmaddwd 88(%1), %%mm7\n" + "paddd %%mm4, %%mm0\n" + "paddd %%mm5, %%mm1\n" + "paddd %%mm6, %%mm2\n" + "paddd %%mm7, %%mm3\n" + "\n" + "movq 96(%0), %%mm4\n" + "movq 104(%0), %%mm5\n" + "movq 112(%0), %%mm6\n" + "movq 120(%0), %%mm7\n" + "pmaddwd 96(%1), %%mm4\n" + "pmaddwd 104(%1), %%mm5\n" + "pmaddwd 112(%1), %%mm6\n" + "pmaddwd 120(%1), %%mm7\n" + "paddd %%mm4, %%mm0\n" + "paddd %%mm5, %%mm1\n" + "paddd %%mm6, %%mm2\n" + "paddd %%mm7, %%mm3\n" + "\n" + "movq 128(%0), %%mm4\n" + "movq 136(%0), %%mm5\n" + "movq 144(%0), %%mm6\n" + "movq 152(%0), %%mm7\n" + "pmaddwd 128(%1), %%mm4\n" + "pmaddwd 136(%1), %%mm5\n" + "pmaddwd 144(%1), %%mm6\n" + "pmaddwd 152(%1), %%mm7\n" + "paddd %%mm4, %%mm0\n" + "paddd %%mm5, %%mm1\n" + "paddd %%mm6, %%mm2\n" + "paddd %%mm7, %%mm3\n" + "\n" + "psrad %4, %%mm0\n" + "psrad %4, %%mm1\n" + "psrad %4, %%mm2\n" + "psrad %4, %%mm3\n" + "\n" + "packssdw %%mm0, %%mm0\n" + "packssdw %%mm1, %%mm1\n" + "packssdw %%mm2, %%mm2\n" + "packssdw %%mm3, %%mm3\n" + "\n" + "movq %%mm0, %%mm4\n" + "movq %%mm0, %%mm5\n" + "pmaddwd 160(%1), %%mm4\n" + "pmaddwd 168(%1), %%mm5\n" + "\n" + "movq %%mm1, %%mm6\n" + "movq %%mm1, %%mm7\n" + "pmaddwd 192(%1), %%mm6\n" + "pmaddwd 200(%1), %%mm7\n" + "paddd %%mm6, %%mm4\n" + "paddd %%mm7, %%mm5\n" + "\n" + "movq %%mm2, %%mm6\n" + "movq %%mm2, %%mm7\n" + "pmaddwd 224(%1), %%mm6\n" + "pmaddwd 232(%1), %%mm7\n" + "paddd %%mm6, %%mm4\n" + "paddd %%mm7, %%mm5\n" + "\n" + "movq %%mm3, %%mm6\n" + "movq %%mm3, %%mm7\n" + "pmaddwd 256(%1), %%mm6\n" + "pmaddwd 264(%1), %%mm7\n" + "paddd %%mm6, %%mm4\n" + "paddd %%mm7, %%mm5\n" + "\n" + "movq %%mm4, (%3)\n" + "movq %%mm5, 8(%3)\n" + "\n" + "movq %%mm0, %%mm5\n" + "pmaddwd 176(%1), %%mm0\n" + "pmaddwd 184(%1), %%mm5\n" + "\n" + "movq %%mm1, %%mm7\n" + "pmaddwd 208(%1), %%mm1\n" + "pmaddwd 216(%1), %%mm7\n" + "paddd %%mm1, %%mm0\n" + "paddd %%mm7, %%mm5\n" + "\n" + "movq %%mm2, %%mm7\n" + "pmaddwd 240(%1), %%mm2\n" + "pmaddwd 248(%1), %%mm7\n" + "paddd %%mm2, %%mm0\n" + "paddd %%mm7, %%mm5\n" + "\n" + "movq %%mm3, %%mm7\n" + "pmaddwd 272(%1), %%mm3\n" + "pmaddwd 280(%1), %%mm7\n" + "paddd %%mm3, %%mm0\n" + "paddd %%mm7, %%mm5\n" + "\n" + "movq %%mm0, 16(%3)\n" + "movq %%mm5, 24(%3)\n" + : + : "r" (in), "r" (consts), "r" (&round_c), "r" (out), + "i" (SBC_PROTO_FIXED8_SCALE) + : "cc", "memory"); +} + +static inline void sbc_analyze_4b_4s_sse(struct sbc_encoder_state *state, + int16_t *x, int32_t *out, int out_stride) +{ + /* Analyze blocks */ + sbc_analyze_four_sse(x + 12, out, analysis_consts_fixed4_simd_odd); + out += out_stride; + sbc_analyze_four_sse(x + 8, out, analysis_consts_fixed4_simd_even); + out += out_stride; + sbc_analyze_four_sse(x + 4, out, analysis_consts_fixed4_simd_odd); + out += out_stride; + sbc_analyze_four_sse(x + 0, out, analysis_consts_fixed4_simd_even); + + __asm__ volatile ("emms\n"); +} + +static inline void sbc_analyze_4b_8s_sse(struct sbc_encoder_state *state, + int16_t *x, int32_t *out, int out_stride) +{ + /* Analyze blocks */ + sbc_analyze_eight_sse(x + 24, out, analysis_consts_fixed8_simd_odd); + out += out_stride; + sbc_analyze_eight_sse(x + 16, out, analysis_consts_fixed8_simd_even); + out += out_stride; + sbc_analyze_eight_sse(x + 8, out, analysis_consts_fixed8_simd_odd); + out += out_stride; + sbc_analyze_eight_sse(x + 0, out, analysis_consts_fixed8_simd_even); + + __asm__ volatile ("emms\n"); +} + +static inline void sbc_analyze_1b_8s_sse_even(struct sbc_encoder_state *state, + int16_t *x, int32_t *out, int out_stride); + +static inline void sbc_analyze_1b_8s_sse_odd(struct sbc_encoder_state *state, + int16_t *x, int32_t *out, int out_stride) +{ + sbc_analyze_eight_sse(x, out, analysis_consts_fixed8_simd_odd); + state->sbc_analyze_8s = sbc_analyze_1b_8s_sse_even; + + __asm__ volatile ("emms\n"); +} + +static inline void sbc_analyze_1b_8s_sse_even(struct sbc_encoder_state *state, + int16_t *x, int32_t *out, int out_stride) +{ + sbc_analyze_eight_sse(x, out, analysis_consts_fixed8_simd_even); + state->sbc_analyze_8s = sbc_analyze_1b_8s_sse_odd; + + __asm__ volatile ("emms\n"); +} + +static void sbc_calc_scalefactors_sse( + int32_t sb_sample_f[16][2][8], + uint32_t scale_factor[2][8], + int blocks, int channels, int subbands) +{ + static const SBC_ALIGNED int32_t consts[2] = { + 1 << SCALE_OUT_BITS, + 1 << SCALE_OUT_BITS, + }; + int ch, sb; + intptr_t blk; + for (ch = 0; ch < channels; ch++) { + for (sb = 0; sb < subbands; sb += 2) { + blk = (blocks - 1) * (((char *) &sb_sample_f[1][0][0] - + (char *) &sb_sample_f[0][0][0])); + __asm__ volatile ( + "movq (%4), %%mm0\n" + "1:\n" + "movq (%1, %0), %%mm1\n" + "pxor %%mm2, %%mm2\n" + "pcmpgtd %%mm2, %%mm1\n" + "paddd (%1, %0), %%mm1\n" + "pcmpgtd %%mm1, %%mm2\n" + "pxor %%mm2, %%mm1\n" + + "por %%mm1, %%mm0\n" + + "sub %2, %0\n" + "jns 1b\n" + + "movd %%mm0, %k0\n" + "psrlq $32, %%mm0\n" + "bsrl %k0, %k0\n" + "subl %5, %k0\n" + "movl %k0, (%3)\n" + + "movd %%mm0, %k0\n" + "bsrl %k0, %k0\n" + "subl %5, %k0\n" + "movl %k0, 4(%3)\n" + : "+r" (blk) + : "r" (&sb_sample_f[0][ch][sb]), + "i" ((char *) &sb_sample_f[1][0][0] - + (char *) &sb_sample_f[0][0][0]), + "r" (&scale_factor[ch][sb]), + "r" (&consts), + "i" (SCALE_OUT_BITS) + : "cc", "memory"); + } + } + __asm__ volatile ("emms\n"); +} + +void sbc_init_primitives_sse(struct sbc_encoder_state *state) +{ + state->sbc_analyze_4s = sbc_analyze_4b_4s_sse; + if (state->increment == 1) + state->sbc_analyze_8s = sbc_analyze_1b_8s_sse_odd; + else + state->sbc_analyze_8s = sbc_analyze_4b_8s_sse; + state->sbc_calc_scalefactors = sbc_calc_scalefactors_sse; + state->implementation_info = "SSE"; +} + +#endif diff --git a/sbc/sbc_primitives_sse.h b/sbc/sbc_primitives_sse.h new file mode 100644 index 0000000..8830cfd --- /dev/null +++ b/sbc/sbc_primitives_sse.h @@ -0,0 +1,38 @@ +/* + * + * Bluetooth low-complexity, subband codec (SBC) library + * + * Copyright (C) 2020 Intel Corporation + * + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __SBC_PRIMITIVES_SSE_H +#define __SBC_PRIMITIVES_SSE_H + +#include "sbc_primitives.h" + +#if defined(__GNUC__) && (defined(__i386__) || defined(__amd64__)) && \ + !defined(SBC_HIGH_PRECISION) && (SCALE_OUT_BITS == 15) + +#define SBC_BUILD_WITH_SSE_SUPPORT + +void sbc_init_primitives_sse(struct sbc_encoder_state *encoder_state); + +#endif + +#endif From patchwork Tue Aug 11 18:16:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11709491 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F95A618 for ; Tue, 11 Aug 2020 18:16:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EAC020782 for ; Tue, 11 Aug 2020 18:16:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gwS6XEWE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726173AbgHKSQ2 (ORCPT ); Tue, 11 Aug 2020 14:16:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbgHKSQ0 (ORCPT ); Tue, 11 Aug 2020 14:16:26 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21513C061787 for ; Tue, 11 Aug 2020 11:16:26 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id 74so8033131pfx.13 for ; Tue, 11 Aug 2020 11:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=UyGhDQx+Fo5M3xKnhn89uy/B9QHHoarx84rdgC8Xt+M=; b=gwS6XEWEeTvDROkJDmbr4xY4Tg27BRumNXRCORqrHqSqoDt5Q0sQr3EVf7uKeAO1P8 XcUTe7Tlbw7NO9Am9OcBDhUraqonqnm+rXhsGAvkHJJoiqjAr6W1yhlDgSFcXfZ3p36L +99t117x4HP4GNgamIs+bOfzpJOHh8/hb1/j4N3uxrDKyU4dvfxwPaVvtd8JE0j1vUmL R8nRZ3FRRbQ4ynxArrlfa0C+QSgD1bFg1qW/2unFlvVJD3JI8FQG10lgJhFgf6h8w6zZ IEHZBWo3d9boRE52D3Lk70vLXCA+7lsJ7RQfVTmIuG+r96vPTbKd/6mzk+pTii+4E/7H oJXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UyGhDQx+Fo5M3xKnhn89uy/B9QHHoarx84rdgC8Xt+M=; b=XWW7LrPmgQ0P8mqhEF4Gln6dy0D3Y0tcgmpHESyXndHwTCpFpRquQ7YRjkmsIpPVuE FFAWriZHVPyyG+Gyy0Wtq9Fav0kWBb+KL4xR/gR57nYZkD6ab1Czr1Wcj2A7CSZsuWzQ BQJsRHZvAPGLgW1XqnLECK3jQhHBupyU+M3wJaLBFFRNmVFp+c2Nyv5DcgOzb71GdblP K8gvgEdqBS1J6nCkQEZl1Cvq2lDoEuS1BNBj7HEK63vbpYWyvAL+hOvVtPomJXSBJvqe WA8AImFXYKLKNJCjoT/AdIeXHAx0fMSWSnBqdvPiema4YB1I3AYI9eVR4qkgLqyVP01f qvcQ== X-Gm-Message-State: AOAM531ShB8wEboKSq/Lge3ATitIfRBZIcHAqjpjTjLxWU0VqyyG9zO9 6l6cIP8pxeQ2oW7SC9rWGwajnC4d X-Google-Smtp-Source: ABdhPJy66salRM0DMojhugequGg5gyaD7WO4LX2t4ysUrV20lLsEegLyOGiDOlDYksQZYnNd/i+viA== X-Received: by 2002:a63:6fc3:: with SMTP id k186mr1864216pgc.109.1597169785295; Tue, 11 Aug 2020 11:16:25 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b22sm27011519pfb.213.2020.08.11.11.16.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 11:16:24 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH SBC 2/3] sbc/sbc_primitives_sse: Optimize sbc_analyze_4s Date: Tue, 11 Aug 2020 11:16:22 -0700 Message-Id: <20200811181623.3683374-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200811181623.3683374-1-luiz.dentz@gmail.com> References: <20200811181623.3683374-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes use 128 bit XMM registers whenever possible. $ time src/sbcenc_mmx -s 4 sin_4m.au > /dev/null real 0m1.073s user 0m1.039s sys 0m0.030s === After ==== $ time src/sbcenc -s 4 sin_4m.au > /dev/null real 0m1.049s user 0m1.000s sys 0m0.047s --- sbc/sbc_primitives_sse.c | 58 +++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/sbc/sbc_primitives_sse.c b/sbc/sbc_primitives_sse.c index c2b729a..6471bd5 100644 --- a/sbc/sbc_primitives_sse.c +++ b/sbc/sbc_primitives_sse.c @@ -38,48 +38,40 @@ static inline void sbc_analyze_four_sse(const int16_t *in, int32_t *out, const FIXED_T *consts) { - static const SBC_ALIGNED int32_t round_c[2] = { + static const SBC_ALIGNED int32_t round_c[4] = { + 1 << (SBC_PROTO_FIXED4_SCALE - 1), + 1 << (SBC_PROTO_FIXED4_SCALE - 1), 1 << (SBC_PROTO_FIXED4_SCALE - 1), 1 << (SBC_PROTO_FIXED4_SCALE - 1), }; __asm__ volatile ( - "movq (%0), %%mm0\n" - "movq 8(%0), %%mm1\n" - "pmaddwd (%1), %%mm0\n" - "pmaddwd 8(%1), %%mm1\n" - "paddd (%2), %%mm0\n" - "paddd (%2), %%mm1\n" + "movdqu (%0), %%xmm0\n" + "pmaddwd (%1), %%xmm0\n" + "paddd (%2), %%xmm0\n" "\n" - "movq 16(%0), %%mm2\n" - "movq 24(%0), %%mm3\n" - "pmaddwd 16(%1), %%mm2\n" - "pmaddwd 24(%1), %%mm3\n" - "paddd %%mm2, %%mm0\n" - "paddd %%mm3, %%mm1\n" + "movdqu 16(%0), %%xmm1\n" + "pmaddwd 16(%1), %%xmm1\n" + "paddd %%xmm1, %%xmm0\n" "\n" - "movq 32(%0), %%mm2\n" - "movq 40(%0), %%mm3\n" - "pmaddwd 32(%1), %%mm2\n" - "pmaddwd 40(%1), %%mm3\n" - "paddd %%mm2, %%mm0\n" - "paddd %%mm3, %%mm1\n" + "movdqu 32(%0), %%xmm1\n" + "pmaddwd 32(%1), %%xmm1\n" + "paddd %%xmm1, %%xmm0\n" "\n" - "movq 48(%0), %%mm2\n" - "movq 56(%0), %%mm3\n" - "pmaddwd 48(%1), %%mm2\n" - "pmaddwd 56(%1), %%mm3\n" - "paddd %%mm2, %%mm0\n" - "paddd %%mm3, %%mm1\n" + "movdqu 48(%0), %%xmm1\n" + "pmaddwd 48(%1), %%xmm1\n" + "paddd %%xmm1, %%xmm0\n" "\n" - "movq 64(%0), %%mm2\n" - "movq 72(%0), %%mm3\n" - "pmaddwd 64(%1), %%mm2\n" - "pmaddwd 72(%1), %%mm3\n" - "paddd %%mm2, %%mm0\n" - "paddd %%mm3, %%mm1\n" + "movdqu 64(%0), %%xmm1\n" + "pmaddwd 64(%1), %%xmm1\n" + "paddd %%xmm1, %%xmm0\n" + "\n" + "psrad %4, %%xmm0\n" + "\n" + "movdqa %%xmm0, %%xmm1\n" + "punpckhqdq %%xmm1, %%xmm1\n" + "movdq2q %%xmm0, %%mm0\n" + "movdq2q %%xmm1, %%mm1\n" "\n" - "psrad %4, %%mm0\n" - "psrad %4, %%mm1\n" "packssdw %%mm0, %%mm0\n" "packssdw %%mm1, %%mm1\n" "\n" From patchwork Tue Aug 11 18:16:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 11709493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 17EF3913 for ; Tue, 11 Aug 2020 18:16:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 005FF20782 for ; Tue, 11 Aug 2020 18:16:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pGYOIwgu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726235AbgHKSQ3 (ORCPT ); Tue, 11 Aug 2020 14:16:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbgHKSQ2 (ORCPT ); Tue, 11 Aug 2020 14:16:28 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 244A6C06174A for ; Tue, 11 Aug 2020 11:16:28 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 2so2270013pjx.5 for ; Tue, 11 Aug 2020 11:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZuY+8ttpOiBKxERHjcGAwCRhPfgHFomYRLZ89jgaUJI=; b=pGYOIwguiT71kLJwMKFDadxrolB7t7l/kGTIK2b4yFSdlxPgvkMgjf9/DiaFgmR1vT KakZFS77e/12pW8u564C9n+GHBN739eYceqxijFGEOJMtZJIYADja5N60VK3Um+oXsnD Om4fh393zfvyGHRrn0jHco6XC648XCw2GDFDCUV5YDNpPDdKvG0d/UmOu+1LInYe9d/I yJyJkin+1tmKTngljqfNlGT0xVNjSIbMcJ7Thi2p9NpuVnXSM9aD6TQ7zC7pJ0TmN4IX shHiR8yfl6rK0ecSN6zG9dhakEkpQ1ZW9roiral2lDG2UvBA7s59aOiDvywuIJ4ymK1T 7P4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZuY+8ttpOiBKxERHjcGAwCRhPfgHFomYRLZ89jgaUJI=; b=MW2LIUPodYv7IefrBjWKm5T9d+5Ob9gXRHJ4PmEnJvAO6q0CL+o6i6VyH7xX2VywHx 3zArB370RObge9pV2jOxO/KT0+gRmgMbDPOOho15vhk5oS9UhFKjzpxhk1pNeiJ2tJuf konBGUA0ENMsYl692PAXEP5mrklGBVrOwgcFjRYH76WOKnhHmQy4dhWFFtpvjWjnERwq eP6o68q1uniqteNFvfFVQCOPWlG6cxBSVR1VIRg+gr84XQTxyUOx3T2MJLtecZOq0whB RHnxcxTLyQ5lAFdZVcPZGPuvIZnfcC6okv1vu3l5BaCF5LAiuRu7OtpmKJOkH5eTWhsl 7Pvg== X-Gm-Message-State: AOAM530CHBVJo7H0/MZzIFXLX72oiE2klP4LlR4nOti2NaTLsSncG+fj oQJKlqVkbxAzL6Njz6XF3Tq8x7Ae X-Google-Smtp-Source: ABdhPJwZUTeF7RhbZyEQi55oHMef1OMcXh6lE6+MVhSd+UJJAE3rCM6nG0g9VqUusf0ybJjWj6926A== X-Received: by 2002:a17:90b:1116:: with SMTP id gi22mr2383393pjb.209.1597169786957; Tue, 11 Aug 2020 11:16:26 -0700 (PDT) Received: from localhost.localdomain (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id b22sm27011519pfb.213.2020.08.11.11.16.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2020 11:16:25 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH SBC 3/3] sbc/sbc_primitives_sse: Optimize sbc_analyze_8s Date: Tue, 11 Aug 2020 11:16:23 -0700 Message-Id: <20200811181623.3683374-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200811181623.3683374-1-luiz.dentz@gmail.com> References: <20200811181623.3683374-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes use 128 bit XMM registers whenever possible. $ time src/sbcenc_mmx -s 8 sin_64m.au > /dev/null real 0m1.064s user 0m1.012s sys 0m0.049s === After ==== $ time src/sbcenc -s 8 sin_64m.au > /dev/null real 0m1.032s user 0m0.996s sys 0m0.033s --- sbc/sbc_primitives_sse.c | 109 ++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 65 deletions(-) diff --git a/sbc/sbc_primitives_sse.c b/sbc/sbc_primitives_sse.c index 6471bd5..6f8eb49 100644 --- a/sbc/sbc_primitives_sse.c +++ b/sbc/sbc_primitives_sse.c @@ -96,80 +96,59 @@ static inline void sbc_analyze_four_sse(const int16_t *in, int32_t *out, static inline void sbc_analyze_eight_sse(const int16_t *in, int32_t *out, const FIXED_T *consts) { - static const SBC_ALIGNED int32_t round_c[2] = { + static const SBC_ALIGNED int32_t round_c[4] = { + 1 << (SBC_PROTO_FIXED8_SCALE - 1), + 1 << (SBC_PROTO_FIXED8_SCALE - 1), 1 << (SBC_PROTO_FIXED8_SCALE - 1), 1 << (SBC_PROTO_FIXED8_SCALE - 1), }; __asm__ volatile ( - "movq (%0), %%mm0\n" - "movq 8(%0), %%mm1\n" - "movq 16(%0), %%mm2\n" - "movq 24(%0), %%mm3\n" - "pmaddwd (%1), %%mm0\n" - "pmaddwd 8(%1), %%mm1\n" - "pmaddwd 16(%1), %%mm2\n" - "pmaddwd 24(%1), %%mm3\n" - "paddd (%2), %%mm0\n" - "paddd (%2), %%mm1\n" - "paddd (%2), %%mm2\n" - "paddd (%2), %%mm3\n" + "movdqu (%0), %%xmm0\n" + "movdqu 16(%0), %%xmm1\n" + "pmaddwd (%1), %%xmm0\n" + "pmaddwd 16(%1), %%xmm1\n" + "paddd (%2), %%xmm0\n" + "paddd (%2), %%xmm1\n" "\n" - "movq 32(%0), %%mm4\n" - "movq 40(%0), %%mm5\n" - "movq 48(%0), %%mm6\n" - "movq 56(%0), %%mm7\n" - "pmaddwd 32(%1), %%mm4\n" - "pmaddwd 40(%1), %%mm5\n" - "pmaddwd 48(%1), %%mm6\n" - "pmaddwd 56(%1), %%mm7\n" - "paddd %%mm4, %%mm0\n" - "paddd %%mm5, %%mm1\n" - "paddd %%mm6, %%mm2\n" - "paddd %%mm7, %%mm3\n" + "movdqu 32(%0), %%xmm2\n" + "movdqu 48(%0), %%xmm3\n" + "pmaddwd 32(%1), %%xmm2\n" + "pmaddwd 48(%1), %%xmm3\n" + "paddd %%xmm2, %%xmm0\n" + "paddd %%xmm3, %%xmm1\n" "\n" - "movq 64(%0), %%mm4\n" - "movq 72(%0), %%mm5\n" - "movq 80(%0), %%mm6\n" - "movq 88(%0), %%mm7\n" - "pmaddwd 64(%1), %%mm4\n" - "pmaddwd 72(%1), %%mm5\n" - "pmaddwd 80(%1), %%mm6\n" - "pmaddwd 88(%1), %%mm7\n" - "paddd %%mm4, %%mm0\n" - "paddd %%mm5, %%mm1\n" - "paddd %%mm6, %%mm2\n" - "paddd %%mm7, %%mm3\n" + "movdqu 64(%0), %%xmm2\n" + "movdqu 80(%0), %%xmm3\n" + "pmaddwd 64(%1), %%xmm2\n" + "pmaddwd 80(%1), %%xmm3\n" + "paddd %%xmm2, %%xmm0\n" + "paddd %%xmm3, %%xmm1\n" "\n" - "movq 96(%0), %%mm4\n" - "movq 104(%0), %%mm5\n" - "movq 112(%0), %%mm6\n" - "movq 120(%0), %%mm7\n" - "pmaddwd 96(%1), %%mm4\n" - "pmaddwd 104(%1), %%mm5\n" - "pmaddwd 112(%1), %%mm6\n" - "pmaddwd 120(%1), %%mm7\n" - "paddd %%mm4, %%mm0\n" - "paddd %%mm5, %%mm1\n" - "paddd %%mm6, %%mm2\n" - "paddd %%mm7, %%mm3\n" + "movdqu 96(%0), %%xmm2\n" + "movdqu 112(%0), %%xmm3\n" + "pmaddwd 96(%1), %%xmm2\n" + "pmaddwd 112(%1), %%xmm3\n" + "paddd %%xmm2, %%xmm0\n" + "paddd %%xmm3, %%xmm1\n" "\n" - "movq 128(%0), %%mm4\n" - "movq 136(%0), %%mm5\n" - "movq 144(%0), %%mm6\n" - "movq 152(%0), %%mm7\n" - "pmaddwd 128(%1), %%mm4\n" - "pmaddwd 136(%1), %%mm5\n" - "pmaddwd 144(%1), %%mm6\n" - "pmaddwd 152(%1), %%mm7\n" - "paddd %%mm4, %%mm0\n" - "paddd %%mm5, %%mm1\n" - "paddd %%mm6, %%mm2\n" - "paddd %%mm7, %%mm3\n" + "movdqu 128(%0), %%xmm2\n" + "movdqu 144(%0), %%xmm3\n" + "pmaddwd 128(%1), %%xmm2\n" + "pmaddwd 144(%1), %%xmm3\n" + "paddd %%xmm2, %%xmm0\n" + "paddd %%xmm3, %%xmm1\n" + "\n" + "psrad %4, %%xmm0\n" + "psrad %4, %%xmm1\n" "\n" - "psrad %4, %%mm0\n" - "psrad %4, %%mm1\n" - "psrad %4, %%mm2\n" - "psrad %4, %%mm3\n" + "movdqa %%xmm0, %%xmm2\n" + "movdqa %%xmm1, %%xmm3\n" + "punpckhqdq %%xmm2, %%xmm2\n" + "punpckhqdq %%xmm3, %%xmm3\n" + "movdq2q %%xmm0, %%mm0\n" + "movdq2q %%xmm2, %%mm1\n" + "movdq2q %%xmm1, %%mm2\n" + "movdq2q %%xmm3, %%mm3\n" "\n" "packssdw %%mm0, %%mm0\n" "packssdw %%mm1, %%mm1\n"