[FFmpeg-devel] [PATCH] Add support for "omp simd" pragma.

Martin Storsjö martin at martin.st
Wed Jan 13 10:04:23 EET 2021


Hi,

On Tue, 12 Jan 2021, Reimar Döffinger wrote:

> I’m not sure it will discourage it more than having to write
> the optimizations over and over, for Armv7 NEON, for Armv8 Linux,
> for Armv8 Windows, then SVE/SVE2, who knows maybe Armv9
> will also need a rewrite.

NEON code for armv8 windows and armv8 linux all use the exact same 
source, no need to write it twice.

> For example macOS we are lucky enough that the assembler etc. are
> largely compatible to Linux.

I'm not sure I'd say it's luck, it's pretty much by design there.

Historically, macOS build tools used an ancient fork of GAS, with very 
limited macroing capabilities. To remedy this, the gas-preprocessor tool 
was invented, for expanding modern gas macros, producing just a straight 
up feed of instructions, passed on to the native platform tools.

In modern times, the build tools are based on Clang/LLVM, and they support 
essentially all modern gas macro features (including altmacro, which was 
added in Clang 5). There's many parties that have an interest in this 
feature, e.g. support for building the Linux kernel with Clang.

Due to backwards compatibility with the old GAS fork's macroing capability 
(I think), there's some very vague differences between LLVM's macro 
support for other platforms and darwin, e.g. on other platforms, it's ok 
to invoke a macro as either "mymacro param1, param2" or "mymacro param1 
param2" (without commas between the arguments). On darwin targets, only 
the former works as intended.

All other platform differences are abstracted away with our macros in 
libavutil/aarch64/asm.S, see e.g. 
http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavutil/aarch64/asm.S;h=d1fa72b3c65a4a58e76029e94b998d935649aa90;hb=ca21cb1e36ccae2ee71d4299d477fa9284c1f551#l85.
For darwin platforms, the movrel macro expands to "add rX, rX, 
symbol at PAGEOFF" while it expands to "add rX, rX, :lo12:symbol" on other 
platforms (ELF and COFF).

All the source files just use the high level macros function, endfunc, 
movrel, etc, which handle the few platform specific details that differ.


If you write code with just one tool, it's of course certainly possible to 
accidentally use some corner case detail that another tool objects to, but 
that's why one needs testing on multiple platforms, via a CI system or 
FATE or whatever. Just like you regularly need to test C code on various 
platforms, even if you'd expect it to work if it's properly written.

> But for Windows-on-Arm there is no GNU assembler, and the Microsoft
> assembler needs a completely different syntax, so even the assembly
> we DO have just doesn’t work.

This is not true at all.

GCC and binutils don't support windows on arm/arm64 at all, that far is 
true.

But Clang/LLVM do (with https://github.com/mstorsjo/llvm-mingw you have an 
easily available packaged cross compiler and all), and they support the 
GAS syntax asm just fine.

If building with MSVC tools, yes you're right that armasm.exe/armasm64.exe 
takes a different syntax. But the gas-preprocessor tool (which is picked 
up automatically by our configure, one just needs to make sure it's 
available) handles expanding all the macros and rewriting directives into 
the armasm form, and feeding it to the armasm tools. Works fine and have 
done so for years. There's even a wiki page which tries to explain how to 
do it (although it's probably outdated in some aspects), see 
https://trac.ffmpeg.org/wiki/CompilationGuide/WinRT.

We even have regular fate tests of these configurations, see e.g. these:

http://fate.ffmpeg.org/report.cgi?slot=aarch64-mingw32-clang-trunk&time=20210113064430

http://fate.ffmpeg.org/report.cgi?time=20210109152105&slot=arm64-msvc2019

http://fate.ffmpeg.org/report.cgi?slot=armv7-mingw32-clang-trunk&time=20210113055653

http://fate.ffmpeg.org/report.cgi?time=20210109163844&slot=arm-msvc2019-phone

All of these run with full assembly optimizations enabled. So please don't 
tell me that our assembly doesn't work on windows on arm, because it does, 
and it has for years.

// Martin


More information about the ffmpeg-devel mailing list