From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7107B4B715 for ; Wed, 12 Jun 2024 01:11:18 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8403468D8F6; Wed, 12 Jun 2024 04:11:09 +0300 (EEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1FC6468D8E7 for ; Wed, 12 Jun 2024 04:11:03 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f4c7b022f8so58235765ad.1 for ; Tue, 11 Jun 2024 18:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718154661; x=1718759461; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=MWcmTkVkv/bkOHh9yWBmEYRfczd7tu8fD6Sg715YCWo=; b=IT70LUTXsK4Fi7tFTMwReFvBq45rTV4gDsd9KVtbBatWDCk2d5/udO5Z9ExQ51zOPw fcAStUc94ciziEqmEQOB2UDhDtZIFSxzF/cnaaWy92NQWeR+qZAnIGvtKZ0EWl1pHRhN Gana8NdRqAmC9IL2mQcfEmCn8AbLX154c1qie/zkBQZOip7EuwDWPf7Uh7jB5nbZwYdl bO/dfe/m4ec0QpF0TN88ckE9GClwm4MK0Zph7KF+1TcM3id3JwNb/iDiy1RxFA4uzM1F KzHfTRDFOh0k9VTv9Vac8iUMT3R94i3cSaRxtjWEsKSCPJR5+hxLI9ESPNukXQz3NHzx 8FGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718154661; x=1718759461; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MWcmTkVkv/bkOHh9yWBmEYRfczd7tu8fD6Sg715YCWo=; b=gycYHZ2nwgdZ+ZI22FnOxcEvO8qg10VyN16D08fOZ4zznIMeKk0Oor/z7s3IuivtTW tdSvQg8Z9EYOhnuuoGUswANup2j1oHRXciDcUl9iGQao/GW4DjabmHdg3oA+BJYdZNO5 IQUzlE32EL/8i002SXsgMymaKqduPMvnEaCLnOQZGmQjq91qqKvv+soXqBjI0ilbcCIM +6EjKuOt7OSCA667HK92iJmKZgJgBtYg1miHGPb374t2hQOCCf/+KdspxVfjzHvYJWNF mRc5jNX7L182M3ifNZcZ14hcelqQGwr6cvzLTS+TyvOB+O4djW6CiicSPCL0f3TgD2Gd 2DLw== X-Gm-Message-State: AOJu0YwX+mlYcX0YK//G2UhXhcW0tMgrLPPM2MosmMLV5D8H6M6ojMJW vJToTZd+Y52rGkk3VTyacnlj2n+fhuPuVgYbahiNici/harBTbyNBQr7vA== X-Google-Smtp-Source: AGHT+IGycUwwV5gNi02SupRK5OUTvXaciDlR4ryGydpBNHic/8D2Jjlsa55Kalr+52Nt8M83vHTOkg== X-Received: by 2002:a17:902:a583:b0:1f7:2dca:ea65 with SMTP id d9443c01a7336-1f83b75a683mr4552095ad.69.1718154660945; Tue, 11 Jun 2024 18:11:00 -0700 (PDT) Received: from localhost.localdomain ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f71a9beb9asm39932185ad.121.2024.06.11.18.10.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 18:10:59 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 11 Jun 2024 22:11:00 -0300 Message-ID: <20240612011101.7641-2-jamrial@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612011101.7641-1-jamrial@gmail.com> References: <20240612011101.7641-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3 v2] avutil/common: assert that bit position in av_zero_extend is valid 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: James Almer --- libavutil/common.h | 5 ++++- libavutil/x86/intmath.h | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libavutil/common.h b/libavutil/common.h index fa2333d181..1f5db42cb2 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -286,11 +286,14 @@ static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p) /** * Clear high bits from an unsigned integer starting with specific bit position * @param a value to clip - * @param p bit position to clip at + * @param p bit position to clip at. Must be between 0 and 31. * @return clipped value */ static av_always_inline av_const unsigned av_zero_extend_c(unsigned a, unsigned p) { +#if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 + if (p > 31) abort(); +#endif return a & ((1U << p) - 1); } diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h index 821a06ab66..4893a1f1b4 100644 --- a/libavutil/x86/intmath.h +++ b/libavutil/x86/intmath.h @@ -82,7 +82,16 @@ static av_always_inline av_const int ff_ctzll_x86(long long v) #if defined(__BMI2__) #if AV_GCC_VERSION_AT_LEAST(5,1) +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 +#define av_zero_extend av_zero_extend_bmi2 +static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p) +{ + if (p > 31) abort(); + return __builtin_ia32_bzhi_si(a, p); +} +#else #define av_zero_extend __builtin_ia32_bzhi_si +#endif #elif HAVE_INLINE_ASM /* GCC releases before 5.1.0 have a broken bzhi builtin, so for those we * implement it using inline assembly @@ -90,8 +99,11 @@ static av_always_inline av_const int ff_ctzll_x86(long long v) #define av_zero_extend av_zero_extend_bmi2 static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsigned p) { +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 + if (p > 31) abort(); +#endif if (av_builtin_constant_p(p)) - return a & ((1 << p) - 1); + return a & ((1U << p) - 1); else { unsigned x; __asm__ ("bzhi %2, %1, %0 \n\t" : "=r"(x) : "rm"(a), "r"(p)); -- 2.45.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".