From patchwork Thu Apr 20 17:53:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 41284 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp700740pzb; Thu, 20 Apr 2023 10:54:11 -0700 (PDT) X-Google-Smtp-Source: AKy350ZTOKLDdqZe77zb6L3I+iJjNF7jzwyqvTn/hqmSqbOAXPqd6o1E+eigKikjwb4WWJTKKQRu X-Received: by 2002:a17:907:8d13:b0:953:7d80:c40e with SMTP id tc19-20020a1709078d1300b009537d80c40emr4102234ejc.0.1682013250962; Thu, 20 Apr 2023 10:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682013250; cv=none; d=google.com; s=arc-20160816; b=teiuC1R+FsNyFBDsUXRyA0yBZIJu/cd7CNZDXaLuePCEtbtzPG4JZTfGa6LTWtl4ks CJQjt4XV/gysSQTa16TIkysyI0Iaz27hOD72ADYTGX2ElXAWtroMMq1wJtcuWJOiIKS3 l4N4w/UN/i6ozYUwSnhBTs3xQKYYN4ZN9lemlflx1c/EEMec6qCdgabDAKEDEREfTYGP DfjqJs7IgbyKpCm2No3DId526laB4rFHE09R7oaF+NzgZ7s0njjxYfHZtgqFDWgKvB5C f2sXWQU376zs7YGvJb3KZHU7/mYl6LFYIz/AQ/J0pnZjjBezKfppoEi/BxLXehlS0yyg NNUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=phjU7XPNbQQwkKXo+ZNrytOpqttk+4S0oOvA6S0kshg=; b=zrD7BZMM3arXUeTWAp9DZGGrpRY9ARcAr+AH69pKbD7bQvCjpra6mtzFdfBrmOijFL prx9SiqGdAc+8qgeerZ6twsml7Ea/OZjs+RS14yh62WQxIMwI35l0dR3UB2Sk8c8L4cu 2MNZFnN91Hc5Czt/lsuet7+IXXSEFesYz5qMEscK9LAddYWj5ie60MGH+ZBAIy4T/s3g RvMu+dHRRukB5zDmCm5tdlcZeB5nFzeDG/2jIpJwWXqpV9H1Q8RAAZONYNuVER+LhUUC shGysTgLQsdWrhiOaiHdgJ8acoxrJchpwZJraSPgBKufaoL/RKMjyRMWdPWPp4bYcuMP f7vw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x8-20020a170906134800b0094f7f53acafsi2031280ejb.527.2023.04.20.10.54.10; Thu, 20 Apr 2023 10:54:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 41DF968BED4; Thu, 20 Apr 2023 20:54:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CDF7D680463 for ; Thu, 20 Apr 2023 20:53:58 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id C6268C01C6 for ; Thu, 20 Apr 2023 20:53:57 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Apr 2023 20:53:56 +0300 Message-Id: <20230420175357.33836-1-remi@remlab.net> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] riscv/bswap: use compiler builtins X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 9Z6+YfNJ7NpX av_bswapXX() are used in context that expect exact size types, notably variable arguments to av_log(). On Linux RV64, uint_fast32_t is an unsigned long, so the current inline assembler does not work properly. Since GCC and Clang gained their byte-swap built-ins before they supported RISC-V, we can simply defer to them. As an added bonus, the compiler can do instruction scheduling, which it couldn't with the Zbb inline assembler. --- libavutil/riscv/bswap.h | 52 ++++------------------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/libavutil/riscv/bswap.h b/libavutil/riscv/bswap.h index de1429c0f7..ce75de974e 100644 --- a/libavutil/riscv/bswap.h +++ b/libavutil/riscv/bswap.h @@ -23,52 +23,10 @@ #include "config.h" #include "libavutil/attributes.h" -#if defined (__riscv_zbb) && (__riscv_zbb > 0) && HAVE_INLINE_ASM +#if defined (__GNUC__) || defined (__clang__) +#define av_bswap16 __builtin_bswap16 +#define av_bswap32 __builtin_bswap32 +#define av_bswap64 __builtin_bswap64 +#endif -static av_always_inline av_const uintptr_t av_bswap_xlen(uintptr_t x) -{ - uintptr_t y; - - __asm__("rev8 %0, %1" : "=r" (y) : "r" (x)); - return y; -} - -#define av_bswap16 av_bswap16 - -static av_always_inline av_const uint_fast16_t av_bswap16(uint_fast16_t x) -{ - return av_bswap_xlen(x) >> (__riscv_xlen - 16); -} - -#if (__riscv_xlen == 32) -#define av_bswap32 av_bswap_xlen -#define av_bswap64 av_bswap64 - -static av_always_inline av_const uint64_t av_bswap64(uint64_t x) -{ - return (((uint64_t)av_bswap32(x)) << 32) | av_bswap32(x >> 32); -} - -#else -#define av_bswap32 av_bswap32 - -static av_always_inline av_const uint_fast32_t av_bswap32(uint_fast32_t x) -{ - return av_bswap_xlen(x) >> (__riscv_xlen - 32); -} - -#if (__riscv_xlen == 64) -#define av_bswap64 av_bswap_xlen - -#else -#define av_bswap64 av_bswap64 - -static av_always_inline av_const uint_fast64_t av_bswap64(uint_fast64_t x) -{ - return av_bswap_xlen(x) >> (__riscv_xlen - 64); -} - -#endif /* __riscv_xlen > 64 */ -#endif /* __riscv_xlen > 32 */ -#endif /* __riscv_zbb */ #endif /* AVUTIL_RISCV_BSWAP_H */ From patchwork Thu Apr 20 17:53:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 41285 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4645:b0:e3:3194:9d20 with SMTP id eb5csp700811pzb; Thu, 20 Apr 2023 10:54:20 -0700 (PDT) X-Google-Smtp-Source: AKy350Ycjb+tHKKh7OSnHaW2ahtzkOjQD5EP6FFXisbAJwDiJB51w4q/BUKIsu3kOi3uVYkYIxAu X-Received: by 2002:a17:906:129b:b0:94f:317f:6a58 with SMTP id k27-20020a170906129b00b0094f317f6a58mr2151108ejb.35.1682013260301; Thu, 20 Apr 2023 10:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682013260; cv=none; d=google.com; s=arc-20160816; b=YNv18kFDEG5l4H/HddXyTzD/H5G1ivJdpnNU11U7VPmcD+KQVjfCQTFi7NgKxiwwh+ xref+e+U3kn3WcDZ+MFajzDZPpB9DdgYkEC8NMkE2KvAENdxlhvKROkxWJQow9SQeCRE 3IVMTQMT157nwNG4pBh8LV+CK1bnC3Um2S2cWjFumKXAGjWXiIluPZhrmUMNpUyQB/RW PEMYUbiwltgCbxbzTKb/54Ulgu5VvzPPLTtgxBmNadmsVi/SS99BZj5GVLMWXct6VFBc dmJOKSZsb7trCdLFWXcsOm95p857w5d3QHNNQrHRVsj3puIeJ13JQlXVk5IqsHlVcJUU rUcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=G/D0R2EwUlifmDgk2NxkkFKKnYekJ9GV1hUFabOLMMY=; b=TchoYybUvy9ASvCCeHCyn0Y8LEWHiderySkPkCYWQnLDpOSKVjSBRiBMC3hDDjOZmI qTR6QW5YojuSNTB/wbfB+X9DA4GcFvi2EQInAW6+MvBSkPcdoCwGNawmo44+6dpKWVYB tBf4tnqiR6ZgJMQbEVKvxKt9eFv5uygZabeg6qNxwTUPkhySlcgLxPXBGoXuBqXhuiwS Ly6cPjOwxPs+TbqZnwM1faClXrcFfWv6Xt9BlZERjXmt38Cx87Jm05HzpIAJsXly4WKj H4yQpMlibT4+GyRSLb6pyk3G+f+AvBttiPxPhiuXHMsKsrRQZllgT4A/n+LxO9xdm1lL hFTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id we21-20020a170907235500b009537be42c08si1924858ejb.798.2023.04.20.10.54.19; Thu, 20 Apr 2023 10:54:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ABB8568BF01; Thu, 20 Apr 2023 20:54:08 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from ursule.remlab.net (vps-a2bccee9.vps.ovh.net [51.75.19.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D02ED68BDFB for ; Thu, 20 Apr 2023 20:53:58 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id 0C67AC01C7 for ; Thu, 20 Apr 2023 20:53:58 +0300 (EEST) From: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Apr 2023 20:53:57 +0300 Message-Id: <20230420175357.33836-2-remi@remlab.net> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] riscv/intmath: use builtins for counting ones X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: afQ0juCgosqd As with the earlier bswap change, all versions of GCC and Clang that support RISC-V support the popcount built-ins, so we can just use them instead of inline assembler. --- libavutil/riscv/intmath.h | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/libavutil/riscv/intmath.h b/libavutil/riscv/intmath.h index 45bce9a0e7..ae9ee7775b 100644 --- a/libavutil/riscv/intmath.h +++ b/libavutil/riscv/intmath.h @@ -69,35 +69,13 @@ static av_always_inline av_const int av_clip_intp2_rvi(int a, int p) return b; } -#if defined (__riscv_zbb) && (__riscv_zbb > 0) && HAVE_INLINE_ASM - -#define av_popcount av_popcount_rvb -static av_always_inline av_const int av_popcount_rvb(uint32_t x) -{ - int ret; - +#if defined (__GNUC__) || defined (__clang__) +#define av_popcount __builtin_popcount #if (__riscv_xlen >= 64) - __asm__ ("cpopw %0, %1\n" : "=r" (ret) : "r" (x)); +#define av_popcount64 __builtin_popcountl #else - __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x)); +#define av_popcount64 __builtin_popcountll #endif - return ret; -} - -#if (__riscv_xlen >= 64) -#define av_popcount64 av_popcount64_rvb -static av_always_inline av_const int av_popcount64_rvb(uint64_t x) -{ - int ret; - -#if (__riscv_xlen >= 128) - __asm__ ("cpopd %0, %1\n" : "=r" (ret) : "r" (x)); -#else - __asm__ ("cpop %0, %1\n" : "=r" (ret) : "r" (x)); #endif - return ret; -} -#endif /* __riscv_xlen >= 64 */ -#endif /* __riscv_zbb */ #endif /* AVUTIL_RISCV_INTMATH_H */