Repository navigation
Optimize ARM64 NEON LUT1D, LUT3D, RGBA pack, and diagonal matrix ops - #2367
Open
wrong-nebula wants to merge 1 commit into
Open
wrong-nebula wants to merge 1 commit into
wrong-nebula wants to merge 1 commit into
Conversation
Signed-off-by: wrong-nebula <263823322+wrong-nebula@users.noreply.github.com>
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes OpenColorIO's ARM64 (
OCIO_USE_SSE2NEON) hot CPU paths and diagonal matrixScaleRenderer/ScaleWithOffsetRendererloops while keeping outputs bit-exact across all bit depths, NaN/Inf edge cases, and odd pixel counts.What Changed
src/OpenColorIO/SSE2.h(SSE2RGBAPackunderOCIO_USE_SSE2NEON)BIT_DEPTH_UINT8: Single-instructionvqtbl1q_u8RGBA deinterleave onLoad;vcvtnq_u32_f32+ 2-levelvsliq_n_u32pack onStore(eliminatessse2neon's 2-instructionfrint32x+fcvtzson ARMv8.5+ andmrs fpcr+ 4-way rounding-mode switch on baseline ARMv8.0-A, plus 3×ext.16b+ 3×orr.16b). Becausesse2_clampguarantees finite inputs in[0, 255],vcvtnq_u32_f32is bit-identical to default round-to-nearest-even_mm_cvtps_epi32.SSE2RGBAPack16(UINT10,UINT12,UINT16):vld4_u16+vmovl_u16onLoad(removes 4×4 transpose);vcvtnq_u32_f32+vsliq_n_u32(..., 16)+vzip1q/vzip2qonStore(hardware-ablated faster thanvst4_u16on Apple Silicon).BIT_DEPTH_F16:vld4_u16+vcvt_f32_f16onLoadandvcvt_f16_f32+vst4_u16onStore, eliminating the 4×4 transpose on both paths while remaining portable across Clang, GCC, and MSVC ARM64 (_M_ARM64).BIT_DEPTH_F32:vld4q_f32/vst4q_f32replacing 4× load/store +sse2RGBATranspose_4x4.src/OpenColorIO/ops/lut1d/Lut1DOpCPU_SSE2.cpp(apply_lut_sse2underOCIO_USE_SSE2NEON)indices_p/n[4]andbuffer_p/n[4]gather buffers and computesnext_i = (i < max_idx) ? i + 1 : idirectly in GPR from extractedprev_ilanes (Max1DLUTLength = 300000 < 2^24), cutting NEON→GPR cross-domain transfers in half (24 → 12 per 4 pixels) and eliminating 3× floatfadd/fminnm/fcvtzschains.src/OpenColorIO/ops/lut3d/Lut3DOpCPU_SSE2.cpp(applyTetrahedralSSE2underOCIO_USE_SSE2NEON)* 4.0fpre-scale) and usesvshll_n_u32(..., 4)ingather_rgb_neon, eliminating 2×fmul * 4.0fand 16× per-lane GPRlsl #2shifts per 4 pixels.sse2neon's 11-instructionext.16b+zip1.2s+mov.dtranspose sequence with a 7-instruction 3-channelvzip1q/vzip2qtranspose.vbslq_f32inblendv_ps_sse2on full-lane comparison masks.src/OpenColorIO/ops/lut3d/Lut3DOpCPU.cpp(Lut3DRenderer::applytrilinear)_mm_loadu_ps(in)instead of 4-scalar_mm_set_ps.OCIO_USE_SSE2NEON, computes the 8 cube-corner voxel offsets directly in GPR from(l0, l1, l2)viavrndmq_f32+vcvtq_u32_f32and loads viavld1q_f32(optLut + idx * 4), eliminating the SSE2-emulated split-multiply/shuffleGetLut3DIndices+LookupNearest4path (~55 instructions/pixel).src/OpenColorIO/ops/matrix/MatrixOpCPU.cpp(ScaleRenderer,ScaleWithOffsetRenderer)#if OCIO_USE_SSE2128-bit SIMD loops (_mm_loadu_ps/_mm_mul_ps/_mm_add_ps/_mm_storeu_ps), fixing the compiler alias-check fallback to scalar 1-float-at-a-time execution on in-place (inImg == outImg) buffers across both ARM64 and x86.Benchmarks (Apple M1, paired alternating
dlopenA/B, 21 interleaved pairs, 16K RGBA pixels, median ± IQR)ScaleWithOffsetRenderer(in-place)ScaleWithOffsetRenderer(disjoint)ScaleRenderer(in-place)Lut3DTrilinear33³(Lut3DRenderer)SSE2RGBAPack<UINT8>Load+StoreLut1DF32→U8 (4096)SSE2RGBAPack<F16>Load+StoreLut1DF32→U16 (4096)Lut1DF32→F16 (4096)SSE2RGBAPack<UINT16>Load+StoreLut1DF32→F32 (4096)Lut3DTetrahedral33³(applyTetrahedralSSE2)Verification
Lut1Doutput bit depths (UINT8,UINT10,UINT12,UINT16,F16,F32),Lut3DTetrahedral and Trilinear, allSSE2RGBAPackroundtrips,ScaleRenderer(in-place & disjoint), andScaleWithOffsetRenderer(-ffp-contract=off), tested withNaN,±Inf,-0.0, subnormals, out-of-range values, and odd remainder pixel counts (1, 2, 3, 4, 5, 7, 13, 1023, 16384).UNSATin Z3 over the full OCIOMax1DLUTLength(300000) andMax3DLUTLength(129) domains.-fsanitize=address,undefined -fno-sanitize-recover=alland-Wall -Wextra -Werroron both Apple Silicon and baseline-march=armv8-a.