[FFmpeg-devel] [PATCH v2 3/3] avfilter/vf_colordetect: add x86 SIMD implementation
James Almer
jamrial at gmail.com
Thu Jul 17 01:21:55 EEST 2025
On 7/16/2025 6:49 PM, Niklas Haas wrote:
> On Wed, 16 Jul 2025 17:25:12 -0300 James Almer <jamrial at gmail.com> wrote:
>> On 7/16/2025 1:24 PM, Niklas Haas wrote:
>>> +cglobal detect_alpha%1_%3, 6, 7, 6, color, color_stride, alpha, alpha_stride, width, height, x
>>> + pxor m0, m0
>>> + add colorq, widthq
>>> + add alphaq, widthq
>>> + neg widthq
>>> +%ifidn %3, limited
>>> +%if ARCH_X86_64
>>> + movq xm3, r6mp ; p
>>> + movq xm4, r7mp ; q
>>> + movq xm5, r8mp ; k
>>
>> They are int arguments, so no point using movq.
>
> This is to avoid an error:
>
> src/libavfilter/x86/vf_colordetect.asm:145: error: invalid combination of opcode and operands
> src/libavfilter/x86/vf_colordetect.asm:75: ... from macro `detect_alpha_fn' defined here
> src//libavutil/x86/x86inc.asm:1518: ... from macro `movd' defined here
> src//libavutil/x86/x86inc.asm:1501: ... from macro `RUN_AVX_INSTR' defined here
That's probably because of the mp suffix. If you use m, it works (as in,
"movd xm3, r6m").
In any case, you can just combine these into a single vpbroadcast%2 that
reads from memory:
%ifidn %3, limited
vpbroadcast%2 m3, r6m
vpbroadcast%2 m4, r7m
vpbroadcast%2 m5, r8m
%endif
>
>>
>>> +%else
>>> + movd xm3, r6mp ; p
>>> + movd xm4, r7mp ; q
>>> + movd xm5, r8mp ; k
>>> +%endif
>>> + vpbroadcast%2 m3, xm3
>>> + vpbroadcast%2 m4, xm4
>>> + vpbroadcast%2 m5, xm5
>>> +%endif
>>> +.lineloop:
>>> + mov xq, widthq
>>> + .loop:
>>> + %ifidn %3, full
>>> + movu m1, [colorq + xq]
>>> + movu m2, [alphaq + xq]
>>> + pmaxu%1 m1, m2
>>> + %else
>>> + pmovzx%1%2 m1, [colorq + xq]
>>> + pmovzx%1%2 m2, [alphaq + xq]
>>> + pmull%2 m1, m3
>>> + pmull%2 m2, m4
>>
>> pmulld is painfully slow, so try to instead use pmaddwd. It should be
>> doable because the input are words.
>
> Will give it a try tomorrow.
>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20250716/c5fea90b/attachment.sig>
More information about the ffmpeg-devel
mailing list