Log in

View Full Version : x264 SIMD asm


dungeonlords
30th July 2023, 09:40
There is x264. It use a lot of x86 asm files. For example pixel-32.asm. This files can use different SIMD instruction set: mmx, 3DNow!, sse family, others

I need the simple way to automatically analyze every file. I want get which SIMD family in which file are used. How?

I think every asm file must contain information about which SIMD family it use (or information that no SIMD). Without this information it is very bad idea try to use this files...
I am angry, my x86 CPU support mmx and 3DNow! only, but x264 try call sse, so I get "Illegal instruction" sometimes. I plan to make patch for x264.

Let's communicate in this post (https://stackoverflow.com/questions/76755651/asm-simd-sniffer?noredirect=1#comment135379255_76755651)

FranceBB
30th July 2023, 12:56
Can't you just target the plain C on compile time with --disable-asm and produce a slow plain C executable that you can then run with --no-asm in the command line?
That should work.

dungeonlords
1st August 2023, 06:13
Can't you just target the plain C on compile time with --disable-asm and produce a slow plain C executable that you can then run with --no-asm in the command line?
That should work.

1) In which case I should use --disable-asm ?
When my CPU doesn't support ... what? What if minimal requirement to use x264 asm files? Can I use x264 if my CPU doesn't support AVX-512? Can I use x264 if my CPU doesn't support sse2? Can I use x264 if my CPU doesn't support sse? And so on...

2) Ok, Let's think my CPU doesn't support anything... Anyway, no, I can't use --disable-asm. Because x264 try use not unisex CFLAGS without any cheking, this is code from x264/git/configure
CFLAGS="$CFLAGS -mfpmath=sse -msse -msse2"
x264 should checking SIMD support before use this CFLAGS, isn't it? x264 can check using GNU autoconf (https://www.gnu.org/software/autoconf-archive/ax_check_x86_features.html). But my dream is change build system to cmake (https://stackoverflow.com/questions/50935181/how-should-sse-flags-be-added-with-modern-cmake) or meson like OpenH264 (https://github.com/cisco/openh264). What are you thinking about it?

Let's communicate in this post (https://stackoverflow.com/questions/76755651/asm-simd-sniffer?noredirect=1#comment135379255_76755651)

MasterNobody
1st August 2023, 09:13
1) When you trying to use it on something unsupported. i.e. doesn't support at least SSE2 for x86. Very minimum is SSE which implies MMXExt but need extra params to configure from item 2.
2) Add --extra-cflags="-mfpmath=387" to configure and it wouldn't add this options. But dunno if inline asm will work or would it be disabled. You probably may need to specify `-march` option also.

dungeonlords
1st August 2023, 11:27
1) When you trying to use it on something unsupported. i.e. doesn't support at least SSE2 for x86. Very minimum is SSE which implies MMXExt but need extra params to configure from item 2.
2) Add --extra-cflags="-mfpmath=387" to configure and it wouldn't add this options. But dunno if inline asm will work or would it be disabled. You probably may need to specify `-march` option also.
Thank you.

1) "1) When you trying to use it on something unsupported. i.e. doesn't support at least SSE2 for x86. Very minimum is SSE which implies MMXExt but need extra params to configure from item 2."
SSE2 for x86? Are you sure? If my x86 CPU supports SSE, SSE2 and not support SSE3, SSSE3, SSE4.1,... then I can use x264 asm files or not?

2) But I have (https://en.wikipedia.org/wiki/Geode_(processor)) not i686 but i586. How change it? This way?
--extra-cflags="-march=i586 -mfpmath=387"

3) I still think x264 should at least check does x86 CPU support sse and show Error if not. At now I can build x264 for my CPU and I get "Illegal instruction" and linux session restart... Best way I think is adaptive current settings to CPU capabilities like openh264 (https://github.com/cisco/openh264) project.

4) Because of 3) many scripts like buildroot doesn't provide capabilities to change x264 build script...

5) my dream is change build system to cmake (https://stackoverflow.com/questions/50935181/how-should-sse-flags-be-added-with-modern-cmake) or meson like OpenH264 (https://github.com/cisco/openh264). What are you thinking about it?

Let's communicate in this post (https://stackoverflow.com/questions/76755651/asm-simd-sniffer?noredirect=1#comment135379255_76755651)

MasterNobody
1st August 2023, 21:57
1) SSE2 for x86? Are you sure? If my x86 CPU supports SSE, SSE2 and not support SSE3, SSSE3, SSE4.1,... then I can use x264 asm files or not?
Yes, you can use it because x264 autodetects supported instruction set.
2) But I have (https://en.wikipedia.org/wiki/Geode_(processor)) not i686 but i586. How change it? This way?
--extra-cflags="-march=i586 -mfpmath=387"
Yes, you need to specify -march=i586 for configure. But it also doesn't make sense to bloat binary with handwritten asm which wouldn't be used in this case (on your CPU). So you need to use:
--disable-asm --extra-cflags="-march=i586 -mfpmath=387"
3) I still think x264 should at least check does x86 CPU support sse and show Error if not. At now I can build x264 for my CPU and I get "Illegal instruction" and linux session restart... Best way I think is adaptive current settings to CPU capabilities like openh264 (https://github.com/cisco/openh264) project.

It checks CPU support but your main problem is C compiled code and inlined asm, not the handwritten external asm. So if C compiler used instructions not supported by your CPU it can SIGILL even before we run CPU detection code. So no, it is not possible.
4) Because of 3) many scripts like buildroot doesn't provide capabilities to change x264 build script...

5) my dream is change build system to cmake (https://stackoverflow.com/questions/50935181/how-should-sse-flags-be-added-with-modern-cmake) or meson like OpenH264 (https://github.com/cisco/openh264). What are you thinking about it?
That is your problem, and not x264 problem, so I don't care.