From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id B8B814ABA8 for ; Fri, 18 Jul 2025 14:52:14 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id A9E2368D28B; Fri, 18 Jul 2025 17:52:10 +0300 (EEST) Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 7DDC868D239 for ; Fri, 18 Jul 2025 17:52:04 +0300 (EEST) Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-60789b450ceso4158626a12.2 for ; Fri, 18 Jul 2025 07:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1752850323; x=1753455123; darn=ffmpeg.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=it9D5hcHsTSwogX09Nx42k9KRSxL5f/VV5m/2g8MAI0=; b=JGh6LFwrF1L6qi1hmvcicR3Rcv+ERtfm/40C3ZfIjjNqFs/tk2dqFkyu9zvF1NhBah zfU0PMRCWwDofAuIcr1YyvdZXrPr3Woha5UgKnWjmFzL9NP/0CuacXyzG3cO7HjUQlgp y+95NaNoHmFMiVsyzXtD2MNR3MFK0AJF3aQTy5oXdcs/1oe1tO0X9cC4D8Sy9S29rVxD NprnqZ6Vfx1Jdm2fjx6hEieI8SJhHUXNjX7Wb2fn8ex4Xk5b93sGbEKJZeh+TJ4WZJVd UnN3qLJ+X3rS3QE/ZBOmO9poTKRAgfZMyFmKDgGKRbgJluSYBdnqY5RvSPek0HqiEgvQ DDsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752850323; x=1753455123; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=it9D5hcHsTSwogX09Nx42k9KRSxL5f/VV5m/2g8MAI0=; b=YaUFKZnAg5q91O4mD271DgCyrJTS6VJKTYm1Gjd48j85ft7A1dT5CL6dL7+JXghTVu nnyNb6IylWDyDLw8ho4QZVokgqOqTyZr9repAHzBkeZZkUr1k//B4oJyPXlqjCCpFB7T iIC92OdxoL/GPnaXdeshYnAnlgVDknMnShYDpyuGMT9nHhSXtSATmDhCZmofO96WtYbh pC5v1e9Qb79Nglof0DHJAgSihnGuMkDvlIIDHvZMmeg6fyztJXrdC3igOO4SiotQbu1q lMSPPfQ/bL51zHdagor9JXHq60iaRTKv5z07IK0vUGZpBJirQ2s0FLopzVU+O5Dk4JCR +hlw== X-Gm-Message-State: AOJu0Yw9NSbFI7ESJPSkwTCs0D4dYKGFrC8JhdkYCaIKS08gq8OSX/bq D8+Cz9+5YXiqeX5JWPUWFJRaBHVx0zRxbLAYjItK5kYilIzvdGw0/Bu/V5gQowRJStD5Q5sg/I4 VT3GGM2FI3QH+cSnUqlqb0EfOxI0fHaFUGdDk X-Gm-Gg: ASbGncs+MXWxds+pQpTidYLBl9Y/UVepuBocX345CXA9vid+oGWRZN9TqFl3FL10I4h 6BsLIdF9kW2O2cOukuq2YEkJ96yqvhB8XPgWnc2/8IEZnO1HHrJBwHp0ZkYzHqs/6mZBHRbF4k7 VbY3Z0Fjx3bT/EGeTsfvBtzybY9KaVK7yfp90UcDL7ni8jC52UT25lvxel4QmDNsx79Lu5qNAFa 63C X-Google-Smtp-Source: AGHT+IElDd8WlIbGxA+eJwWokv4CWaIRt/F2K2gx1el/KQIKxGbATQ/0180+FbCnEiZecYbaD4oUCt2HwfOu1SnBMjw= X-Received: by 2002:a05:6402:1e92:b0:612:a86b:ac79 with SMTP id 4fb4d7f45d1cf-612a86bbc3bmr6049500a12.2.1752850322708; Fri, 18 Jul 2025 07:52:02 -0700 (PDT) MIME-Version: 1.0 References: <20250718095716.68346-1-ffmpeg@haasn.xyz> <20250718144653.GC312574@haasn.xyz> In-Reply-To: <20250718144653.GC312574@haasn.xyz> From: Kacper Michajlow Date: Fri, 18 Jul 2025 16:51:29 +0200 X-Gm-Features: Ac12FXy611Q-G1kPfzBI-dwj8O288CQhh-4OLJGCbPUIqrEWuKTZI_1udggJUFw Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] [PATCH v3 1/3] avfilter/vf_colordetect: add new color range detection filter 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: On Fri, 18 Jul 2025 at 14:47, Niklas Haas wrote: > > On Fri, 18 Jul 2025 14:38:04 +0200 Kacper Michajlow wrote: > > > +static inline int ff_detect_range_c(const uint8_t *data, ptrdiff_t stride, > > > + ptrdiff_t width, ptrdiff_t height, > > > + int mpeg_min, int mpeg_max) > > > +{ > > > + while (height--) { > > > + for (int x = 0; x < width; x++) { > > > + const uint8_t val = data[x]; > > > + if (val < mpeg_min || val > mpeg_max) > > > + return 1; > > > + } > > > + data += stride; > > > + } > > > + > > > + return 0; > > > +} > > > > You could process width as a whole to allow better vectorization. > > Assuming you don't process 10000x1 images, it will be faster on average. > > That's what I had in v1 of my patch, but it is significantly (50%) slower > on GCC, which prefers the version I have written above. > > There is the not insignificant point that this C routine is also being used > to handle remaining elements that don't fit into a multiple of the SIMD > kernel, for which the scalar code is actually preferred. Interesting. It's my fault, I didn't check. GCC really doesn't like bool/int there. If that function is important you could try: { + uint8_t min = mpeg_min, max = mpeg_max; while (height--) { + uint8_t out_of_range = 0; for (int x = 0; x < width; x++) { const uint8_t val = data[x]; - if (val < mpeg_min || val > mpeg_max) - return 1; + out_of_range |= val < min || val > max; } + if (out_of_range) + return 1; data += stride; } Side note, if you change function prototype to `uint8_t mpeg_min, uint8_t mpeg_max` directly, clang goes down to 267.6 ( 1.00x). Unless it's because of UB, lol. So, gcc scalar version is a bit slower in this case, but I think there is value in it, because it scales very nicely with -ftree-vectorize, even with sse2 target. Hopefully we will enable -ftree-vectorize by default soon, there is pending patch for that. before (gcc -fno-tree-vectorize) detect_range_8_c: 5537.4 ( 1.00x) detect_range_8_avx2: 149.7 (36.98x) detect_range_8_avx512: 111.2 (49.80x) after (gcc -fno-tree-vectorize) detect_range_8_c: 7709.0 ( 1.00x) detect_range_8_avx2: 137.6 (56.02x) detect_range_8_avx512: 104.2 (73.97x) after (gcc -ftree-vectorize --march=generic) detect_range_8_c: 657.0 ( 1.00x) detect_range_8_avx2: 161.7 ( 4.06x) detect_range_8_avx512: 116.5 ( 5.64x) after (gcc -ftree-vectorize --march=znver4) detect_range_8_c: 285.6 ( 1.00x) detect_range_8_avx2: 256.0 ( 1.12x) detect_range_8_avx512: 107.6 ( 2.65x) after (clang --march=generic) detect_range_8_c: 1769.0 ( 1.00x) detect_range_8_avx2: 231.8 ( 7.63x) detect_range_8_avx512: 96.6 (18.32x) after (clang --march=znver4) detect_range_8_c: 952.9 ( 1.00x) detect_range_8_avx2: 137.7 ( 6.92x) detect_range_8_avx512: 95.9 ( 9.94x) - Kacper _______________________________________________ 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".