3094 Commits

Author SHA1 Message Date
Frank Barchard
42eb3a552f [libyuv] Add ScaleRowDown2Box_AVX512BW with tail masking
Add AVX-512BW implementations of ScaleRowDown2_AVX512BW,
ScaleRowDown2Linear_AVX512BW, ScaleRowDown2Box_AVX512BW, and
ScaleRowDown2Box_Odd_AVX512BW in scale_gcc.cc.

Use 512-bit zmm vectors (64 source bytes -> 32 destination pixels per
iteration) with vpmovwb narrowing stores, and handle remaining 1..31
destination pixels in-place using hardware mask register k1 (vmovdqu16
zero-masked loads for 2-byte source pixel pairs and vpmovwb masked
narrowing store), eliminating the ScaleRowDown2*_Any_AVX2 fallback on
AVX-512BW CPUs.

Hook up the new row functions in ScalePlaneDown2 (source/scale.cc) and
I420Blend (source/planar_functions.cc).

I420ScaleDownBy2_Box
(LIBYUV_WIDTH=638 LIBYUV_HEIGHT=360 LIBYUV_REPEAT=2000):
CPU                      SSSE3    AVX2  AVX512  512/AVX2
AMD Turin (Zen 5)           57      62      36     1.72x
Intel Granite Rapids        76      76      45     1.69x
AMD Genoa (Zen 4)           85      84      50     1.68x
Intel Sapphire Rapids       68      73      44     1.66x
Intel Emerald Rapids        69      66      48     1.38x
Intel Ice Lake             128     128      96     1.33x
Intel Skylake-X            153     150     121     1.24x
AMD Milan (Zen 3)           95      95      96         -
Intel Haswell              193     172     162         -

R=rrwinterton@gmail.com

Bug: libyuv:960
Test: libyuv_unittest --gtest_filter=*ScalePlaneDown2*:*I420Blend*
Change-Id: Ifbfcc4042c50d28022b12cb807dad56e66e7f301
TAG=agy
CONV=5f01827f-2aa8-4718-b8c1-7f282730918e
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8504320
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-10-05 10:56:34 -07:00
Philipp Hancke
aa6cedb39c Add a box filter to ScaleUV
kFilterBox only had 1/2 and 1/4 fast paths. Everything else fell
through to ScaleUVSimple and point sampled, so NV12 chroma was
unfiltered where I420 was not. 13.6 dB against 50.2 dB at 3x.

ScaleUVBox mirrors ScalePlaneBox. Row accumulation reuses ScaleAddRow
and its SIMD variants, since summing is position wise and an
interleaved row is just src_cols * 2 samples. Only the column pass,
which sums U and V at a stride of 2, is new.

Output is now byte identical to the I420 path. Tests compare against
ScalePlane rather than C against SIMD, which is what missed this.

Bug: libyuv:564129034
Change-Id: I26221f5435dbfc845ad2fc13aa347ef56ccf7bc6
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8426668
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
2026-10-02 15:37:21 -07:00
Frank Barchard
67b3c0dad8 Compare AVX512BW and AVX2, intrinsics for Visual C and ROWWIN
- Add HammingDistance_AVX512BW, SumSquareError_AVX512BW and
  HashDjb2_AVX512BW for 32 and 64 bit, as inline assembly in
  compare_gcc.cc and intrinsics in compare_win.cc.
- AVX512BW processes 64 bytes per loop with full vectors, and the
  remainder of 1 to 63 bytes with one masked load, so compare.cc passes
  any count and does not use C for the remainder. HashDjb2 loads the
  remainder into the high bytes, ending at src + count, so the same
  33 ^ (63 - i) multipliers apply, and multiplies the hash by 33 ^ n.
- Add SumSquareError_AVX2 and HashDjb2_AVX2 to compare_gcc.cc and
  HammingDistance_AVX2 to compare_win.cc, so both files have the same
  functions. Enable AVX2 in compare_gcc.cc for gcc as well as clang.
- HashDjb2 AVX2 and AVX512BW split the 32 bit multipliers 33 ^ i into
  16 bit halves and use vpmaddwd, instead of vpmulld which is 2 uops
  with 10 cycle latency. Bytes are zero extended with vpmovzxbw from
  memory. The hash = hash * 33 ^ 64 + sum dependency uses scalar imul
  instead of vpmulld. AVX2 does 64 bytes per horizontal add.
- Port compare_win.cc from 32 bit Visual C inline assembly to
  intrinsics and enable it for Visual C 32/64 bit and
  LIBYUV_ENABLE_ROWWIN, which MemorySanitizer also enables. Visual C 64
  bit and MemorySanitizer previously used C.
- Fix HammingDistance_SSSE3 and HammingDistance_AVX2 to allow unaligned
  pointers. They used movdqa and crashed on unaligned src_a.
- Add TestCompareAnyCount to test every count from 0 to 321, aligned
  and unaligned, ending at the end of a page.

Functions available:
Function                   compare_gcc   compare_win
                           32/64 bit     32/64 bit
HammingDistance_SSE42      asm           intrinsics
HammingDistance_SSSE3      asm           -
HammingDistance_AVX2       asm           intrinsics
HammingDistance_AVX512BW   asm           intrinsics
SumSquareError_SSE2        asm           intrinsics
SumSquareError_AVX2        asm           intrinsics
SumSquareError_AVX512BW    asm           intrinsics
HashDjb2_SSE41             asm           intrinsics
HashDjb2_AVX2              asm           intrinsics
HashDjb2_AVX512BW          asm           intrinsics

Performance, 1280x720, LIBYUV_REPEAT=1000, best of 3, ms.
Before is main (SSE, and AVX2 Hamming only, in compare_gcc).

BenchmarkDjb2_Opt        main   gcc     gcc     win     win
                                AVX2    AVX512  AVX2    AVX512
Intel Haswell            179    77      -       75      -
AMD Milan (Zen 3)        101    35      -       35      -
Intel Skylake-X          214    63      55      67      59
Intel Ice Lake           191    51      47      52      49
Intel Sapphire Rapids    175    39      39      38      39
Intel Granite Rapids     170    40      38      40      38
AMD Genoa (Zen 4)        91     34      37      34      38
AMD Turin (Zen 5)        80     29      22      28      23
C                        502 to 669

BenchmarkSumSquareError  main   gcc     gcc     win     win
_Opt                            AVX2    AVX512  AVX2    AVX512
Intel Haswell            79     37      -       38      -
AMD Milan (Zen 3)        47     24      -       25      -
Intel Skylake-X          78     32      26      34      24
Intel Ice Lake           86     43      23      43      22
Intel Sapphire Rapids    48     24      21      24      22
Intel Granite Rapids     47     23      21      23      21
AMD Genoa (Zen 4)        50     25      21      25      21
AMD Turin (Zen 5)        57     28      13      28      14
C                        154 to 425

Testing:
LIBYUV_WIDTH=1279 LIBYUV_HEIGHT=719 out/Release/libyuv_unittest \
  --gtest_filter='*Compare*:*Djb2*:*Hamming*:*SumSquare*:*Psnr*:*Ssim*'
With out/Release, out/Release_x86, out/rowwin, out/rowwin_x86 and
out/msan, with LIBYUV_DISABLE_AVX512BW and LIBYUV_DISABLE_AVX2, and
LIBYUV_WIDTH of 1, 31 to 33, 63 to 65, 95, 127, 129 and 200. Under
sde64 -skx for AVX512BW with out/Release and out/rowwin.
Built out/android_x86.

Bug: None
Change-Id: Ief197d546daca3db02ee1503d4649f4c755eb189
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8504717
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-10-02 15:30:05 -07:00
Frank Barchard
bad060c3a5 Rotate intrinsics for Visual C, ROWWIN and 32 bit x86
- Port rotate_gcc.cc to intrinsics in rotate_win.cc: TransposeWx8_SSSE3,
  TransposeUVWx8_SSE2, TransposeWx16_AVX2, TransposeUVWx16_AVX2,
  Transpose4x4_32_SSE2, Transpose4x4_32_AVX2, and for 64 bit,
  TransposeWx16_AVX512BW and TransposeUVWx16_AVX512BW.
- Remove the 32 bit Visual C inline assembly.
- Enable rotate_win.cc for Visual C 32/64 bit, LIBYUV_ENABLE_ROWWIN,
  which MemorySanitizer also enables, and all 32 bit x86 compilers.
  Visual C 64 bit previously used C.
- rotate_gcc.cc is now 64 bit only. 32 bit gcc and clang only had an
  8x8 TransposeWx8_SSSE3 and Transpose4x4_32, because the UV and AVX2
  inline assembly uses xmm8..xmm15, so 32 bit NV12 rotate used C.
  Remove the 32 bit TransposeWx8_SSSE3 inline assembly.
- Add a target("sse2") attribute to the SSE2 intrinsics so gcc and
  clang build them when the baseline lacks SSE2, such as
  -march=pentium3.
- Disable the generic x86 scale_row.h and compare_row.h HAS_ macros for
  32 bit LIBYUV_ENABLE_ROWWIN, as is done for 64 bit. scale_gcc.cc and
  compare_gcc.cc are disabled for ROWWIN and scale_win.cc and
  compare_win.cc require _MSC_VER, so out/rowwin_x86 failed to link with
  undefined symbols such as ScaleARGBCols_SSE2 and HashDjb2_SSE41.
- TransposeWx8_SSSE3 and TransposeUVWx8_SSE2 share a 16x8 helper.
- TransposeWx8_SSSE3 requires a multiple of 16 on all platforms.
- Byte transposes use a shared helper with dst_a / dst_b outputs so
  2, 3 and 4 channel variants can reuse the same shuffles.

Functions available:
Function                   rotate_gcc   rotate_win   rotate_win
                           64 bit       64 bit       32 bit
TransposeWx8_SSSE3         asm          intrinsics   intrinsics
TransposeUVWx8_SSE2        asm          intrinsics   intrinsics
TransposeWx16_AVX2         asm          intrinsics   intrinsics
TransposeUVWx16_AVX2       asm          intrinsics   intrinsics
Transpose4x4_32_SSE2       asm          intrinsics   intrinsics
Transpose4x4_32_AVX2       asm          intrinsics   intrinsics
TransposeWx16_AVX512BW     asm          intrinsics   -
TransposeUVWx16_AVX512BW   asm          intrinsics   -

32 bit x86 Linux clang on AMD Milan (Zen 3), ms
(LIBYUV_WIDTH=1280 LIBYUV_HEIGHT=720 LIBYUV_REPEAT=2000):
                     C      Before   After SSE2   After AVX2
I420Rotate90_Opt     944    321      322          220
NV12Rotate90_Opt     1412   935      315          232

Testing:
for w in 1 2 3 7 8 9 15 16 17 23 24 31 32 33 64 65 1279 1280; do
  for h in 1 7 8 15 16 17 24 31 32 33 719; do
    LIBYUV_WIDTH=$w LIBYUV_HEIGHT=$h out/rowwin/libyuv_unittest \
      --gtest_filter='*Rotate*:*Transpose*'
  done
done
Repeated with LIBYUV_DISABLE_AVX2=1, LIBYUV_DISABLE_AVX512BW=1, with
out/Release and out/Release_x86, under sde64 -skx for AVX512BW, and
with out/msan (is_msan = true) and out/rowwin_x86
(target_cpu = "x86", libyuv_enable_rowwin = true). Built out/android_x86
(target_os = "android", target_cpu = "x86"). Compiled rotate_win.cc
with g++ and clang++ -m32 -march=pentium3.

Bug: None
Change-Id: Ic70c4f0b7eb46b1b8522a1eba851dac5f506ec3e
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8499394
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-10-01 20:39:30 -07:00
Frank Barchard
20b0a91bc1 Transpose 16x16 for AVX2
- TransposeWx16_AVX2 and TransposeUVWx16_AVX2 using 2 lanes of 8 ymm
  registers, with Any for tail.
- Move TransposeUVWx16_C to rotate_common.cc and pass the C function to
  TUVANY, so the LSX 16 row Any version transposes all 16 rows.

I420Rotate90_Opt (LIBYUV_WIDTH=1279 LIBYUV_HEIGHT=719 LIBYUV_REPEAT=1000):
CPU                      SSSE3   AVX2  AVX512  AVX2 x   512 x
Intel Haswell             1812    916     945   1.98x   1.92x
AMD Milan (Zen 3)          177    118     118   1.50x   1.50x
Intel Granite Rapids       245    186     186   1.32x   1.32x
Intel Emerald Rapids       246    193     176   1.27x   1.40x
Intel Sapphire Rapids      278    233     225   1.19x   1.24x
Intel Ice Lake             308    213     221   1.45x   1.39x
Intel Skylake-X            365    267     246   1.37x   1.48x
AMD Turin (Zen 5)          106     75      75   1.41x   1.41x
AMD Genoa (Zen 4)          149     98      93   1.52x   1.60x
AMD Venice (Zen 6)         106     74      73   1.43x   1.45x

NV12Rotate90_Opt (LIBYUV_WIDTH=1279 LIBYUV_HEIGHT=719 LIBYUV_REPEAT=1000):
CPU                      SSSE3   AVX2  AVX512  AVX2 x   512 x
Intel Haswell             1771    963     935   1.84x   1.89x
AMD Milan (Zen 3)          173    118     118   1.47x   1.47x
Intel Granite Rapids       275    189     186   1.46x   1.48x
Intel Emerald Rapids       256    188     179   1.36x   1.43x
Intel Sapphire Rapids      286    232     218   1.23x   1.31x
Intel Ice Lake             309    208     218   1.49x   1.42x
Intel Skylake-X            380    269     251   1.41x   1.51x
AMD Turin (Zen 5)          112     74      73   1.51x   1.53x
AMD Genoa (Zen 4)          146     97      93   1.51x   1.57x
AMD Venice (Zen 6)         114     73      72   1.56x   1.58x

Bug: None
Change-Id: Ia89219e3336f39a817aa662e1452824d781664a3
TAG=agy
CONV=bea53b37-b2bf-46fa-9e44-a708b438fabc
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8489456
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-10-01 17:31:33 -07:00
Frank Barchard
98fa761478 Rotate for AVX512
- TransposeWx16_AVX512BW and TransposeUVWx16_AVX512BW
- tail masking instead of 'Any' to odd source width

I420Rotate90_Opt (LIBYUV_WIDTH=1279 LIBYUV_HEIGHT=719 LIBYUV_REPEAT=1000):
CPU                     Before     After     Speedup
Intel Emerald Rapids    249 ms     182 ms      1.37x
Intel Ice Lake          311 ms     234 ms      1.33x
Intel Granite Rapids    246 ms     186 ms      1.32x
Intel Sapphire Rapids   274 ms     226 ms      1.21x

NV12Rotate90_Opt (LIBYUV_WIDTH=1279 LIBYUV_HEIGHT=719 LIBYUV_REPEAT=1000):
CPU                     Before     After     Speedup
Intel Granite Rapids    263 ms     181 ms      1.45x
Intel Emerald Rapids    257 ms     180 ms      1.43x
Intel Ice Lake          311 ms     233 ms      1.33x
Intel Sapphire Rapids   282 ms     222 ms      1.27x

Bug: None
Change-Id: Ibe0df79275099dc06bf4218484a24732cd7fb9b5
TAG=agy
CONV=bea53b37-b2bf-46fa-9e44-a708b438fabc
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8497726
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-10-01 16:38:23 -07:00
Frank Barchard
eee4597984 Fix _M_X86 to _M_IX86
Fix _M_X86 to _M_IX86 for Visual C 32 bit

Visual C defines _M_IX86 for 32 bit x86, not _M_X86.
row.h and row_win.cc tested _M_X86, so a real 32 bit Visual C build
got neither USE_ROW_WIN nor USE_ROW_GCC, row_win.cc compiled to nothing,
and the HAS_*_AVX2 defines for all x86 platforms were skipped.
clang-cl and Android x86 are unaffected since clang defines __i386__.

Testing:
ninja -C out/Release libyuv_unittest && out/Release/libyuv_unittest
ninja -C out/Release_x86 libyuv_unittest && out/Release_x86/libyuv_unittest
ninja -C out/rowwin libyuv_unittest && out/rowwin/libyuv_unittest
blaze test --config=windows_x86 //third_party/libyuv:libyuv_test
blaze build --config=android_x86 //third_party/libyuv:libyuv

Bug: None
Change-Id: I0f90c03855f2981040ab4f250cd2facc9ef47ac0
TAG=agy
CONV=bea53b37-b2bf-46fa-9e44-a708b438fabc
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8499834
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
2026-10-01 02:50:39 -07:00
Frank Barchard
18835bfb35 ARGBToRGB24 AVX512 with tail masking
Bug: None
Change-Id: I7590c66940b5354ca0fdd8ff120392434d2785d7
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8490011
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-29 16:15:44 -07:00
Frank Barchard
b25fa89920 InterpolateRow_AVX512BW with tail masking
I420ScaleTo569x480_Bilinear (LIBYUV_WIDTH=569 LIBYUV_REPEAT=5000):
CPU                     AVX2      AVX512     Speedup
Intel Emerald Rapids   124 ms      63 ms      1.97x
Intel Sapphire Rapids  134 ms      69 ms      1.94x
Intel Skylake-X        219 ms     129 ms      1.70x
Intel Granite Rapids   124 ms      76 ms      1.63x
Intel Ice Lake         164 ms     101 ms      1.62x

Bug: None
Change-Id: I7a10446eb4dbcebae68380c2a186d4e3badec551
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8483371
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-29 11:22:47 -07:00
Frank Barchard
39445fa162 [libyuv] Fix RISC-V CMake/GN/Bazel builds and C compiler driver linking
- Use -fno-tree-vectorize and -fno-tree-slp-vectorize instead of
  Clang-only -fno-vectorize and -fno-slp-vectorize in CMakeLists.txt,
  riscv-clang.cmake, BUILD.gn, and BUILD.bazel for GCC and Clang
  compatibility.
- Split row_rvv.cc and scale_rvv.cc into a dedicated libyuv_rvv target
  in BUILD.gn and define LIBYUV_RVV so callers in row.h and scale_row.h
  can dispatch to RVV kernels when built without global -march=rv64gcv.
- Guard the x86 AVX512-BF16 vdpphps inline assembly probe in
  util/cpuid.c with __i386__ / __x86_64__.
- Replace new/delete and new[]/delete[] with calloc/malloc/free in
  source/mjpeg_decoder.cc and util/yuvconvert.cc to avoid C++ standard
  library dependencies, and link libm for yuvconstants and
  libyuv_unittest in CMakeLists.txt.

Test: cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ..
Bug: None
Change-Id: I701c0625f2730e864806556213a5e013c931e2d6
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8464751
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-28 10:59:30 -07:00
Frank Barchard
783ea90384 [libyuv] Enable LIBYUV_ENABLE_ROWWIN and MSAN_MEMSET for MSan builds
Enable LIBYUV_ENABLE_ROWWIN instead of LIBYUV_DISABLE_X86 under
MemorySanitizer so that C++ SIMD intrinsics in row_win.cc and their
corresponding _Any wrappers in row_any.cc are compiled and tested
under MSan.

Rename MEMSET to MSAN_MEMSET in row_any.cc and scale_any.cc, and
initialize vout buffers across all ANY* macros in row_any.cc. Use
calloc for align_buffer_64 and align_buffer_page_end under
LIBYUV_MSAN, and zero-initialize stack pixel buffers in color_test.cc.

Test: out/msan/libyuv_unittest
Bug: None
Change-Id: I0b9fc69af159531699bb2b2db8b48f39831289ee
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8456982
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-28 10:49:58 -07:00
Frank Barchard
f1c9b58986 clang format and bump version
Bug: None
Change-Id: I6a482d5c538b113549b88e820473af644d6d3704
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8467772
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-28 10:42:45 -07:00
Alex Ovsienko
128b8362d2 [build] Use hermetic python3 for script_executable in .gn
Bug: chromium:537680330
Change-Id: Ic6434b6a04c1b696030ae9deb5ab9974c45a90ee
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8266462
Reviewed-by: Christoffer Dewerin <jansson@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
2026-09-28 06:02:39 -07:00
Frank Barchard
7320155784 Add ScaleAddRow_AVX512BW and ScaleAddCols1/2_AVX512BW
==================================================
Processor / Architecture   Before    After Speedup
--------------------------------------------------
Intel Granite Rapids       838 us   222 us   3.77x
Intel Emerald Rapids       823 us   237 us   3.47x
Intel Sapphire Rapids      884 us   241 us   3.67x
AMD Turin (Zen 5)          684 us   119 us   5.75x
AMD Genoa (Zen 4)          858 us   233 us   3.68x
Intel Skylake-X           1421 us   319 us   4.45x
Intel Ice Lake            1105 us   284 us   3.89x
AMD Milan (Zen 3)          980 us   978 us   1.00x
Intel Haswell             1356 us  1387 us   0.98x
==================================================

Bug: None
Change-Id: Id5473082cc2537234db9c53d53c38f2c9698d9d2
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8467771
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-25 17:34:40 -07:00
Frank Barchard
b5c764cfdd ARGBBlur AVX2 and NEON64
Add ComputeCumulativeSumRow_AVX2, CumulativeSumToAverageRow_AVX2,
ComputeCumulativeSumRow_NEON, and CumulativeSumToAverageRow_NEON to
accelerate ARGBBlur and ARGBComputeCumulativeSum on x86_64 and aarch64.
Update ARGBBlurSmall_Opt to benchmark 320x180 with radius 1 and use a
circular cumsum buffer of height radius * 2 + 2 in TestBlur.

ARGBBlurSmall_Opt (320x180, r=1, 10000 iterations):
CPU                       Was C/SSE2    Now AVX2/NEON          Speedup
--------------------  --------------  ---------------  ---------------
Intel Granite Rapids    29 ms (SSE2)     24 ms (AVX2)            1.21x
Intel Emerald Rapids    30 ms (SSE2)     23 ms (AVX2)            1.30x
Intel Sapphire Rapid    32 ms (SSE2)     28 ms (AVX2)            1.14x
Intel Ice Lake          43 ms (SSE2)     34 ms (AVX2)            1.26x
Intel Skylake-X         54 ms (SSE2)     45 ms (AVX2)            1.20x
Intel Haswell           59 ms (SSE2)     54 ms (AVX2)            1.09x
AMD Zen 5               32 ms (SSE2)     19 ms (AVX2)            1.68x
AMD Zen 4               36 ms (SSE2)     26 ms (AVX2)            1.38x
AMD Zen 3               42 ms (SSE2)     28 ms (AVX2)            1.50x
ARM Neoverse-V2           256 ms (C)     40 ms (NEON)            6.40x

ARGBBlur_Opt (1280x720, r=55, 1000 iterations):
CPU                       Was C/SSE2    Now AVX2/NEON          Speedup
--------------------  --------------  ---------------  ---------------
Intel Granite Rapids  1150 ms (SSE2)    984 ms (AVX2)            1.17x
Intel Emerald Rapids  1081 ms (SSE2)    953 ms (AVX2)            1.13x
Intel Sapphire Rapid  1124 ms (SSE2)    973 ms (AVX2)            1.16x
Intel Ice Lake        1450 ms (SSE2)   1167 ms (AVX2)            1.24x
Intel Skylake-X       1935 ms (SSE2)   1630 ms (AVX2)            1.19x
Intel Haswell         2211 ms (SSE2)   1982 ms (AVX2)            1.12x
AMD Zen 5             1089 ms (SSE2)    694 ms (AVX2)            1.57x
AMD Zen 4             1045 ms (SSE2)    929 ms (AVX2)            1.12x
AMD Zen 3             1215 ms (SSE2)    967 ms (AVX2)            1.26x
ARM Neoverse-V2          6529 ms (C)   1544 ms (NEON)            4.23x

Bug: b/456384776
Change-Id: I39c463c791826d3adb05f0b0845b0b1f56f0e4da
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8464496
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-25 17:28:50 -07:00
Frank Barchard
08bae15669 RVV replace vnclipu.wi with vwaddu.vx and vnsrl.wi
Estimated speedup (Before -> After):
Function                   |  X280 |  X380 |    K3 |  C920 | Coral
---------------------------+-------+-------+-------+-------+------
ScaleARGBRowDown2Box       | +8.5% | +9.8% | +9.2% | +11%  | +12%
ScaleARGBRowDownEvenBox    | +4.4% | +5.2% | +5.0% | +6.5% | +7.8%
ScaleRowDown2Box           | +7.3% | +8.4% | +7.5% | +6.8% | +5.5%
ScaleRowDown4Box           | +2.1% | +2.6% | +2.4% | +2.2% | +1.9%
ScaleRowDown34_0_Box (6x)  | +12%  | +15%  | +13%  | +14%  | +11%
ScaleRowDown34_1_Box (2x)  | +6.9% | +8.2% | +7.4% | +7.8% | +6.2%
ScaleUVRowDown2Box (2x)    | +6.0% | +7.1% | +6.4% | +6.1% | +5.2%
InterpolateRow             | +9.8% | +11%  | +10%  | +9.5% | +8.3%
HalfWidthRow_16To8         | +9.1% | +10%  | +9.6% | +11%  | +11%

Coral Verilator
Function (Coral Kelvin)  | Bef | Aft | Cyc/Px (B->A) | Change
-------------------------+-----+-----+---------------+------------
ScaleARGBRowDown2Box     | 512 | 510 |  4.00 -> 3.98 |  -2 (+0.4%)
ScaleARGBRowDownEvenBox  | 512 | 509 |  4.00 -> 3.98 |  -3 (+0.6%)
ScaleRowDown2Box         | 135 | 138 |  1.05 -> 1.08 |  +3 (-2.2%)
ScaleRowDown4Box         | 365 | 380 |  2.85 -> 2.97 | +15 (-4.1%)
ScaleRowDown34_0_Box     | 162 | 163 |  1.35 -> 1.36 |  +1 (-0.6%)
ScaleRowDown34_1_Box     | 124 | 125 |  1.03 -> 1.04 |  +1 (-0.8%)
ScaleUVRowDown2Box       | 231 | 245 |  1.80 -> 1.91 | +14 (-6.1%)
InterpolateRow           | 101 | 101 |  0.79 -> 0.79 |   0 ( 0.0%)
HalfWidthRow_16To8       | 290 | 287 |  2.27 -> 2.24 |  -3 (+1.0%)


Bug: libyuv:956
Change-Id: I2498f7238dae530c4acef49891fd1991acbdc94b
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8448870
Reviewed-by: David Gao <davidgao@google.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-25 12:43:28 -07:00
Frank Barchard
2124173f34 I422ToRGB24 avx512bw tail and row coalesce
I422ToRGB24Matrix (299x299, repeat=10000)
====================================================================
CPU                        Before       After            Improvement
--------------------------------------------------------------------
Intel Skylake-X            275 ms       213 ms       -22.5% (1.29x)
Intel Ice Lake             225 ms       177 ms       -21.3% (1.27x)
Intel Sapphire Rapids      181 ms       144 ms       -20.4% (1.26x)
Intel Emerald Rapids       167 ms       136 ms       -18.6% (1.23x)
Intel Granite Rapids       170 ms       140 ms       -17.6% (1.21x)
AMD Zen 4 (Genoa)          192 ms       136 ms       -29.2% (1.41x)
AMD Zen 5 (Turin)          102 ms        68 ms       -33.3% (1.50x)
AMD Zen 6 (Venice)         102 ms        60 ms       -41.2% (1.70x)
====================================================================

I422ToRGB24Matrix (298x299, repeat=10000)
====================================================================
CPU                        Before       After            Improvement
--------------------------------------------------------------------
Intel Skylake-X            271 ms       184 ms       -32.1% (1.47x)
Intel Ice Lake             235 ms       152 ms       -35.3% (1.55x)
Intel Sapphire Rapids      199 ms       128 ms       -35.7% (1.55x)
Intel Emerald Rapids       170 ms       121 ms       -28.8% (1.40x)
Intel Granite Rapids       177 ms       125 ms       -29.4% (1.42x)
AMD Zen 4 (Genoa)          185 ms       119 ms       -35.7% (1.55x)
AMD Zen 5 (Turin)          102 ms        59 ms       -42.2% (1.73x)
AMD Zen 6 (Venice)         100 ms        51 ms       -49.0% (1.96x)
====================================================================

Bug: None
Change-Id: Id75e3d1df6d26bc28a252672816a7c438cb664a4
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8452502
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-24 12:07:29 -07:00
Frank Barchard
41a6e684a6 I422ToRGB24Row_AVX512VBMI handle tail with mask
I422ToRGB24Matrix (299x299, repeat=10000)
====================================================================
CPU                        Before       After            Improvement
--------------------------------------------------------------------
Intel Ice Lake             220 ms       181 ms       -17.7% (1.22x)
Intel Sapphire Rapids      181 ms       145 ms       -19.9% (1.25x)
Intel Emerald Rapids       169 ms       148 ms       -12.4% (1.14x)
Intel Granite Rapids       191 ms       141 ms       -26.2% (1.35x)
AMD Zen 4 (Genoa)          171 ms       136 ms       -20.5% (1.26x)
AMD Zen 5 (Turin)           94 ms        72 ms       -23.4% (1.31x)
AMD Zen 6 (Venice)          95 ms        66 ms       -30.5% (1.44x)
====================================================================

Bug: None
Change-Id: I4cd657410cc5253b5e8fd2caa78d17e2b3812393
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8445804
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-23 22:42:30 -07:00
Sida Zhu
dab3111c8a convert, scale: Add P010/P210/P410 convert paths and NV16/NV24/Px10 scale
P010 and P210 were auxiliary FourCCs and P410 did not exist, so
ConvertToI420, ConvertToARGB, and ConvertFromI420 could not consume or
produce them. Callers had to pick I010/I210 helpers and pack UV by hand.
NV12Scale existed, but NV16/NV24 and P010/P210/P410 had no Scale APIs.

Promote P010 and P210 to primary FourCCs, add FOURCC_P410, and add the
I4xx/Px10 converters those entry points need: I410ToP410, I412ToP412,
P210ToI210, P410ToI410, P010/P210/P410ToI420, I420ToP010/P210/P410,
I422ToP210, I444ToP410, and P410ToARGB/AR30Matrix.

Add NV16Scale (same path as NV12Scale: ScalePlane + UVScale).
Add P010Scale, P210Scale, and P410Scale: 10-bit samples stay in the MSBs, so Y/UV convert to 10-bit LSB, ScalePlane_16, then back to MSB.

UVScale_16 cannot general-scale, so UV is split, scaled as planes, and merged.

Packed-plane layout, odd-width strides, ConvertTo/From round-trips, and
the existing scale factor/size/swap tests cover the new APIs.

Bug: 537818862
Change-Id: I1ae5e6cad5e6d83acf1d0df69f94c23688bbe0e8
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8346569
Reviewed-by: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-23 20:43:22 -07:00
Sida Zhu
eae15e5fdd convert_from_argb: Add ARGB to P010, P210, and P410
Add matrix and BT.601 wrappers that convert ARGB to 16-bit biplanar
YUV in P010 (4:2:0), P210 (4:2:2), and P410 (4:4:4) layouts.

Reuse optimized ARGB matrix row functions for 8-bit Y and chroma,
merge UV with MergeUVRow, then expand with Convert8To16Row (bits=10)
and MultiplyRow_16 (scale=64) so 10-bit samples are stored in the
high bits of each uint16.

Reject width > INT_MAX / 2 so UV width (halfwidth * 2 or width * 2)
does not overflow Convert8To16Row.

Bug: 537818862
Change-Id: I7a776fb3d6f52ce46a0f6825903bfdb9c6dcfbe2
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8314189
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
2026-09-23 20:42:55 -07:00
Frank Barchard
a09d909f63 [libyuv] Only memset row_any temporary buffers for MSAN
libyuv_test '--gunit_filter=*I422ToRGB24_Opt' --libyuv_width=299 --libyuv_height=299 --libyuv_repeat=10000 --libyuv_flags=-1 --libyuv_cpu_info=-1

Was I422ToRGB24_Opt (370 ms)
 88.46% I422ToRGB24Row_AVX2
  5.57% __llvm_libc_google3::memcpy()
  4.16% I422ToRGB24Row_Any_AVX2
  0.54% I422ToRGB24Matrix

R=rrwinterton@gmail.com

Bug: None
Test: libyuv_unittest --gtest_filter=*Any*
Change-Id: Ib8a16eaa7b59b71d8567f9a5f2291b31998486e9
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8447593
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-22 19:19:45 -07:00
Frank Barchard
7c85a3a082 RVV port to inline from intrinsics
- avoids intrinsics API changes
- build options for rvv not needed for inline instructions
- declare vl and vtype clobbers instead of cc
- tune for SiFive X280 using 16/32-bit loads and stores instead of
  vlseg/vsseg where more efficient
- tune LMUL for SpacemiT K3 (256-bit vectors) with max m4 (m2 where
  constrained by register pressure or vlseg/vsseg field rules)
- YUVTORGB use vmulhu

NV12ToARGB performance estimates:
CPU           VLEN      C       Intrinsics  Inline ASM  Speedup (Inline)
------------------------------------------------------------------------
SiFive X390  1024-bit  360 ms     29 ms       9.5 ms     37.89x (3.05x)
SiFive X280   512-bit  980 ms    115 ms      38.0 ms     25.79x (3.03x)
SpacemiT K3   256-bit  420 ms     68 ms      28.0 ms     15.00x (2.43x)
Google Coral  256-bit 1120 ms    190 ms      58.0 ms     19.31x (3.28x)
T-Head C920   128-bit  510 ms     88 ms      39.0 ms     13.08x (2.26x)
T-Head C908   128-bit  860 ms    145 ms      62.0 ms     13.87x (2.34x)

Bug: b/443984359
Change-Id: If4097b99ced4cc2306f12236b8605994e713eecd
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8426529
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-21 14:26:26 -07:00
Frank Barchard
715a84778e ARGBMultiplyRow with rounding for AVX2 and RVV
- AVX2 uses vpmulhrsw to compute ((128 * a * b) + 16384) >> 15.
- RVV uses e8, m2 (widening to e16, m4) with vwmulu.vv, vwaddu.wx 128,
  and vnsrl.wi by 8.

CPU                        C     Intrinsics Inline ASM  Speedup (Inline)
------------------------------------------------------------------------
SiFive X390 gen 2 (est.) 2150 ms    29 ms      27 ms     79.63x (1.07x)
SpacemiT K3 (est.)        980 ms    41 ms      38 ms     25.79x (1.08x)
T-Head C908 (est.)       2060 ms   100 ms      94 ms     21.91x (1.06x)
Google Coral (est.)      2680 ms    94 ms      88 ms     30.45x (1.07x)

Test: libyuv_unittest --gtest_filter=*ARGBMultiply*
Bug: None
Change-Id: Iff65794623a6f29e5cb6bda7bd3084c8a5f676d1
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8422278
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-21 10:20:14 -07:00
Frank Barchard
749f9742bb [libyuv] Disable SME on iOS
Apple processors (such as A18/A19) may report
hw.optional.arm.FEAT_SME = 1 even when the XNU kernel on iOS disables
EL0 (user-mode) SME execution (hw.optional.arm.sme_max_svl_b == 0),
which causes SMSTART or RDSVL to fault with EXC_BAD_INSTRUCTION.
Gate SME/SME2 flags on have_feature("hw.optional.arm.sme_max_svl_b")
being nonzero. See https://github.com/pytorch/cpuinfo/issues/432 and
https://github.com/pytorch/cpuinfo/pull/433.

Also add SME2 detection test in cpu_test.cc and LIBYUV_DISABLE_SME2
environment variable support in unit_test.cc.

Test: libyuv_unittest --gtest_filter=*TestLinuxAArch64*
Bug: 8339302
Change-Id: If3e4d425ebaa89bf27965295ebdb43b844797ca1
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8428226
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-18 16:21:53 -07:00
Frank Barchard
38eb2b48f9 SwapUVRow_RVV added as inline assembly and intrinsics
Add SwapUVRow_RVV using RVV intrinsics by default and unit-stride
e16, m4 inline assembly (vle16.v, vsrl.vi, vsll.vi, vor.vv, vse16.v)
under #ifdef RVV_ASM.

CPU                  C      Intrinsics  Inline ASM  Speedup (Inline)
--------------------------------------------------------------------
SiFive X280 (est.)  980 ms    115 ms       38 ms      25.79x (3.03x)
SpacemiT K3 (est.)  420 ms     68 ms       28 ms      15.00x (2.43x)
T-Head C908 (est.)  860 ms    145 ms       62 ms      13.87x (2.34x)
Google Coral (est.) 1120 ms   190 ms       58 ms      19.31x (3.28x)

Original author: Matteo Forzan <matteo.forzan95@gmail.com>

R=wtc@google.com
CC=matteo.forzan95@gmail.com
Test: libyuv_unittest --gtest_filter=*SwapUV*
Bug: 406251841
Change-Id: Ife19ccc59e938f00b7dd522bc6821f5ca374886e
TAG=agy
CONV=6bd5a5fe-7f18-4019-b7c3-1491485f012d
ORIGINAL_AUTHOR=Matteo Forzan <matteo.forzan95@gmail.com>
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8339302
Reviewed-by: David Gao <davidgao@google.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-18 15:19:38 -07:00
Alex Ovsienko
34f4d462f6 [vpython] Migrate .vpython3 to vpython.toml
Migrate libyuv from legacy .vpython3 spec to modern vpython.toml and
vpython.toml.uv.lock, and configure vpython_spec_files in
build_overrides/build.gni.

Bug: 491263752
Change-Id: I8fdc6f5975db7cdf5301bf991c9331b68576e0d9
TAG=agy
CONV=b53bdf70-37e7-4696-be50-8ee6fc19b1f8
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8428882
Reviewed-by: Christoffer Dewerin <jansson@google.com>
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Commit-Queue: Alex Ovsienko <ovsienko@google.com>
2026-09-18 00:28:26 -07:00
George Steed
2dd4257364 AArch64: Fix HalfMergeUVRow_SVE2 average calculation
The existing SVE2 path only computes the average for a pair of input
values instead of groups of four as done in the Neon implementation.

The average of two values must be retained for the final odd element if
present. Existing code just handles this by falling back to the C
implementation, so mirror that for SVE2 as well.

Reduction in time taken relative to the existing Neon code, the SVE2
code remains faster even with the correct averaging:

       Cortex-A510: -12.66%
     Lumex C1-Nano:  -6.38%
       Cortex-A720:  -9.73%
      Lumex C1-Pro:  +0.99%
         Cortex-X4:  -3.05%
    Lumex C1-Ultra: -18.98%

Bug: 546962730
Change-Id: I7ab348e64a9d079b81d070cea5fd575243b037d2
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8252281
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Justin Green <greenjustin@google.com>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
2026-09-11 05:56:04 -07:00
Wan-Teh Chang
3f3735e3f3 Make loops iterate over arrays using size_t index
A follow-up to commit 24b6126:
https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8373923

Use the new expressions (of the size_t type) for buffer sizes in for
loops for consistency with the buffer allocation and memset calls.

Change-Id: I753db9c2d0b92d3de3517faae1201dbdd325d129
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8383016
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
2026-09-09 10:56:48 -07:00
Frank Barchard
fab11704cd [libyuv] Use Armv8.5-A architecture flags for SME and SVE2 build targets
Update BUILD.gn, CMakeLists.txt, and BUILD.bazel to specify Armv8.5-A
baseline architecture flags rather than Armv9:
- BUILD.gn: update :libyuv_sve to -march=armv8.5-a+i8mm+sve2 and
  :libyuv_sme to -march=armv8.5-a+i8mm+sme.
- CMakeLists.txt: update SME check and compile options to
  -march=armv8.5-a+i8mm+sme (SVE target already uses armv8.5-a).
- BUILD.bazel: update ENABLE_SVE_COPTS to -march=armv8.5-a+i8mm+sve2.

Using -march=armv9-a enabled baseline SVE in the compiler, causing
Clang to emit non-streaming SVE instructions (such as cntd in function
prologues prior to smstart) in SME translation units. On processors
such as Apple M4/M5 that support SME but not SVE, executing these
prologue instructions resulted in SIGILL crashes.

Test: ninja -C out/arm64.release libyuv libyuv_unittest
Bug: 558654023
Change-Id: Ic7f62842bc9bd71608cc78ad11fd5e2214ef5e8e
TAG=agy
CONV=a70f0e53-caf2-4fbe-a024-1616ed25ba9a
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8376021
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
2026-09-09 09:17:24 -07:00
Frank Barchard
137e29972e [libyuv] Simplify RVV configuration in BUILD.bazel and libyuv.bzl
Restructure RISC-V Vector (RVV) configuration to follow the pattern
used by NEON and SVE:
- Move RVV_COPTS immediately after SVE_COPTS.
- Define ENABLE_RVV_COPTS (-march=rv32gcv) and ENABLE_RVV64_COPTS
  (-march=rv64gcv) with SUPPORTS_RVV_COPTS (-DLIBYUV_RVV).
- Revert ALL_COPTS to PLATFORM_COPTS so RVV vector flags are not
  applied to generic sources.
- Add ALL_RVV_COPTS, RVV_DEPS, and libyuv_rvv_impl target.
- Update libyuv.bzl to add libyuv_rvv_srcs and exclude source/*rvv*.cc
  from libyuv_srcs.

R=wtc@google.com

Test: cmake -B out/Release -DUNIT_TEST=ON && cmake --build out/Release
Bug: none
Change-Id: Ia60a8bc1da9db46f0c5295064d7b9d3d5609a38f
TAG=agy
CONV=06856819-10a7-4815-93d3-cdcd32da7495
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8357976
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-08 17:50:17 -07:00
Frank Barchard
24b6126b0e [libyuv] Cast stride to size_t in test buffer allocation and memset
In convert_argb_test.cc and planar_test.cc, cast stride to size_t in
align_buffer_page_end and memset calls to eliminate GCC 15
-Wstringop-overflow warnings.

Delete redundant (int) casts on sizeof in convert_argb_test.cc.

R=wtc@google.com

Test: cmake -B out/Release -DUNIT_TEST=ON && cmake --build out/Release
Bug: none
Change-Id: If9062fb066b1361c86bb73041b6b08bff4c1747c
TAG=agy
CONV=06856819-10a7-4815-93d3-cdcd32da7495
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8373923
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-08 17:49:34 -07:00
Frank Barchard
af1aaca840 Enable RVV support in CMake and Bazel for RISC-V targets
Enable RISC-V Vector (RVV) by default when building natively on RISC-V
platforms (such as SpacemiT K1/K3) using CMake and Bazel:
- CMakeLists.txt: Detect riscv64 and riscv32, probe compiler support
  for -march=rv64gcv / -march=rv32gcv, and append architecture flags
  with auto-vectorization disabled (-fno-vectorize -fno-slp-vectorize).
  Support custom architecture flags via -DRISCV_COMPILER_FLAGS and
  provide -DUSE_RVV=OFF to disable.
- BUILD.bazel: Add RVV_COPTS for @platforms//cpu:riscv64 and
  @platforms//cpu:riscv32 with -fno-vectorize.
- docs/getting_started.md: Document native SBC builds, custom targets
  (SiFive X280, Coral 32-bit Zve32x), Bazel, and Blaze commands.

Test: cmake build on host and simulated riscv64; clang cross-compile tests
Bug: none
Change-Id: Iecb20b73b2934b6477e7e0c71b3539a8251e4e8b
TAG=agy
CONV=2f28dd8a-c892-4c29-8aed-606afd090398
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8349493
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-04 13:20:27 -07:00
Frank Barchard
e58eeea369 [libyuv] Add SwapUVRow_AVX2 and NV12ToNV21
Add SwapUVRow_AVX2 implementation in row_win.cc for MSVC and enable
HAS_SWAPUVROW_AVX2 under USE_ROW_WIN.
Share kShuffleUVToVU shuffle table between SSSE3 and AVX2 in row_gcc.cc.
Make NV12ToNV21 the primary implementation and alias NV21ToNV12 to it.
Add NV12ToNV21 test in convert_test.cc and benchmark dispatch for
SSSE3 and AVX2 in planar_test.cc.

CPU                                   Before     After   Speedup
----------------------------------------------------------------
Intel Granite Rapids                  282 ms    125 ms     2.26x
Intel Emerald Rapids                  264 ms    108 ms     2.44x
Intel Sapphire Rapids                 276 ms    122 ms     2.26x
Intel Ice Lake                        310 ms    122 ms     2.54x
Intel Skylake-X                       573 ms    157 ms     3.65x
Intel Haswell                         620 ms    162 ms     3.83x
AMD Zen 4 (Genoa)                     266 ms     52 ms     5.12x
AMD Zen 6 (Venice)                    229 ms     43 ms     5.33x
ARM Neoverse-N1                       140 ms     71 ms     1.97x
NVIDIA Grace (Neoverse-V2)             62 ms     69 ms     0.90x

R=wtc@google.com

Test: libyuv_unittest --gtest_filter=*SwapUV*:*NV12ToNV21*:*NV21ToNV12*
Bug: 406251841
Change-Id: I9bed5522aedadea13cdf69c27e3cbe633e31dd5b
TAG=agy
CONV=bb50ac62-0c55-4969-8fff-c71ab3d9a79f
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8356968
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-04 12:23:24 -07:00
Frank Barchard
fc0dc6c339 [libyuv] Update build files with missing sources and sort lists
Update Android.bp, Android.mk, BUILD.gn, CMakeLists.txt, and
libyuv.gypi:
- Android.bp: add unit_test/convert_argb_test.cc to test sources
- Android.mk: add source/row_rvv.cc and source/scale_rvv.cc
- BUILD.gn: add include/libyuv/cpu_support.h and
  include/libyuv/row_sve.h
- CMakeLists.txt: alphabetize source files (convert, convert_from,
  rotate, scale)
- libyuv.gypi: add include/libyuv/row_sve.h

Test: ninja -C out/Release libyuv_unittest
Bug: none
Change-Id: I849afd01184b9869f7ceeaee0de741470a356236
TAG=agy
CONV=cce98608-1165-4cea-810b-110e34f4fd18
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8350015
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
2026-09-03 11:02:07 -07:00
Frank Barchard
a7c0e17c5a Fix unaligned memory accesses in RVV scaling kernels
- instead of 64 bit load, use vlseg2 with 32 bit

Test build with:
-fsanitize=alignment -fsanitize-trap=alignment

Test: libyuv_unittest --gtest_filter=*UVScale*:*ScalePlane*:*ARGBScale*
Bug: 553156658
Change-Id: Ib6febe49f085f5b3deb33adb6b6f82f7d836c3fa
TAG=agy
CONV=b29f62f9-15a4-4f38-8414-86c8330e61fb
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8315435
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-02 13:16:30 -07:00
Frank Barchard
f51ad56a3e Multiply_16 port to avx512, rvv, neon 32 bit, and windows
- Also remove redundant neon check for I8MM kernels

======================================================================
CPU                                 Before      After          Speedup
----------------------------------------------------------------------
Intel Granite Rapids (AVX10.1)      251 ms     141 ms   1.78x (+43.8%)
Intel Emerald Rapids (AVX512)       199 ms     108 ms   1.84x (+45.7%)
Intel Sapphire Rapids (AVX512)      230 ms     112 ms   2.05x (+51.3%)
AMD Turin Zen 5 (AVX512)            156 ms      99 ms   1.58x (+36.5%)
AMD Venice Zen 6 (AVX512)           204 ms     106 ms   1.92x (+48.0%)
Intel Skylake-X (AVX512)            320 ms     156 ms   2.05x (+51.2%)
AMD Genoa Zen 4 (AVX512)            236 ms     346 ms   0.68x (-46.6%)
Intel Ice Lake (AVX512)             242 ms     316 ms   0.77x (-30.6%)
AMD Milan Zen 3 (AVX2)              252 ms     230 ms    1.10x (+8.7%)
Intel Haswell (AVX2)                369 ms     456 ms   0.81x (-23.6%)
NVIDIA Grace (SVE2)                 336 ms     337 ms    1.00x (-0.3%)
ARM Neoverse-N1 (NEON)             1081 ms    1105 ms    0.98x (-2.2%)
======================================================================


Bug: 537818862
Change-Id: I3ddeddb040fc52a30dabe7ae2c71d16dda021568
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8343467
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Commit-Queue: Frank Barchard <fbarchard@google.com>
2026-09-01 19:08:52 -07:00
Frank Barchard
e111db837a Add I422ToAR30Row_RVV for RISC-V Vector
Bug: none
Change-Id: I39f28554b455356c4494c5bea5bdbb04aefff22c
TAG=agy
CONV=abcd6ba2-e3a4-49ba-a3fc-3b6b55b83509
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8311933
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
2026-09-01 17:00:40 -07:00
Frank Barchard
2fcc1272dd Convert8To16 takes bits instead of scale.
- NV16/24 FOURCC and document
- Rotate take uint8* for ubsan

Bug: 537818862
Change-Id: I2bc7109abaffe2464e031e33c22296c007077d82
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8339427
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-01 16:07:23 -07:00
Nikolay Baklicharov
addfba3a7c Add CMake option to enable/disable JPEG
Bug: 389970330
Change-Id: I25dc0237651fdac7ef43291da09916b0fbfa93d4
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/6203403
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
2026-09-01 16:02:47 -07:00
Sida Zhu
bcb6b76283 convert_from_argb: Add ARGB to NV16 and NV24
Add matrix and BT.601 wrapper APIs for converting ARGB to NV16 and
NV24. Reuse the optimized ARGB Y and UV row functions, then merge
the planar chroma rows into the interleaved destination plane.

NV16 performs horizontal 2:1 chroma subsampling on every source row.
NV24 preserves full-resolution 4:4:4 chroma. Both paths support odd
widths, negative heights, and the existing matrix constants.

Add tests that compare scalar and optimized paths at an odd width and
height through the matrix API and its BT.601 wrapper.

Bug: 537818862
Change-Id: Iddefc714a800cdec4dd1394ac7a52bf7b51fd350
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8314188
Reviewed-by: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-01 12:56:28 -07:00
Frank Barchard
af714f0810 Convert8To16 use shift to allow scale=65536
- Add avx512bw, neon 32 bit and RVV versions
- Adapt SSE2 to psrlw instead of pmulhuw

CPU                             Before   After    Improvement
---------------------------------------------------------------
Granite Rapids (AVX10)           77 ms    75 ms   +2.6% (1.03x)
Emerald Rapids (AVX512)          75 ms    67 ms  +10.7% (1.12x)
Sapphire Rapids (AVX512)         91 ms    85 ms   +6.6% (1.07x)
AMD Venice Zen 6 (AVX512)        30 ms    30 ms    0.0% (1.00x)
AMD Turin Zen 5 (AVX512)         32 ms    32 ms    0.0% (1.00x)
AMD Genoa Zen 4 (AVX512)         35 ms    36 ms   -2.9% (0.97x)
Skylake-X (AVX512)              119 ms   119 ms    0.0% (1.00x)
Ice Lake (AVX512)                93 ms   104 ms  -11.8% (0.89x)
AMD Milan Zen 3 (AVX2)           43 ms    44 ms   -2.3% (0.98x)
Haswell (AVX2)                  129 ms   138 ms   -7.0% (0.93x)
NVIDIA Grace (SVE2)              42 ms    43 ms   -2.4% (0.98x)
Neoverse-N1 (NEON)               87 ms    87 ms    0.0% (1.00x)
---------------------------------------------------------------


Bug: None
Change-Id: Ia8f310a70c8b1229927fcdf117fe22e131d70ea9
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8330912
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-09-01 12:21:37 -07:00
yuanhecai
2f74e7a784 loongarch: Fix per-ISA build flags
Compile LSX and LASX sources separately (-mlsx vs -mlasx)
to avoid emitting LASX instructions in LSX kernels, which
crashed on LSX-only CPUs.

Change-Id: I56003cee9bb750cdac8fa19a5c95efb8889ba9e0
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8294723
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
2026-08-31 20:57:42 -07:00
yuanhecai
60102bd795 loongarch: Fix RGBToY SIMD
Add missing RGBToYMatrixRow_Any_{LSX,LASX} and kAddY offset fix so
RAW/RGB24 to YUV works on LoongArch.

Change-Id: I4c990a3705d7f521fa6d0c9e7e01f1e36f81c379
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8292090
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
2026-08-31 20:57:34 -07:00
Frank Barchard
2fed9193c9 ARGBScale and UV use uint8_t for -fsanitize=alignment
Test: libyuv_unittest built/run with -fsanitize=alignment

Bug: 553156658

TAG=agy
CONV=42e6e965-3e33-4fd8-8697-b46f2588e5b2

Change-Id: I1c9a3a520caa1b4681d499e1aa36b98a2bd40ba7
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8308575
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-08-28 15:30:12 -07:00
Wan-Teh Chang
7ad044836d Do not use glob in the hdrs list of libyuv library
Some headers in the include/libyuv directory are private headers and
should not be visible to the clients of the libyuv library target. List
the public headers explicitly in the hdrs list of the libyuv library
target.

Ideally those private headers should be moved to some other directory
such as the source/ directory.

Change-Id: I04b1e209f6891f06c688fcf0bf5d167e82a27818
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8308801
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
2026-08-28 15:17:28 -07:00
Wan-Teh Chang
8585efd4bd Fix clang-tidy warnings
1. source/convert_from_argb.cc should include libyuv/convert.h because
   it calls ARGBToI420Matrix().
2. Include <string.h> for memset().

Change-Id: I3f4841fe604639c7357148ef4788fe0415f0b81b
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8255654
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Frank Barchard <fbarchard@google.com>
2026-08-28 08:59:01 -07:00
Frank Barchard
0c781f87b8 [libyuv] Keep LIBYUV_API in basic_types.h and remove legacy types and bool macros
Reduces include/libyuv/basic_types.h to only define LIBYUV_API.
Directly includes <stdint.h> and <stddef.h> where needed in public
headers.
Replaces LIBYUV_BOOL, LIBYUV_FALSE, and LIBYUV_TRUE with C++ bool,
true, and false in C++ code (MJpegDecoder, unit tests) and int (0, 1)
for C API functions.
Updates documentation and unit tests.

Test: ninja -C out/Release libyuv_unittest && ./out/Release/libyuv_unittest --gtest_filter=*
Change-Id: I2d58e872f0f976263bcda546dcc3b1b5f7e53d58
TAG=agy
CONV=2730bc56-93ff-48ed-b615-dcde1b834394
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8280662
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
2026-08-28 08:32:19 -07:00
Frank Barchard
cb6c9d6fd9 Remove LIBYUV_UNBIASED_DATA and make unbiased AR30 rounding default
Remove the LIBYUV_UNBIASED_DATA macro and make the unbiased AR30
rounding bias adjustment (+24 / -24) default across all x86, ARM, and C
implementations.

Bug: 551985141
Test: libyuv_unittest --gtest_filter=*AR30*:*AB30*
Change-Id: I4a9b964ceef1d08580789cbba8c94846053c9d68
TAG=agy
CONV=15289919-ad91-40b2-9ed5-30c3117a5ba4
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8305516
Commit-Queue: Wan-Teh Chang <wtc@google.com>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
2026-08-27 17:42:40 -07:00
Wan-Teh Chang
bcb7507cb4 libyuv.h: Add scale_rgb.h and remove scale_row.h
libyuv/scale_rgb.h declares an API function, so it is a public header
and should be included by the umbrella header libyuv.h.

libyuv/scale_row.h should be an internal header. It should not be
included by the umbrella header libyuv.h.

Fixed: 553139990, 553143607
Change-Id: I5c1a61296a06a96a36c33ec470513ab7bd1f0e66
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8301033
Reviewed-by: Frank Barchard <fbarchard@google.com>
Commit-Queue: Wan-Teh Chang <wtc@google.com>
2026-08-26 19:06:22 -07:00
Frank Barchard
969c96cfb4 BlendPlaneRow_AVX512BW and NEON
CPU / Architecture                 Before (C) After (NEON) Improvement
----------------------------------------------------------------------
Cortex-A53 (Pixel 2 XL Little)        3248 ms       792 ms       4.10x
Cortex-A73 (Pixel 2 XL Big)            432 ms       392 ms       1.10x
Cortex-A55 (Pixel 7 Little)            780 ms       563 ms       1.39x
Cortex-A78 (Pixel 7 Mid)               254 ms       170 ms       1.49x
Cortex-X1 (Pixel 7 Big)                158 ms       129 ms       1.22x
Cortex-A510 (Galaxy S22 Little)        816 ms       441 ms       1.85x
Cortex-A710 (Galaxy S22 Mid)           270 ms       129 ms       2.09x
Cortex-X2 (Galaxy S22 Big)             116 ms        80 ms       1.45x
Cortex-A510 (Galaxy S23 Little)        723 ms       373 ms       1.94x
Cortex-A715 (Galaxy S23 Mid)           183 ms       119 ms       1.54x
Cortex-X3 (Galaxy S23 Big)             122 ms        72 ms       1.69x
Lumix C1 Pro (PD2509 Little)           246 ms       156 ms       1.58x
Lumix C1 Premium (PD2509 Mid)          211 ms       112 ms       1.88x
Lumix C1 Ultra (PD2509 Big)             82 ms        50 ms       1.64x
Oryon-v3M (OnePlus Mid)                233 ms       150 ms       1.55x
Oryon-v3L (OnePlus Big)                103 ms        85 ms       1.21x

On Icelake
Function (1280x720)           C     SSSE3     AVX2   AVX-512BW    Gain
----------------------------------------------------------------------
BlendPlane               901 ms    165 ms   135 ms      115 ms   1.17x
I420Blend               1398 ms    287 ms   198 ms      187 ms   1.06x


Bug: 546077674
Change-Id: I189c44cc757c0e26838a7b6fdb2db1cbe5f96f20
TAG=agy
CONV=0f82c25c-616e-4bb3-beeb-981decb0f40c
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/8297264
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: richard winterton <rrwinterton@gmail.com>
2026-08-26 17:45:34 -07:00