From patchwork Fri Sep 9 15:48:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?R=C3=A9mi_Denis-Courmont?= X-Patchwork-Id: 37792 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp997815pzh; Fri, 9 Sep 2022 08:49:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR7sAFKZlNdTTVg4DXbYgFVkcqCXNTBhgGni89Lmq9s7YCUYnrgJZqgTzj3h37h+7GMWMPDH X-Received: by 2002:a17:907:6293:b0:769:9dfc:10eb with SMTP id nd19-20020a170907629300b007699dfc10ebmr10559064ejc.191.1662738575313; Fri, 09 Sep 2022 08:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662738575; cv=none; d=google.com; s=arc-20160816; b=V7grA1r6k5NZBgmxINdqGipapQ/FYRq5CieOmebf7Z3SknIfoxmTZrFEmSZgvvdkbb FIrL1N/R0hxyj8+h7wYgSSqa9tSSMJ/nTHliCVeuYRW7CUcWLUZg0ArErUrRQIJr06z7 vAbAeLSrvCW62W5akCDp076nMXXsVuFnFBWxn3Ly8iRbUe3SSZlntZ9q506wRDRgoyyx s9qmEnY/4FlVYC+l9NBkxt0ZfnlRhGLJ77PTbwIztrd4auOCXAcSDe58wGGjoKChtSK5 cBRY89c0X1u1hk3fcuJ9PyZHy2VRhk6bzrvHfQrrl2W52teMQgPV13WcZ9Ay8cTTkFPr 7DrQ== 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=jVp59uuj9jWqE1sqKr9zVxd+9IcgkUK8L4g/icvyTF4=; b=KQDMLdWAWY6uv3EXVD85RlQIMI+PCzr28kpeMc1l6Lhc6Gy3WI7NOnQHMZ7T2H+jjD UNR1jzmOpB6meUrzjBNMuk70dFspEUio4FHEh0bOUYYPt+bWYjZaFe5aIs5g7umc6D+6 z8iqP4/ByBInZyNyfCtQ+U9dRrw0nMGZzgXczNTjSPObMkicj1qICibxV1MmmUlSSFkb IK43JugLpF4kNKExSy4ZEBIxk659Zsc4qTaUx3hF7FZZV72gNCX6JdEAaboT8iAJ7Tm9 qmjlRUp7HKalYjTsU5VGNhza4A1WTYaoSOFZCAZQD9SZZp7QLsEEqlIC5mN+zMd0/y6x M0yQ== 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 l6-20020a056402124600b00448b8836866si679208edw.586.2022.09.09.08.49.34; Fri, 09 Sep 2022 08:49:35 -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 6C49168BAFE; Fri, 9 Sep 2022 18:49:09 +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 2E63568BB06 for ; Fri, 9 Sep 2022 18:49:00 +0300 (EEST) Received: from basile.remlab.net (localhost [IPv6:::1]) by ursule.remlab.net (Postfix) with ESMTP id D7589C00B0 for ; Fri, 9 Sep 2022 18:48:59 +0300 (EEST) From: remi@remlab.net To: ffmpeg-devel@ffmpeg.org Date: Fri, 9 Sep 2022 18:48:45 +0300 Message-Id: <20220909154859.68954-4-remi@remlab.net> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/18] lavu/riscv: byte-swap operations 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: zWRXngJYNDT9 From: RĂ©mi Denis-Courmont If the target supports the Basic bit-manipulation (Zbb) extension, then the REV8 instruction is available to reverse byte order. Note that this instruction only exists at the "XLEN" register size, so we need to right shift the result down to the data width. If Zbb is not supported, then this patchset does nothing. Support for run-time detection is left for the future. Currently, there are no bits in auxv/ELF HWCAP for Z-extensions, so there are no clean ways to do this. --- libavutil/bswap.h | 2 ++ libavutil/riscv/bswap.h | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 libavutil/riscv/bswap.h diff --git a/libavutil/bswap.h b/libavutil/bswap.h index 91cb79538d..4840ab433f 100644 --- a/libavutil/bswap.h +++ b/libavutil/bswap.h @@ -40,6 +40,8 @@ # include "arm/bswap.h" #elif ARCH_AVR32 # include "avr32/bswap.h" +#elif ARCH_RISCV +# include "riscv/bswap.h" #elif ARCH_SH4 # include "sh4/bswap.h" #elif ARCH_X86 diff --git a/libavutil/riscv/bswap.h b/libavutil/riscv/bswap.h new file mode 100644 index 0000000000..de1429c0f7 --- /dev/null +++ b/libavutil/riscv/bswap.h @@ -0,0 +1,74 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_RISCV_BSWAP_H +#define AVUTIL_RISCV_BSWAP_H + +#include +#include "config.h" +#include "libavutil/attributes.h" + +#if defined (__riscv_zbb) && (__riscv_zbb > 0) && HAVE_INLINE_ASM + +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 */