[FFmpeg-devel] [PATCH 2/2] Use gcc/clang builtins for av_sat_(add|sub)_64_c if available.
Michael Niedermayer
michael at niedermayer.cc
Wed May 27 21:09:47 EEST 2020
On Tue, May 26, 2020 at 12:23:41PM -0700, Dale Curtis wrote:
> On Fri, May 22, 2020 at 1:34 PM Michael Niedermayer <michael at niedermayer.cc>
> wrote:
>
> >
> > does this produce faster / better code ?
> > that is do compilers actually fail to optimize this from plain
> > clean C code ?
> >
>
> Here's the difference:
> clang trunk: https://godbolt.org/z/6SHmEo
interresting tool
but I tried it locally (plain C version with -O9)
av_sat_add64_c: # @av_sat_add64_c
.cfi_startproc
movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
testq %rsi, %rsi
js .LBB0_2
movq %rax, %rcx
subq %rsi, %rcx
cmpq %rdi, %rcx
jg .LBB0_2
retq
.LBB0_2:
addq $1, %rax
movq %rax, %rcx
subq %rsi, %rcx
leaq (%rsi,%rdi), %rdx
cmpq %rdi, %rcx
cmovlq %rdx, %rax
testq %rsi, %rsi
cmovgq %rdx, %rax
retq
.Lfunc_end0:
.size av_sat_add64_c, .Lfunc_end0-av_sat_add64_c
.cfi_endproc
# -- End function
.ident "clang version 9.0.0 (https://github.com/llvm/llvm-project/ 49b965079b18f8aa485dd1156dd088d40b7ee465)"
and the builtin one:
av_sat_add64_c: # @av_sat_add64_c
.cfi_startproc
leaq (%rdi,%rsi), %rcx
movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
leaq 1(%rax), %rdx
testq %rcx, %rcx
cmovnsq %rdx, %rax
addq %rsi, %rdi
cmovnoq %rdi, %rax
retq
so the builtin does better and both locally do better than clang on the web
tool
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200527/d8671110/attachment.sig>
More information about the ffmpeg-devel
mailing list