Patch: Inline asm fixes for Intel compiler on Windows
Hey, I made a patch that changes some of the inline asm found in FFmpeg so that it will compile under windows natively using the Intel compiler. The Intel compiler supports AT&T inline assembly syntax but doesnt have all the functionality that GAS has. A result is that a few things need to be slightly tweaked. Mostly this just involves changing direct symbol references to asm-interfaces. The attached patch should not change the functionality of FFmpeg in any way as it just changes the syntax of some instructions so that it will compile. That said there are a few sections where the code required slightly more complicated changes in order to work. These are x86/cabac.h in the BRANCHLESS_GET_CABAC macro and mlpdsp.c. The macro in cabac.h just requires some slightly more complicated asm-interface conversions that someone more familiar with the code may want to have a look at. mlpdsp.c uses some runtime jump lists that would require an almost complete rewrite to work on Intel which is probably not worth it. So at the moment both of these are simply skipped if the Intel compile is detected. All other asm works fine though. Code was compiled on Windows in Intel and using gcc 4.8 to ensure compatibility. All code was tested and past FATE. Matt
Matt Oliver <protogonoi <at> gmail.com> writes: [...]
- "pmullw "MANGLE(MUL2)", %%mm7\n\t"\ + "pmullw "#MUL2", %%mm7 \n\t"\
Does this fail at compile time or link time? Is is really impossible to make MANGLE() compatible?
+#if !defined(__INTEL_COMPILER) + , "%"REG_SP +#endif
(Sorry if this is obvious.) Why is this not under "!( defined(__INTEL_COMPILER) && defined(_MSC_VER) )"?
-//MMX versions -#if HAVE_MMX_INLINE -#undef RENAME -#undef COMPILE_TEMPLATE_MMXEXT -#define COMPILE_TEMPLATE_MMXEXT 0 -#define RENAME(a) a ## _MMX -#include "yuv2rgb_template.c" -#endif /* HAVE_MMX_INLINE */ - // MMXEXT versions #if HAVE_MMXEXT_INLINE #undef RENAME @@ -66,6 +57,15 @@ #include "yuv2rgb_template.c" #endif /* HAVE_MMXEXT_INLINE */
+//MMX versions +#if HAVE_MMX_INLINE +#undef RENAME +#undef COMPILE_TEMPLATE_MMXEXT +#define COMPILE_TEMPLATE_MMXEXT 0 +#define RENAME(a) a ## _MMX +#include "yuv2rgb_template.c" +#endif /* HAVE_MMX_INLINE */ +
Is this related / intended? Carl Eugen
On Sat, Dec 28, 2013 at 11:35:31AM +1100, Matt Oliver wrote:
Hey, I made a patch that changes some of the inline asm found in FFmpeg so that it will compile under windows natively using the Intel compiler. The Intel compiler supports AT&T inline assembly syntax but doesnt have all the functionality that GAS has. A result is that a few things need to be slightly tweaked. Mostly this just involves changing direct symbol references to asm-interfaces.
The attached patch should not change the functionality of FFmpeg in any way as it just changes the syntax of some instructions so that it will compile.
That said there are a few sections where the code required slightly more complicated changes in order to work. These are x86/cabac.h in the BRANCHLESS_GET_CABAC macro and mlpdsp.c. The macro in cabac.h just requires some slightly more complicated asm-interface conversions that someone more familiar with the code may want to have a look at. mlpdsp.c uses some runtime jump lists that would require an almost complete rewrite to work on Intel which is probably not worth it. So at the moment both of these are simply skipped if the Intel compile is detected. All other asm works fine though.
Code was compiled on Windows in Intel and using gcc 4.8 to ensure compatibility. All code was tested and past FATE.
The patch doesnt apply: Applying: Patch: Inline asm fixes for Intel compiler on Windows Using index info to reconstruct a base tree... error: patch failed: libavcodec/x86/mpegvideoenc_template.c:168 error: libavcodec/x86/mpegvideoenc_template.c: patch does not apply Did you hand edit your patch? It does not apply to blobs recorded in its index. Cannot fall back to three-way merge. trying to apply the patch with "patch" does not result in code that can be compiled. In file included from /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb.c:57:0: /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 7 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 8 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 9 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 10 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 11 is not directly addressable about the changes themselfs, its unlikely that adding operands to asm will work. These will break some versions of gcc and clang on x86-32 (and i would not be surprised if they break intels compiler the same way) If you want to add operands anyway, then you have to convince us that its safe on all supported compilers with all common use cases (position independant code, and various optimization levels for example) (testing with 2-3 old compilers from the 2.95 /3.* era might do, but its still alot of work so if theres an alternative to adding operands that would likely be easier) also successfull compilation alone isnt enough, old gcc versions are known to silently miscompile code that has more than 9 or 10 (and "+" operands counts as 2) operands to an asm like in the case below also, if you add operands, the code needs to be benchmarked or the generated asm compared, gcc (especially at lower optimization levels and with position independant code has the tendency to add extra code) for benchmarking START/STOP_TIMER could be used So i would suggest that a differnt solution is used than adding operands, if possible
: "+r"(block) - : + : "m"(*m127), "m"(*iTab1), "m"(*walkenIdctRounders), "m"(*iTab2), "m"(*iTab3), "m"(*iTab4), + "m"(*tan3), "m"(*tan1), "m"(*tan2), "m"(*sqrt2) : XMM_CLOBBERS("%xmm0" , "%xmm1" , "%xmm2" , "%xmm3" , "%xmm4" , "%xmm5" , "%xmm6" , "%xmm7" ,)
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have often repented speaking, but never of holding my tongue. -- Xenocrates
Michael Niedermayer <michaelni <at> gmx.at> writes:
(testing with 2-3 old compilers from the 2.95
I don't think 2.95.3 can be used to compile unpatched FFmpeg git head. Carl Eugen
On Sat, Dec 28, 2013 at 01:34:26PM +0000, Carl Eugen Hoyos wrote:
Michael Niedermayer <michaelni <at> gmx.at> writes:
(testing with 2-3 old compilers from the 2.95
I don't think 2.95.3 can be used to compile unpatched FFmpeg git head.
ok, in that case some older gcc 3 versions should do PS: iam interrested in the errors that gcc 2.95 generates when building ffmpeg ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Observe your enemies, for they first find out your faults. -- Antisthenes
On Sat, Dec 28, 2013 at 03:04:43PM +0100, Michael Niedermayer wrote:
On Sat, Dec 28, 2013 at 01:34:26PM +0000, Carl Eugen Hoyos wrote:
Michael Niedermayer <michaelni <at> gmx.at> writes:
(testing with 2-3 old compilers from the 2.95
I don't think 2.95.3 can be used to compile unpatched FFmpeg git head.
ok, in that case some older gcc 3 versions should do
PS: iam interrested in the errors that gcc 2.95 generates when building ffmpeg ?
It misses some C99 features mostly. Empty macro arguments not supported (to be honest, I find use of that feature somewhat questionable): libavdevice/v4l2.c:132: macro `SET_WRAPPERS' used without args libavcodec/mss1.c:63: macro `ARITH_GET_BIT' used without args libavcodec/mss1.c:108: macro `ARITH_GET_MODEL_SYM' used without args libswresample/x86/swresample_x86.c:28: macro `PROTO4' used without args Compound statement (surprisingly the only place where we use it?!): libavfilter/af_aresample.c:101: invalid use of non-lvalue array More than 10 asm operands: libavcodec/x86/h264_i386.h: In function `decode_significance_x86': libavcodec/x86/h264_i386.h:113: more than 10 operands in `asm' libavcodec/x86/h264_i386.h: In function `decode_significance_8x8_x86': libavcodec/x86/h264_i386.h:198: more than 10 operands in `asm' libavcodec/x86/dsputil_x86.c: In function `ff_add_hfyu_median_prediction_cmov': libavcodec/x86/dsputil_x86.c:59: more than 10 operands in `asm' libavcodec/x86/mlpdsp.c: In function `mlp_filter_channel_x86': libavcodec/x86/mlpdsp.c:174: more than 10 operands in `asm' Doesn't like ecx clobber (?): libavcodec/x86/cabac.h:205: Invalid `asm' statement: libavcodec/x86/cabac.h:205: fixed or forbidden register 2 (cx) was spilled for class GENERAL_REGS. No native atomics and not compatible with my system's pthreads (?) libavutil/atomic.c:30: extra brace group at end of initializer libavutil/log.c:45: extra brace group at end of initializer No va_copy: cmdutils.c:102: undefined reference to `va_copy' That _seems_ to be all, but I of course didn't end up with anything working after wildly commenting out the broken code (didn't link).
On Mon, Dec 30, 2013 at 12:38:20AM +0100, Reimar Döffinger wrote:
On Sat, Dec 28, 2013 at 03:04:43PM +0100, Michael Niedermayer wrote:
On Sat, Dec 28, 2013 at 01:34:26PM +0000, Carl Eugen Hoyos wrote:
Michael Niedermayer <michaelni <at> gmx.at> writes:
(testing with 2-3 old compilers from the 2.95
I don't think 2.95.3 can be used to compile unpatched FFmpeg git head.
ok, in that case some older gcc 3 versions should do
PS: iam interrested in the errors that gcc 2.95 generates when building ffmpeg ?
It misses some C99 features mostly.
Empty macro arguments not supported (to be honest, I find use of that feature somewhat questionable): libavdevice/v4l2.c:132: macro `SET_WRAPPERS' used without args libavcodec/mss1.c:63: macro `ARITH_GET_BIT' used without args libavcodec/mss1.c:108: macro `ARITH_GET_MODEL_SYM' used without args libswresample/x86/swresample_x86.c:28: macro `PROTO4' used without args
Compound statement (surprisingly the only place where we use it?!): libavfilter/af_aresample.c:101: invalid use of non-lvalue array
More than 10 asm operands: libavcodec/x86/h264_i386.h: In function `decode_significance_x86': libavcodec/x86/h264_i386.h:113: more than 10 operands in `asm' libavcodec/x86/h264_i386.h: In function `decode_significance_8x8_x86': libavcodec/x86/h264_i386.h:198: more than 10 operands in `asm' libavcodec/x86/dsputil_x86.c: In function `ff_add_hfyu_median_prediction_cmov': libavcodec/x86/dsputil_x86.c:59: more than 10 operands in `asm' libavcodec/x86/mlpdsp.c: In function `mlp_filter_channel_x86': libavcodec/x86/mlpdsp.c:174: more than 10 operands in `asm'
Doesn't like ecx clobber (?): libavcodec/x86/cabac.h:205: Invalid `asm' statement: libavcodec/x86/cabac.h:205: fixed or forbidden register 2 (cx) was spilled for class GENERAL_REGS.
No native atomics and not compatible with my system's pthreads (?) libavutil/atomic.c:30: extra brace group at end of initializer libavutil/log.c:45: extra brace group at end of initializer
No va_copy: cmdutils.c:102: undefined reference to `va_copy'
It's called __va_copy, so easily fixable if desired. However there is no point unless the macro issues were to be fixed I'd say. That would then allow to test at least with asm disabled if anyone desires. Haiku might be one of the last platforms that have a somewhat maintained gcc 2.95 setup if someone wanted to have it tested... (though even they use a newer compiler for most things nowadays).
On 28.12.2013, at 14:28, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sat, Dec 28, 2013 at 11:35:31AM +1100, Matt Oliver wrote:
Hey, I made a patch that changes some of the inline asm found in FFmpeg so that it will compile under windows natively using the Intel compiler. The Intel compiler supports AT&T inline assembly syntax but doesnt have all the functionality that GAS has. A result is that a few things need to be slightly tweaked. Mostly this just involves changing direct symbol references to asm-interfaces.
The attached patch should not change the functionality of FFmpeg in any way as it just changes the syntax of some instructions so that it will compile.
That said there are a few sections where the code required slightly more complicated changes in order to work. These are x86/cabac.h in the BRANCHLESS_GET_CABAC macro and mlpdsp.c. The macro in cabac.h just requires some slightly more complicated asm-interface conversions that someone more familiar with the code may want to have a look at. mlpdsp.c uses some runtime jump lists that would require an almost complete rewrite to work on Intel which is probably not worth it. So at the moment both of these are simply skipped if the Intel compile is detected. All other asm works fine though.
Code was compiled on Windows in Intel and using gcc 4.8 to ensure compatibility. All code was tested and past FATE.
The patch doesnt apply:
Applying: Patch: Inline asm fixes for Intel compiler on Windows Using index info to reconstruct a base tree... error: patch failed: libavcodec/x86/mpegvideoenc_template.c:168 error: libavcodec/x86/mpegvideoenc_template.c: patch does not apply Did you hand edit your patch? It does not apply to blobs recorded in its index. Cannot fall back to three-way merge.
trying to apply the patch with "patch" does not result in code that can be compiled. In file included from /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb.c:57:0: /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 7 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 8 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 9 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 10 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 11 is not directly addressable
about the changes themselfs, its unlikely that adding operands to asm will work. These will break some versions of gcc and clang on x86-32 (and i would not be surprised if they break intels compiler the same way)
More importantly, it actually changes the code. As soon as PIC is enabled, a "m" reference can no longer be stored as a constant. But the code requires it to be a constant. Or to put it simpler: the patch is simply wrong for 32 bit PIC. (and before we start a discussion again: yes, this "hack" means FFmpeg has TEXTRELs in the asm code even for PIC compilation. Since it affects only 32 bit I don't consider it very relevant). That said, I also have a very hard time believing that ICC assembler support cannot access global symbols from asm. I find that highly unlikely, more like the MANGLE macro and/or the macros that force these symbols to be exported are not working.
On 29 December 2013 00:58, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On Sat, Dec 28, 2013 at 11:35:31AM +1100, Matt Oliver wrote:
Hey, I made a patch that changes some of the inline asm found in FFmpeg so
On 28.12.2013, at 14:28, Michael Niedermayer <michaelni@gmx.at> wrote: that
it will compile under windows natively using the Intel compiler. The Intel compiler supports AT&T inline assembly syntax but doesnt have all the functionality that GAS has. A result is that a few things need to be slightly tweaked. Mostly this just involves changing direct symbol references to asm-interfaces.
The attached patch should not change the functionality of FFmpeg in any way as it just changes the syntax of some instructions so that it will compile.
That said there are a few sections where the code required slightly more complicated changes in order to work. These are x86/cabac.h in the BRANCHLESS_GET_CABAC macro and mlpdsp.c. The macro in cabac.h just requires some slightly more complicated asm-interface conversions that someone more familiar with the code may want to have a look at. mlpdsp.c uses some runtime jump lists that would require an almost complete rewrite to work on Intel which is probably not worth it. So at the moment both of these are simply skipped if the Intel compile is detected. All other asm works fine though.
Code was compiled on Windows in Intel and using gcc 4.8 to ensure compatibility. All code was tested and past FATE.
The patch doesnt apply:
Applying: Patch: Inline asm fixes for Intel compiler on Windows Using index info to reconstruct a base tree... error: patch failed: libavcodec/x86/mpegvideoenc_template.c:168 error: libavcodec/x86/mpegvideoenc_template.c: patch does not apply Did you hand edit your patch? It does not apply to blobs recorded in its index. Cannot fall back to three-way merge.
trying to apply the patch with "patch" does not result in code that can be compiled. In file included from /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb.c:57:0: /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 7 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 8 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 9 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 10 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 11 is not directly addressable
about the changes themselfs, its unlikely that adding operands to asm will work. These will break some versions of gcc and clang on x86-32 (and i would not be surprised if they break intels compiler the same way)
More importantly, it actually changes the code. As soon as PIC is enabled, a "m" reference can no longer be stored as a constant. But the code requires it to be a constant. Or to put it simpler: the patch is simply wrong for 32 bit PIC. (and before we start a discussion again: yes, this "hack" means FFmpeg has TEXTRELs in the asm code even for PIC compilation. Since it affects only 32 bit I don't consider it very relevant). That said, I also have a very hard time believing that ICC assembler support cannot access global symbols from asm. I find that highly unlikely, more like the MANGLE macro and/or the macros that force these symbols to be exported are not working.
OK Sorry about the patch not sure what happened there. Im downloading a fresh copy of git master that ill use to make up a fresh one. As for Intels asm support, on Linux they just use GAS directly for compiling all asm. But on Windows they had to implement it themselves and so it is incomplete. To quote Intel themselves "Direct symbol references in the asm-template are not supported. To access a C++ object, use the asm-interface with a substitution directive." This is from : http://software.intel.com/sites/products/documentation/doclib/iss/2013/compi... which also lists all the other limitations of inline AT&T asm on Windows. So unfortunately there is not really any other option (that I can think of anyway). So if using memory "m" constraint cant be used with PIC how would you recommend this problem be approached? Im happy to allocate the time needed to come up with the ideal solution so any input is appreciated.
On Sun, Dec 29, 2013 at 01:25:05AM +1100, Matt Oliver wrote:
More importantly, it actually changes the code. As soon as PIC is enabled, a "m" reference can no longer be stored as a constant. But the code requires it to be a constant. Or to put it simpler: the patch is simply wrong for 32 bit PIC. (and before we start a discussion again: yes, this "hack" means FFmpeg has TEXTRELs in the asm code even for PIC compilation. Since it affects only 32 bit I don't consider it very relevant). That said, I also have a very hard time believing that ICC assembler support cannot access global symbols from asm. I find that highly unlikely, more like the MANGLE macro and/or the macros that force these symbols to be exported are not working.
OK Sorry about the patch not sure what happened there. Im downloading a fresh copy of git master that ill use to make up a fresh one.
As for Intels asm support, on Linux they just use GAS directly for compiling all asm. But on Windows they had to implement it themselves and so it is incomplete. To quote Intel themselves "Direct symbol references in the asm-template are not supported. To access a C++ object, use the asm-interface with a substitution directive." This is from : http://software.intel.com/sites/products/documentation/doclib/iss/2013/compi... which also lists all the other limitations of inline AT&T asm on Windows.
So unfortunately there is not really any other option (that I can think of anyway). So if using memory "m" constraint cant be used with PIC how would you recommend this problem be approached?
Im happy to allocate the time needed to come up with the ideal solution so any input is appreciated.
Well, there is the brute-force approach of using the support for .byte to define that symbol each and every time it is used. But that might be more ugly than what we'd want to accept as a patch...
On Sun, Dec 29, 2013 at 01:25:05AM +1100, Matt Oliver wrote:
On 29 December 2013 00:58, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On Sat, Dec 28, 2013 at 11:35:31AM +1100, Matt Oliver wrote:
Hey, I made a patch that changes some of the inline asm found in FFmpeg so
On 28.12.2013, at 14:28, Michael Niedermayer <michaelni@gmx.at> wrote: that
it will compile under windows natively using the Intel compiler. The Intel compiler supports AT&T inline assembly syntax but doesnt have all the functionality that GAS has. A result is that a few things need to be slightly tweaked. Mostly this just involves changing direct symbol references to asm-interfaces.
The attached patch should not change the functionality of FFmpeg in any way as it just changes the syntax of some instructions so that it will compile.
That said there are a few sections where the code required slightly more complicated changes in order to work. These are x86/cabac.h in the BRANCHLESS_GET_CABAC macro and mlpdsp.c. The macro in cabac.h just requires some slightly more complicated asm-interface conversions that someone more familiar with the code may want to have a look at. mlpdsp.c uses some runtime jump lists that would require an almost complete rewrite to work on Intel which is probably not worth it. So at the moment both of these are simply skipped if the Intel compile is detected. All other asm works fine though.
Code was compiled on Windows in Intel and using gcc 4.8 to ensure compatibility. All code was tested and past FATE.
The patch doesnt apply:
Applying: Patch: Inline asm fixes for Intel compiler on Windows Using index info to reconstruct a base tree... error: patch failed: libavcodec/x86/mpegvideoenc_template.c:168 error: libavcodec/x86/mpegvideoenc_template.c: patch does not apply Did you hand edit your patch? It does not apply to blobs recorded in its index. Cannot fall back to three-way merge.
trying to apply the patch with "patch" does not result in code that can be compiled. In file included from /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb.c:57:0: /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 7 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 8 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 9 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 10 is not directly addressable /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 11 is not directly addressable
about the changes themselfs, its unlikely that adding operands to asm will work. These will break some versions of gcc and clang on x86-32 (and i would not be surprised if they break intels compiler the same way)
More importantly, it actually changes the code. As soon as PIC is enabled, a "m" reference can no longer be stored as a constant. But the code requires it to be a constant. Or to put it simpler: the patch is simply wrong for 32 bit PIC. (and before we start a discussion again: yes, this "hack" means FFmpeg has TEXTRELs in the asm code even for PIC compilation. Since it affects only 32 bit I don't consider it very relevant). That said, I also have a very hard time believing that ICC assembler support cannot access global symbols from asm. I find that highly unlikely, more like the MANGLE macro and/or the macros that force these symbols to be exported are not working.
OK Sorry about the patch not sure what happened there. Im downloading a fresh copy of git master that ill use to make up a fresh one.
As for Intels asm support, on Linux they just use GAS directly for compiling all asm. But on Windows they had to implement it themselves and so it is incomplete. To quote Intel themselves "Direct symbol references in the asm-template are not supported. To access a C++ object, use the asm-interface with a substitution directive." This is from : http://software.intel.com/sites/products/documentation/doclib/iss/2013/compi... which also lists all the other limitations of inline AT&T asm on Windows.
So unfortunately there is not really any other option (that I can think of anyway). So if using memory "m" constraint cant be used with PIC how would you recommend this problem be approached?
Im happy to allocate the time needed to come up with the ideal solution so any input is appreciated.
code that is not frequently called could be rewritten to yasm syntax and put in seperate .asm files, this will not work for all cases though, also it would be quite alot of work and would be best done in small steps and patches ... or maybe intels assembler could be fixed or replaced but first, theres still something i dont understand C does support accesing global and static symbols, am i assuming correctly that intels C compler generates asm that is mixed with the asm from asm() statements? If so what does intels C compiler generate to access such symbols ? Iam asking as the same could be used to implement MANGLE() possibly Thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Freedom in capitalist society always remains about the same as it was in ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
On 29 December 2013 13:48, Michael Niedermayer <michaelni@gmx.at> wrote:
On 29 December 2013 00:58, Reimar Döffinger <Reimar.Doeffinger@gmx.de wrote:
On Sat, Dec 28, 2013 at 11:35:31AM +1100, Matt Oliver wrote:
Hey, I made a patch that changes some of the inline asm found in FFmpeg so
On 28.12.2013, at 14:28, Michael Niedermayer <michaelni@gmx.at> wrote: that
it will compile under windows natively using the Intel compiler. The Intel compiler supports AT&T inline assembly syntax but doesnt have all
functionality that GAS has. A result is that a few things need to be slightly tweaked. Mostly this just involves changing direct symbol references to asm-interfaces.
The attached patch should not change the functionality of FFmpeg in any way as it just changes the syntax of some instructions so that it will compile.
That said there are a few sections where the code required slightly more complicated changes in order to work. These are x86/cabac.h in the BRANCHLESS_GET_CABAC macro and mlpdsp.c. The macro in cabac.h just requires some slightly more complicated asm-interface conversions that someone more familiar with the code may want to have a look at. mlpdsp.c uses some runtime jump lists that would require an almost complete rewrite to work on Intel which is probably not worth it. So at the moment both of
On Sun, Dec 29, 2013 at 01:25:05AM +1100, Matt Oliver wrote: the these are
simply skipped if the Intel compile is detected. All other asm works fine though.
Code was compiled on Windows in Intel and using gcc 4.8 to ensure compatibility. All code was tested and past FATE.
The patch doesnt apply:
Applying: Patch: Inline asm fixes for Intel compiler on Windows Using index info to reconstruct a base tree... error: patch failed: libavcodec/x86/mpegvideoenc_template.c:168 error: libavcodec/x86/mpegvideoenc_template.c: patch does not apply Did you hand edit your patch? It does not apply to blobs recorded in its index. Cannot fall back to three-way merge.
trying to apply the patch with "patch" does not result in code that can be compiled. In file included from /home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb.c:57:0:
/home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 7 is not directly addressable
/home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 8 is not directly addressable
/home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 9 is not directly addressable
/home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 10 is not directly addressable
/home/michael/ffmpeg-git/ffmpeg/libswscale/x86/yuv2rgb_template.c:333:9: error: memory input 11 is not directly addressable
about the changes themselfs, its unlikely that adding operands to asm will work. These will break some versions of gcc and clang on x86-32 (and i would not be surprised if they break intels compiler the same way)
More importantly, it actually changes the code. As soon as PIC is enabled, a "m" reference can no longer be stored as a constant. But the code requires it to be a constant. Or to put it simpler: the patch is simply wrong for 32 bit PIC. (and before we start a discussion again: yes, this "hack" means FFmpeg has TEXTRELs in the asm code even for PIC compilation. Since it affects only 32 bit I don't consider it very relevant). That said, I also have a very hard time believing that ICC assembler support cannot access global symbols from asm. I find that highly unlikely, more like the MANGLE macro and/or the macros that force these symbols to be exported are not working.
OK Sorry about the patch not sure what happened there. Im downloading a fresh copy of git master that ill use to make up a fresh one.
As for Intels asm support, on Linux they just use GAS directly for compiling all asm. But on Windows they had to implement it themselves and so it is incomplete. To quote Intel themselves "Direct symbol references in the asm-template are not supported. To access a C++ object, use the asm-interface with a substitution directive." This is from :
http://software.intel.com/sites/products/documentation/doclib/iss/2013/compi...
which also lists all the other limitations of inline AT&T asm on Windows.
So unfortunately there is not really any other option (that I can think of anyway). So if using memory "m" constraint cant be used with PIC how would you recommend this problem be approached?
Im happy to allocate the time needed to come up with the ideal solution so any input is appreciated.
code that is not frequently called could be rewritten to yasm syntax and put in seperate .asm files, this will not work for all cases though, also it would be quite alot of work and would be best done in small steps and patches ...
or maybe intels assembler could be fixed or replaced
but first, theres still something i dont understand C does support accesing global and static symbols, am i assuming correctly that intels C compler generates asm that is mixed with the asm from asm() statements? If so what does intels C compiler generate to access such symbols ? Iam asking as the same could be used to implement MANGLE() possibly
Thanks
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Freedom in capitalist society always remains about the same as it was in ancient Greek republics: Freedom for slave owners. -- Vladimir Lenin
YASM would be the obvious solution to ensure wide compiler compatibility but as you said would require a significant amount of work. Also would there be a notable performance decrease to doing this? Is inline still preferred? Intels compiler handles symbol naming pretty much as you would expect. The problem is that the inline asm compiler seems to be separated in that the generated code from the inline asm pass resolves symbol names before being linked in with the rest of the code (or in this case errors on symbol names). So symbols are not exported across units unless they are in the asm-interface. So any attempt to use a direct symbol reference will automatically generate an error such as: "error : The direct symbol reference in mov is currently unsupported. Access symbols through the asm interface." So it doesnt even bother to check the symbol name it just automatically errors should anyone try to reference one directly. The ideal solution would be Intel updating there compiler to support direct symbols but I believe they have indicated it is not high on their list of priorities and I doubt they will let someone else try and fix it (hell id fix it if they'd let me!). So if someone knows someone on the compiler team then feel free to prod them otherwise we still have to try and work around it as best we can. If using "m" is an issue with PIC then that posses a problem. I had hoped the compiler would be smart enough to optimise constants but I guess that is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly. Anyway I have created a new patch based on current git master. It doesnt include any new changes from last time but it should apply correctly. Ill update the patch once theres a consensus on how to handle PIC etc.
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
If using "m" is an issue with PIC then that posses a problem. I had hoped the compiler would be smart enough to optimise constants but I guess that is to much to ask.
1) Compilers are never smart enough to reliably do even the most trivial stuff. That is basically a constant over decades of development. 2) It isn't a constant, not even if PIC is disabled, since dynamic libraries always must be relocatable. You could of course use the "constant" constraint instead of "memory", but that would probably fail even more often (it also would make the PIC issue obvious by failing compile time, assuming you even get it to work when PIC is disabled). Still leaves the issue with > 9 arguments. 3) It very much isn't a constant at all if PIC is enabled, especially on 32 bit x86 which is about as unsuitable for PIC as you can get.
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB You can kill me, but you cannot change the truth.
On 30 December 2013 02:26, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
Using named asm constraints is a good idea as it seems that Intel compiler supports those. So I will update the patch so that MANGLE remains in use but it will just change to a named asm constraint on Intel+Windows. Combine that with a macro such as XMM_CLOBBERS_ONLY in order to add the necessary asm interfaces and that should work fine. That one thing I did notice though is that if the use of "m" constraints with PIC is an issue then there are several locations in existing code that dont seem to follow that. For instance in libavcodec/x86/cavsdsp.c the macro QPEL_CAVSV1 uses a asm interface for MUL1 (which is variable ff_pw_96 and is assigned to %5). However MUL2 (which is variable ff_pw_42) is used as a direct symbol through MANGLE. Since both these variables are defined in the same place and are of the same type (uint64_t) then it appears there are some inconsistencies in existing FFmpeg code. Ill leave all existing instances of MANGLE but i thought id just point this out.
On 30.12.2013, at 03:06, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 02:26, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
Using named asm constraints is a good idea as it seems that Intel compiler supports those. So I will update the patch so that MANGLE remains in use but it will just change to a named asm constraint on Intel+Windows. Combine that with a macro such as XMM_CLOBBERS_ONLY in order to add the necessary asm interfaces and that should work fine.
That one thing I did notice though is that if the use of "m" constraints with PIC is an issue then there are several locations in existing code that dont seem to follow that. For instance in libavcodec/x86/cavsdsp.c the macro QPEL_CAVSV1 uses a asm interface for MUL1 (which is variable ff_pw_96 and is assigned to %5). However MUL2 (which is variable ff_pw_42) is used as a direct symbol through MANGLE. Since both these variables are defined in the same place and are of the same type (uint64_t) then it appears there are some inconsistencies in existing FFmpeg code. Ill leave all existing instances of MANGLE but i thought id just point this out.
I think you missed the reason it is an issue (though the difference between MUL1 and MUL2 is strange). If the asm block uses only a few registers it's just a matter of balancing proper PIC code with textrels (which is good and you get if you use "m") with the risk of the compiler messing up and generating slow code and generally slower code if PIC is enabled. However if your code already uses 6 registers, the "compiler messing up" suddenly means "doesn't even compile", which is a much bigger issue than the performance cost of a single pointless register load (which might in theory even be marginally faster if the address is used often). Note then I suspect the CAVS code is probably not that well maintained, so I don't know if what you noticed is intentional or bad code.
On 30 December 2013 13:06, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 02:26, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
Using named asm constraints is a good idea as it seems that Intel compiler supports those. So I will update the patch so that MANGLE remains in use but it will just change to a named asm constraint on Intel+Windows. Combine that with a macro such as XMM_CLOBBERS_ONLY in order to add the necessary asm interfaces and that should work fine.
That one thing I did notice though is that if the use of "m" constraints with PIC is an issue then there are several locations in existing code that dont seem to follow that. For instance in libavcodec/x86/cavsdsp.c the macro QPEL_CAVSV1 uses a asm interface for MUL1 (which is variable ff_pw_96 and is assigned to %5). However MUL2 (which is variable ff_pw_42) is used as a direct symbol through MANGLE. Since both these variables are defined in the same place and are of the same type (uint64_t) then it appears there are some inconsistencies in existing FFmpeg code. Ill leave all existing instances of MANGLE but i thought id just point this out.
OK so I have redone the patch using named asm constraints and a macro to add them to the asm-interface (similar to XMM_CLOBBERS_ONLY as discussed). There are only 2 locations that are slightly different and these are in motion_est.c and vf_fspp.c. The inline asm in Intel compiler is rather unstable and changing some compilation flags suddenly result in errors from what was previously perfectly functional asm. To get compilation to work using standard release options 2 variables were changed from direct symbol references to an asm-interface. This should not be a problem as these symbols are defined in asm-interfaces already (for instance in vf_fspp.c temps[0] is already in an interface and all I did was add temps[1]). So the patch does not change anything that didnt already exist. To ensure everything stayed the same I compiled using gcc 4.8.2 and checked the generated disassembly for the part affected. For all changes the resulting code is exactly identical so this does not change anything (which for the most part it shouldn't anyway as the macros only change when using Intel on Windows). So no surprises there but I thought i would be thorough just to be sure. So obviously all FATE tests passed. Let me know how this one looks.
On Sun, Jan 05, 2014 at 01:27:26PM +1100, Matt Oliver wrote:
On 30 December 2013 13:06, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 02:26, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
Using named asm constraints is a good idea as it seems that Intel compiler supports those. So I will update the patch so that MANGLE remains in use but it will just change to a named asm constraint on Intel+Windows. Combine that with a macro such as XMM_CLOBBERS_ONLY in order to add the necessary asm interfaces and that should work fine.
That one thing I did notice though is that if the use of "m" constraints with PIC is an issue then there are several locations in existing code that dont seem to follow that. For instance in libavcodec/x86/cavsdsp.c the macro QPEL_CAVSV1 uses a asm interface for MUL1 (which is variable ff_pw_96 and is assigned to %5). However MUL2 (which is variable ff_pw_42) is used as a direct symbol through MANGLE. Since both these variables are defined in the same place and are of the same type (uint64_t) then it appears there are some inconsistencies in existing FFmpeg code. Ill leave all existing instances of MANGLE but i thought id just point this out.
OK so I have redone the patch using named asm constraints and a macro to add them to the asm-interface (similar to XMM_CLOBBERS_ONLY as discussed).
There are only 2 locations that are slightly different and these are in motion_est.c and vf_fspp.c.
The inline asm in Intel compiler is rather unstable and changing some compilation flags suddenly result in errors from what was previously perfectly functional asm. To get compilation to work
hmm
using standard release options 2 variables were changed from direct symbol references to an asm-interface. This should not be a problem as these symbols are defined in asm-interfaces already (for instance in vf_fspp.c temps[0] is already in an interface and all I did was add temps[1]). So the patch does not change anything that didnt already exist.
To ensure everything stayed the same I compiled using gcc 4.8.2 and checked the generated disassembly for the part affected. For all changes the resulting code is exactly identical so this does not change anything (which for the most part it shouldn't anyway as the macros only change when using Intel on Windows). So no surprises there but I thought i would be thorough just to be sure. So obviously all FATE tests passed.
Let me know how this one looks.
libavcodec/x86/cabac.h | 3 + libavcodec/x86/cavsdsp.c | 2 + libavcodec/x86/constants.h | 2 + libavcodec/x86/dsputil_mmx.c | 1 libavcodec/x86/h264_i386.h | 3 + libavcodec/x86/idct_sse2_xvid.c | 18 +++++----- libavcodec/x86/lpc.c | 3 + libavcodec/x86/mathops.h | 2 - libavcodec/x86/mlpdsp.c | 5 +- libavcodec/x86/motion_est.c | 4 +- libavcodec/x86/mpegvideoenc_template.c | 4 +- libavcodec/x86/simple_idct.c | 1 libavcodec/x86/vc1dsp_mmx.c | 6 +++ libavfilter/libmpcodecs/vf_fspp.c | 58 ++++++++++++++++++--------------- libavfilter/libmpcodecs/vf_ilpack.c | 8 ++-- libavfilter/libmpcodecs/vf_pp7.c | 2 - libavfilter/libmpcodecs/vf_uspp.c | 2 - libavfilter/vf_drawtext.c | 4 +- libavutil/mathematics.h | 3 + libavutil/x86/asm.h | 43 +++++++++++++++++++++++- libpostproc/postprocess_template.c | 7 +++ libswresample/x86/resample_mmx.h | 2 + libswscale/x86/rgb2rgb.c | 8 ++++ libswscale/x86/rgb2rgb_template.c | 11 ++++++ libswscale/x86/swscale_template.c | 27 +++++++++++++++ libswscale/x86/yuv2rgb.c | 18 +++++----- libswscale/x86/yuv2rgb_template.c | 21 ++++++++++- 27 files changed, 205 insertions(+), 63 deletions(-) d26137cd7e89161d06bef0332b959df68afaadbb Fixed-inline-asm-compilation-with-Intel-compiler.patch From 6eea177a4761629df5d6f02359fccc4efb116aed Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 5 Jan 2014 13:09:25 +1100 Subject: [PATCH] Fixed inline asm compilation with Intel compiler,
--- libavcodec/x86/cabac.h | 3 +- libavcodec/x86/cavsdsp.c | 2 ++ libavcodec/x86/constants.h | 2 ++ libavcodec/x86/dsputil_mmx.c | 1 + libavcodec/x86/h264_i386.h | 3 +- libavcodec/x86/idct_sse2_xvid.c | 18 +++++------ libavcodec/x86/lpc.c | 3 ++ libavcodec/x86/mathops.h | 2 +- libavcodec/x86/mlpdsp.c | 5 +-- libavcodec/x86/motion_est.c | 4 ++- libavcodec/x86/mpegvideoenc_template.c | 4 +-- libavcodec/x86/simple_idct.c | 1 + libavcodec/x86/vc1dsp_mmx.c | 6 ++++ libavfilter/libmpcodecs/vf_fspp.c | 58 +++++++++++++++++++--------------- libavfilter/libmpcodecs/vf_ilpack.c | 8 ++--- libavfilter/libmpcodecs/vf_pp7.c | 2 +- libavfilter/libmpcodecs/vf_uspp.c | 2 +- libavfilter/vf_drawtext.c | 4 ++- libavutil/mathematics.h | 3 ++ libavutil/x86/asm.h | 43 ++++++++++++++++++++++++- libpostproc/postprocess_template.c | 7 ++++ libswresample/x86/resample_mmx.h | 2 ++ libswscale/x86/rgb2rgb.c | 8 +++++ libswscale/x86/rgb2rgb_template.c | 11 +++++++ libswscale/x86/swscale_template.c | 27 ++++++++++++++++ libswscale/x86/yuv2rgb.c | 18 +++++------ libswscale/x86/yuv2rgb_template.c | 21 ++++++++++-- 27 files changed, 205 insertions(+), 63 deletions(-)
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 558d287..fe1eb32 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -34,7 +34,8 @@ # define BROKEN_COMPILER 0 #endif
-#if HAVE_INLINE_ASM +#if HAVE_INLINE_ASM && !( defined(__INTEL_COMPILER) && defined(_MSC_VER) )
that condition occurs alot maybe something like HAVE_INTEL_GAS or .._ASSEMBLER or something could be used to simplify these and also test for the actual thing that causes the problems assuming that is what causes the problem [...]
@@ -266,7 +267,7 @@ static inline void sad8_4_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) "punpckhbw %%mm7, %%mm5 \n\t" "paddw %%mm4, %%mm2 \n\t" "paddw %%mm5, %%mm3 \n\t" - "movq 16+"MANGLE(round_tab)", %%mm5 \n\t" + "movq %5, %%mm5 \n\t" "paddw %%mm2, %%mm0 \n\t" "paddw %%mm3, %%mm1 \n\t" "paddw %%mm5, %%mm0 \n\t" @@ -290,6 +291,7 @@ static inline void sad8_4_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) " js 1b \n\t" : "+a" (len) : "r" (blk1 - len), "r" (blk1 -len + stride), "r" (blk2 - len), "r" ((x86_reg)stride) + , "m"(round_tab[2])
a int64 instead of a array could be used [...]
diff --git a/libavfilter/libmpcodecs/vf_fspp.c b/libavfilter/libmpcodecs/vf_fspp.c index a8a33e2..290057f 100644 --- a/libavfilter/libmpcodecs/vf_fspp.c +++ b/libavfilter/libmpcodecs/vf_fspp.c
changes to libmpcodecs should be sent to mplayer-dev [...]
index e4315ef..226b415 100644 --- a/libswscale/x86/yuv2rgb.c +++ b/libswscale/x86/yuv2rgb.c @@ -48,15 +48,6 @@ DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL; DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL; DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL;
-//MMX versions -#if HAVE_MMX_INLINE -#undef RENAME -#undef COMPILE_TEMPLATE_MMXEXT -#define COMPILE_TEMPLATE_MMXEXT 0 -#define RENAME(a) a ## _mmx -#include "yuv2rgb_template.c" -#endif /* HAVE_MMX_INLINE */ - // MMXEXT versions #if HAVE_MMXEXT_INLINE #undef RENAME @@ -66,6 +57,15 @@ DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL; #include "yuv2rgb_template.c" #endif /* HAVE_MMXEXT_INLINE */
+//MMX versions +#if HAVE_MMX_INLINE +#undef RENAME +#undef COMPILE_TEMPLATE_MMXEXT +#define COMPILE_TEMPLATE_MMXEXT 0 +#define RENAME(a) a ## _mmx +#include "yuv2rgb_template.c" +#endif /* HAVE_MMX_INLINE */ + #endif /* HAVE_INLINE_ASM */
av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
why ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB It is what and why we do it that matters, not just one of them.
On 05.01.2014, at 03:27, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 13:06, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 02:26, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a problem. Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
Using named asm constraints is a good idea as it seems that Intel compiler supports those. So I will update the patch so that MANGLE remains in use but it will just change to a named asm constraint on Intel+Windows. Combine that with a macro such as XMM_CLOBBERS_ONLY in order to add the necessary asm interfaces and that should work fine.
That one thing I did notice though is that if the use of "m" constraints with PIC is an issue then there are several locations in existing code that dont seem to follow that. For instance in libavcodec/x86/cavsdsp.c the macro QPEL_CAVSV1 uses a asm interface for MUL1 (which is variable ff_pw_96 and is assigned to %5). However MUL2 (which is variable ff_pw_42) is used as a direct symbol through MANGLE. Since both these variables are defined in the same place and are of the same type (uint64_t) then it appears there are some inconsistencies in existing FFmpeg code. Ill leave all existing instances of MANGLE but i thought id just point this out.
OK so I have redone the patch using named asm constraints and a macro to add them to the asm-interface (similar to XMM_CLOBBERS_ONLY as discussed).
I would feel more comfortable if this and only this part was a separate patch. It is fairly simple to check whereas some of the other changes need further discussion. I'd also suggest a different name for the define. The name suggests that it would be added always. I would suggest something like "MANGLE_REFERENCES" or at least something that makes it clearer that most of the time it expands to nothing at all.
On 5 January 2014 13:27, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 13:06, Matt Oliver <protogonoi@gmail.com> wrote:
On 30 December 2013 02:26, Michael Niedermayer <michaelni@gmx.at> wrote:
On Sun, Dec 29, 2013 at 02:48:52PM +1100, Matt Oliver wrote:
is to much to ask. The only other option I can think of is to have different versions. i.e. for those few lines with direct symbol references have an #ifdef that only changes the code for Intel compiler on Windows. Windows shared libraries dont need PIC so this shouldn't be a
On Sun, Dec 29, 2013 at 02:19:40PM +0100, Reimar Döffinger wrote: problem.
Although the code may become a bit ugly.
One thing I thought of: You could try using named asm constraints, and only change the MANGLE to convert to a reference to a named asm argument. If you are lucky in quite a few cases you'd then only need an ifdef around the extra asm constraints.
that should be possible without ifdef, see XMM_CLOBBERS_ONLY() for something similar
[...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
Using named asm constraints is a good idea as it seems that Intel compiler supports those. So I will update the patch so that MANGLE remains in use but it will just change to a named asm constraint on Intel+Windows. Combine that with a macro such as XMM_CLOBBERS_ONLY in order to add the necessary asm interfaces and that should work fine.
That one thing I did notice though is that if the use of "m" constraints with PIC is an issue then there are several locations in existing code that dont seem to follow that. For instance in libavcodec/x86/cavsdsp.c the macro QPEL_CAVSV1 uses a asm interface for MUL1 (which is variable ff_pw_96 and is assigned to %5). However MUL2 (which is variable ff_pw_42) is used as a direct symbol through MANGLE. Since both these variables are defined in the same place and are of the same type (uint64_t) then it appears there are some inconsistencies in existing FFmpeg code. Ill leave all existing instances of MANGLE but i thought id just point this out.
OK so I have redone the patch using named asm constraints and a macro to add them to the asm-interface (similar to XMM_CLOBBERS_ONLY as discussed).
There are only 2 locations that are slightly different and these are in motion_est.c and vf_fspp.c. The inline asm in Intel compiler is rather unstable and changing some compilation flags suddenly result in errors from what was previously perfectly functional asm. To get compilation to work using standard release options 2 variables were changed from direct symbol references to an asm-interface. This should not be a problem as these symbols are defined in asm-interfaces already (for instance in vf_fspp.c temps[0] is already in an interface and all I did was add temps[1]). So the patch does not change anything that didnt already exist.
To ensure everything stayed the same I compiled using gcc 4.8.2 and checked the generated disassembly for the part affected. For all changes the resulting code is exactly identical so this does not change anything (which for the most part it shouldn't anyway as the macros only change when using Intel on Windows). So no surprises there but I thought i would be thorough just to be sure. So obviously all FATE tests passed.
Let me know how this one looks.
A minor addition to the last patch. There was a file I missed as it is only enabled when fast_cmov is active. The Intel compiler has a whole lot of bugs on this one as it will compile in 32bit but not 64bit. So for the moment it is just disabled for 64bit intel compiler on windows. So this should be everything and using default release compile options with the changes in the patch it is now possible to build with inline asm enabled with the Intel compiler on windows.
Matt Oliver <protogonoi <at> gmail.com> writes:
On 5 January 2014 13:27, Matt Oliver <protogonoi <at> gmail.com> wrote:
+// Determine if compiler support direct symbol references in inline asm +#if defined(__INTEL_COMPILER) && defined(_MSC_VER) +# define HAVE_DIRECT_SYMBOL_REF 0 +#else +# define HAVE_DIRECT_SYMBOL_REF 1 +#endif
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc". I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl). Once your initial patch hits git, send a patch for libmpcodecs either here or to mplayer-dev-eng and we will commit it.
+//MMX versions
Is this move needed / related? If not, please remove it, such unintended cosmetic changes should not be committed to the repository.
"r" (dest), "m" (dstW_reg), "m"(uv_off) \ + +#define YSCALEYUV2PACKEDX_END2 \
I don't know much about it, but doesn't this empty line hurt?
+//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c) +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset);
Is there no common header?
+#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#endif
Is this related? What does it fix?
+#include "config.h" +#if HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <time.h>
-#include "config.h"
If this is needed on some platform, please provide an independent patch with a short explanation. Carl Eugen
Matt Oliver <protogonoi <at> gmail.com> writes:
On 5 January 2014 13:27, Matt Oliver <protogonoi <at> gmail.com> wrote:
+// Determine if compiler support direct symbol references in inline asm +#if defined(__INTEL_COMPILER) && defined(_MSC_VER) +# define HAVE_DIRECT_SYMBOL_REF 0 +#else +# define HAVE_DIRECT_SYMBOL_REF 1 +#endif
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl). Once your initial patch hits git, send a patch for libmpcodecs either here or to mplayer-dev-eng and we will commit it.
+//MMX versions
Is this move needed / related? If not, please remove it, such unintended cosmetic changes should not be committed to the repository.
"r" (dest), "m" (dstW_reg), "m"(uv_off) \ + +#define YSCALEYUV2PACKEDX_END2 \
I don't know much about it, but doesn't this empty line hurt?
+//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c) +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset);
Is there no common header?
+#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#endif
Is this related? What does it fix?
+#include "config.h" +#if HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <time.h>
-#include "config.h"
If this is needed on some platform, please provide an independent patch with a short explanation.
Carl Eugen
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
Currently only Intel on Windows sets the HAVE_DIRECT_SYMBOL_REF to 0 so it would be possible to use that define instead however the other uses of "defined intel && defined msvc" are there because those sections even when changed to not using direct symbol references will still not compile. ASM in Intel compiler is extremely sensitive and some sections of code that even when using completely supported features will often not compile. So these sections are skipped using the "defined intel && defined msvc" not because of an issue with direct symbol references but for an issue that only affects the intel compiler and only on Windows. So i didnt want there to be any confusion should at some point down the line another compiler fails the "have direct symbol" check. I admit that the defines are rather ugly but are technically the only way around it. The only exception to this is in mlpdsp.c where the "defined intel && defined msvc" is because Intel does not support custom labels in asm so that could be replaced with a HAVE_NAMED_SYMBOLS if you would prefer.
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl).
I can do that if thats what people want.
+//MMX versions
Is this move needed / related?
Yes, The order that the files are included affects the end result. Compilation fails with the previous order but will work when rearranged (sounds weird I know).
I don't know much about it, but doesn't this empty line hurt?
Your right, probably should be removed.
Is there no common header?
Nope, these are defined in swscale.c hence the need for the additional externs.
Is this related? What does it fix?
The M_PI_2 and #if HAVE_SYS_TIME_H are somewhat related. They are not necessary for fixing inline asm for Intel but they are necessary in that without them the Intel compiler will not compile anything (inline or not). So I was thinking of this patch as a fix for Intel compilation, but if you want it to be fix for intel asm compilation only then I can remove it into another patch. But without it then this patch wont compile anyway so thats why I included it. However if you want them separated then let me know. Matt
On 27 January 2014 12:07, Matt Oliver <protogonoi@gmail.com> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
On 5 January 2014 13:27, Matt Oliver <protogonoi <at> gmail.com> wrote:
+// Determine if compiler support direct symbol references in inline asm +#if defined(__INTEL_COMPILER) && defined(_MSC_VER) +# define HAVE_DIRECT_SYMBOL_REF 0 +#else +# define HAVE_DIRECT_SYMBOL_REF 1 +#endif
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl). Once your initial patch hits git, send a patch for libmpcodecs either here or to mplayer-dev-eng and we will commit it.
+//MMX versions
Is this move needed / related? If not, please remove it, such unintended cosmetic changes should not be committed to the repository.
"r" (dest), "m" (dstW_reg), "m"(uv_off) \ + +#define YSCALEYUV2PACKEDX_END2 \
I don't know much about it, but doesn't this empty line hurt?
+//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c) +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset);
Is there no common header?
+#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#endif
Is this related? What does it fix?
+#include "config.h" +#if HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <time.h>
-#include "config.h"
If this is needed on some platform, please provide an independent patch with a short explanation.
Carl Eugen
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
Currently only Intel on Windows sets the HAVE_DIRECT_SYMBOL_REF to 0 so it would be possible to use that define instead however the other uses of "defined intel && defined msvc" are there because those sections even when changed to not using direct symbol references will still not compile. ASM in Intel compiler is extremely sensitive and some sections of code that even when using completely supported features will often not compile. So these sections are skipped using the "defined intel && defined msvc" not because of an issue with direct symbol references but for an issue that only affects the intel compiler and only on Windows. So i didnt want there to be any confusion should at some point down the line another compiler fails the "have direct symbol" check. I admit that the defines are rather ugly but are technically the only way around it.
The only exception to this is in mlpdsp.c where the "defined intel && defined msvc" is because Intel does not support custom labels in asm so that could be replaced with a HAVE_NAMED_SYMBOLS if you would prefer.
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl).
I can do that if thats what people want.
+//MMX versions
Is this move needed / related?
Yes, The order that the files are included affects the end result. Compilation fails with the previous order but will work when rearranged (sounds weird I know).
I don't know much about it, but doesn't this empty line hurt?
Your right, probably should be removed.
Is there no common header?
Nope, these are defined in swscale.c hence the need for the additional externs.
Is this related? What does it fix?
The M_PI_2 and #if HAVE_SYS_TIME_H are somewhat related. They are not necessary for fixing inline asm for Intel but they are necessary in that without them the Intel compiler will not compile anything (inline or not). So I was thinking of this patch as a fix for Intel compilation, but if you want it to be fix for intel asm compilation only then I can remove it into another patch. But without it then this patch wont compile anyway so thats why I included it. However if you want them separated then let me know.
Matt
OK So I have split the patch up into 4 smaller patches. Ill list them here to get feedback first but if people want me to create a new email thread for each one then let me know and i will. Patch 1: Removed 2 minor fixes that are independent of inline asm and are required just to get intel compiler to work in general. These are found in this patch. Patch 2: This is the inline asm patch similar to what I have previously submitted. From previous suggestions the libmpcodec stuff has been separated into a separate patch. Ive also cleaned up most of the "defined(__INTEL_COMPILER) && defined(_MSC_VER)" from all around the place. I added 2 defines; these are for HAVE_INLINE_ASM_NONLOCAL_LABELS which is used to determine if a compiler supports inline asm nonlocal label names (where a local name is just a number and is defined in local scope e.g. 1: ). This define replaces a previous specific intel compiler check. Another 2 locations check for intel and then create a BROKEN_COMPILER define. This is exactly what was previously done in x86/cabac.h for the clang compiler so I did exactly the same thing. The difference is that the clang broken compiler skips all 3 functions in cabac.h whereas the Intel compiler only breaks on the first (get_cabac_inline_x86). This prevented me from just reusing the existing clang BROKEN_COMPILER. Its quite possible that clang only brakes on the first function aswell but no one tested the whole thing. So if this is the case and the last 2 functions (get_cabac_bypass_sign_x86, get_cabac_bypass_x86) actually work under clang then the defines can be merged but otherwise theyll need to remain separate. But atleast now it cleans things up a bit and doesnt add anything much that wasnt already done. Patch 3: This is the inline asm changes specific for libmpcodecs. If you want me to submit this separately then let me know. Patch 4: Updates to configure to support generation of the new define HAVE_INLINE_ASM_NONLOCAL_LABELS and previous HAVE_INLINE_ASM_DIRECT_SYMBOL_REFS. Also no longer disables inline asm when using icl. The configure changes are in a separate patch in case they affect other build chains. I have tested with gcc and all works but havnt got access to a clang machine. Also im having unrelated icl issues with configure anyway. I must admit that all my testing of the actual inline asm code was performed directly within visual studio as I wrote a program (admittedly a rather hacky one) that reads in the existing configure/make scripts and any applicable command line arguments and dynamically generates an appropriate Visual Studio project file. So I can test all the intel/msvc specific code directly from Visual Studio without even needing an msys environment. Feedback welcome.
On 03.02.2014, at 08:13, Matt Oliver <protogonoi@gmail.com> wrote:
On 27 January 2014 12:07, Matt Oliver <protogonoi@gmail.com> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
On 5 January 2014 13:27, Matt Oliver <protogonoi <at> gmail.com> wrote:
+// Determine if compiler support direct symbol references in inline asm +#if defined(__INTEL_COMPILER) && defined(_MSC_VER) +# define HAVE_DIRECT_SYMBOL_REF 0 +#else +# define HAVE_DIRECT_SYMBOL_REF 1 +#endif
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl). Once your initial patch hits git, send a patch for libmpcodecs either here or to mplayer-dev-eng and we will commit it.
+//MMX versions
Is this move needed / related? If not, please remove it, such unintended cosmetic changes should not be committed to the repository.
"r" (dest), "m" (dstW_reg), "m"(uv_off) \ + +#define YSCALEYUV2PACKEDX_END2 \
I don't know much about it, but doesn't this empty line hurt?
+//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c) +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset);
Is there no common header?
+#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#endif
Is this related? What does it fix?
+#include "config.h" +#if HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <time.h>
-#include "config.h"
If this is needed on some platform, please provide an independent patch with a short explanation.
Carl Eugen
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
Currently only Intel on Windows sets the HAVE_DIRECT_SYMBOL_REF to 0 so it would be possible to use that define instead however the other uses of "defined intel && defined msvc" are there because those sections even when changed to not using direct symbol references will still not compile. ASM in Intel compiler is extremely sensitive and some sections of code that even when using completely supported features will often not compile. So these sections are skipped using the "defined intel && defined msvc" not because of an issue with direct symbol references but for an issue that only affects the intel compiler and only on Windows. So i didnt want there to be any confusion should at some point down the line another compiler fails the "have direct symbol" check. I admit that the defines are rather ugly but are technically the only way around it.
The only exception to this is in mlpdsp.c where the "defined intel && defined msvc" is because Intel does not support custom labels in asm so that could be replaced with a HAVE_NAMED_SYMBOLS if you would prefer.
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl).
I can do that if thats what people want.
+//MMX versions
Is this move needed / related?
Yes, The order that the files are included affects the end result. Compilation fails with the previous order but will work when rearranged (sounds weird I know).
I don't know much about it, but doesn't this empty line hurt?
Your right, probably should be removed.
Is there no common header?
Nope, these are defined in swscale.c hence the need for the additional externs.
Is this related? What does it fix?
The M_PI_2 and #if HAVE_SYS_TIME_H are somewhat related. They are not necessary for fixing inline asm for Intel but they are necessary in that without them the Intel compiler will not compile anything (inline or not). So I was thinking of this patch as a fix for Intel compilation, but if you want it to be fix for intel asm compilation only then I can remove it into another patch. But without it then this patch wont compile anyway so thats why I included it. However if you want them separated then let me know.
Matt
OK So I have split the patch up into 4 smaller patches. Ill list them here to get feedback first but if people want me to create a new email thread for each one then let me know and i will.
Patch 1: Removed 2 minor fixes that are independent of inline asm and are required just to get intel compiler to work in general. These are found in this patch.
Looks good to me.
Patch 2: This is the inline asm patch similar to what I have previously submitted. From previous suggestions the libmpcodec stuff has been
Could you please split it by issue? As said you change to use cdq _will_ break things, so I will object as long as it's there. If you split it by "type of change" it can be applied step by step. Also the BROKEN_COMPILER define is already bad naming, it would be good if you can think of a better name than PARTIAL_BROKEN_COMPILER
separated into a separate patch. Ive also cleaned up most of the "defined(__INTEL_COMPILER) && defined(_MSC_VER)" from all around the place. I added 2 defines; these are for HAVE_INLINE_ASM_NONLOCAL_LABELS which is used to determine if a compiler supports inline asm nonlocal label names (where a local name is just a number and is defined in local scope e.g. 1: ).
This change is also problematic I suspect, at least I remember some issues with gcc generating labels itself that ended up with the same name as our inline asm ones, which breaks things in a very bad way. However I do not remember which names were safe and which weren't, so it's possible that your change even fixes things for gcc...
Patch 3: This is the inline asm changes specific for libmpcodecs. If you want me to submit this separately then let me know.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
On 3 February 2014 18:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On 03.02.2014, at 08:13, Matt Oliver <protogonoi@gmail.com> wrote:
On 27 January 2014 12:07, Matt Oliver <protogonoi@gmail.com> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
On 5 January 2014 13:27, Matt Oliver <protogonoi <at> gmail.com> wrote:
+// Determine if compiler support direct symbol references in inline asm +#if defined(__INTEL_COMPILER) && defined(_MSC_VER) +# define HAVE_DIRECT_SYMBOL_REF 0 +#else +# define HAVE_DIRECT_SYMBOL_REF 1 +#endif
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl). Once your initial patch hits git, send a patch for libmpcodecs either here or to mplayer-dev-eng and we will commit it.
+//MMX versions
Is this move needed / related? If not, please remove it, such unintended cosmetic changes should not be committed to the repository.
"r" (dest), "m" (dstW_reg), "m"(uv_off) \ + +#define YSCALEYUV2PACKEDX_END2 \
I don't know much about it, but doesn't this empty line hurt?
+//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c) +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset);
Is there no common header?
+#ifndef M_PI_2 +#define M_PI_2 1.57079632679489661923 /* pi/2 */ +#endif
Is this related? What does it fix?
+#include "config.h" +#if HAVE_SYS_TIME_H #include <sys/time.h> +#endif #include <time.h>
-#include "config.h"
If this is needed on some platform, please provide an independent patch with a short explanation.
Carl Eugen
You should test this in configure. And please use this define all over the patch instead of "defined intel && defined msvc".
Currently only Intel on Windows sets the HAVE_DIRECT_SYMBOL_REF to 0 so it would be possible to use that define instead however the other uses of "defined intel && defined msvc" are there because those sections even when changed to not using direct symbol references will still not compile. ASM in Intel compiler is extremely sensitive and some sections of code that even when using completely supported features will often not compile. So these sections are skipped using the "defined intel && defined msvc" not because of an issue with direct symbol references but for an issue that only affects the intel compiler and only on Windows. So i didnt want there to be any confusion should at some point down the line another compiler fails the "have direct symbol" check. I admit that the defines are rather ugly but are technically the only way around it.
The only exception to this is in mlpdsp.c where the "defined intel && defined msvc" is because Intel does not support custom labels in asm so that could be replaced with a HAVE_NAMED_SYMBOLS if you would prefer.
I would suggest you postpone the changes to libavfilter/libmpcodecs, test with --disable-filter=mp (or disable-gpl).
I can do that if thats what people want.
+//MMX versions
Is this move needed / related?
Yes, The order that the files are included affects the end result. Compilation fails with the previous order but will work when rearranged (sounds weird I know).
I don't know much about it, but doesn't this empty line hurt?
Your right, probably should be removed.
Is there no common header?
Nope, these are defined in swscale.c hence the need for the additional externs.
Is this related? What does it fix?
The M_PI_2 and #if HAVE_SYS_TIME_H are somewhat related. They are not necessary for fixing inline asm for Intel but they are necessary in that without them the Intel compiler will not compile anything (inline or not). So I was thinking of this patch as a fix for Intel compilation, but if you want it to be fix for intel asm compilation only then I can remove it into another patch. But without it then this patch wont compile anyway so thats why I included it. However if you want them separated then let me know.
Matt
OK So I have split the patch up into 4 smaller patches. Ill list them here to get feedback first but if people want me to create a new email thread for each one then let me know and i will.
Patch 1: Removed 2 minor fixes that are independent of inline asm and are required just to get intel compiler to work in general. These are found in this patch.
Looks good to me.
Patch 2: This is the inline asm patch similar to what I have previously submitted. From previous suggestions the libmpcodec stuff has been
Could you please split it by issue? As said you change to use cdq _will_ break things, so I will object as long as it's there. If you split it by "type of change" it can be applied step by step. Also the BROKEN_COMPILER define is already bad naming, it would be good if you can think of a better name than PARTIAL_BROKEN_COMPILER
separated into a separate patch. Ive also cleaned up most of the "defined(__INTEL_COMPILER) && defined(_MSC_VER)" from all around the place. I added 2 defines; these are for HAVE_INLINE_ASM_NONLOCAL_LABELS which is used to determine if a compiler supports inline asm nonlocal label names (where a local name is just a number and is defined in local scope e.g. 1: ).
This change is also problematic I suspect, at least I remember some issues with gcc generating labels itself that ended up with the same name as our inline asm ones, which breaks things in a very bad way. However I do not remember which names were safe and which weren't, so it's possible that your change even fixes things for gcc...
Patch 3: This is the inline asm changes specific for libmpcodecs. If you want me to submit this separately then let me know.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
I can split the libmpcodecs patch into 2 if needed. Although I must have missed the issue with cdq being raised (or forgot). Given cltd will not work at all in Intel, both work for gcc and apparently cdq does not work with other compilers what is the recommend way to get around that? A define would be the obvious one but a little ugly. Any suggestions? Also if BROKEN_COMPILER is bad naming what would you suggest? Unfortunately its one of those situations were the compiler is behaving badly so I figured the name was appropriate.
On Mon, Feb 03, 2014 at 09:16:47PM +1100, Matt Oliver wrote:
On 3 February 2014 18:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On 03.02.2014, at 08:13, Matt Oliver <protogonoi@gmail.com> wrote:
Patch 3: This is the inline asm changes specific for libmpcodecs. If you want me to submit this separately then let me know.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
I can split the libmpcodecs patch into 2 if needed.
"Needed" is an exaggeration, but the larger the patch, the fewer people will have time to review, the more review comments you'll get all over the place, it makes debugging the changes later harder etc. Splitting is a simple way to reduce the amount of code changes you have locally.
Although I must have missed the issue with cdq being raised (or forgot).
Mentioned it in both of my earlier partial reviews.
Given cltd will not work at all in Intel, both work for gcc and apparently cdq does not work with other compilers what is the recommend way to get around that? A define would be the obvious one but a little ugly. Any suggestions?
Define doesn't sound so bad, but to be honest this change is in the middle of a huge number of other changes so I have 0 overview and feel unable to really get an idea of what would be appropriate. Which is why I suggest splitting patches: reduce the complexity of the problem by solving it step by step instead of all in one go. With the trivial stuff first since that is unlikely to need changes and should go in quickly.
Also if BROKEN_COMPILER is bad naming what would you suggest? Unfortunately its one of those situations were the compiler is behaving badly so I figured the name was appropriate.
Well, the "problem" is that a compiler can be broken in hundreds of ways, something more specific would seem helpful. Since I don't know/haven't checked what exactly it is about I don't have any suggestion, but in general the question to ask is: If you look at the code in 5 years, what name might help you understand what goes on? I'm fairly certain that "BROKEN_COMPILER" will be almost as helpful a name for understanding as just calling it "FJSNVGFRVB". But yes, it's not a big deal, just a suggestion to think about.
On 5 February 2014 06:37, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Mon, Feb 03, 2014 at 09:16:47PM +1100, Matt Oliver wrote:
On 3 February 2014 18:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On 03.02.2014, at 08:13, Matt Oliver <protogonoi@gmail.com> wrote:
Patch 3: This is the inline asm changes specific for libmpcodecs. If you want me to submit this separately then let me know.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
I can split the libmpcodecs patch into 2 if needed.
"Needed" is an exaggeration, but the larger the patch, the fewer people will have time to review, the more review comments you'll get all over the place, it makes debugging the changes later harder etc. Splitting is a simple way to reduce the amount of code changes you have locally.
Although I must have missed the issue with cdq being raised (or forgot).
Mentioned it in both of my earlier partial reviews.
Given cltd will not work at all in Intel, both work for gcc and apparently cdq does not work with other compilers what is the recommend way to get around that? A define would be the obvious one but a little ugly. Any suggestions?
Define doesn't sound so bad, but to be honest this change is in the middle of a huge number of other changes so I have 0 overview and feel unable to really get an idea of what would be appropriate. Which is why I suggest splitting patches: reduce the complexity of the problem by solving it step by step instead of all in one go. With the trivial stuff first since that is unlikely to need changes and should go in quickly.
Also if BROKEN_COMPILER is bad naming what would you suggest? Unfortunately its one of those situations were the compiler is behaving badly so I figured the name was appropriate.
Well, the "problem" is that a compiler can be broken in hundreds of ways, something more specific would seem helpful. Since I don't know/haven't checked what exactly it is about I don't have any suggestion, but in general the question to ask is: If you look at the code in 5 years, what name might help you understand what goes on? I'm fairly certain that "BROKEN_COMPILER" will be almost as helpful a name for understanding as just calling it "FJSNVGFRVB". But yes, it's not a big deal, just a suggestion to think about. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Well, having the DECLARE_ALIGNED changes separately would be nice since I
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks. Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels. think that part can be applied without further review. Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested. Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact. There is a fourth patch for libmpcodecs but it requires the asm.h changes from the previous inline asm patch so I will include that one later once the main ffmpeg patch has been cleaned up and excepted. The above 3 patches are completely stand alone.
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them).
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since the labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
On 6 February 2014 12:35, Matt Oliver <protogonoi@gmail.com> wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since the labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
Next round of patches, this time for everything else (i.e. non libmpcodecs). I broke the whole thing up into some smaller easier to handle patches. Patch 1: Adds some missing external declarations. Nice and easy this one. Patch 2: Adds a configuration check and option for HAVE_INLINE_ASM_NONLOCAL_LABELS which checks for the ability to use named nonlocal labels in inline asm. Patch 3: This is the main one and it adds support for using named references in place of direct symbol references. This includes the changes to MANGLE. Patch 4: This adds a work around for get_cabac not working on Intel. This was previously using the BROKEN_COMPILER define but I renamed it to the more descriptive BROKEN_REGISTER_ALLOCATION (because the error is due to register allocation failing so I figured that was clear enough now). Patch 5: 2 very minor fixes for icl. First changes the order of yuv2rgb_template inclusion (as previously discussed this is necessary). And the other explicitly uses eax in movzbl instead of REG_a as movzbl only works on eax and not rax anyway so this avoids a compiler error. Patch 6: Adds a configure check for availability of cdq over cltd and creates a define accordingly. In addition to all those there is the final libmpcodec patch which adds the named references added in Patch 3 above.
Matt Oliver <protogonoi <at> gmail.com> writes:
Next round of patches
They do not apply, please rebase your local checkout.
check_cc <<EOF && enable inline_asm_direct_symbol_refs void foo(void){ int test; __asm__ volatile("movl test2, %eax"); } #EOF
Isn't the following sufficient? check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 31cb36a..f4b3a24 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -33,6 +33,11 @@ #else # define BROKEN_COMPILER 0 #endif +#if (defined(__INTEL_COMPILER) && defined(_MSC_VER)) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index e71dbf8..ba01412 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -24,7 +24,13 @@ #ifndef AVCODEC_X86_VP56_ARITH_H #define AVCODEC_X86_VP56_ARITH_H
+#if (defined(__INTEL_COMPILER) && defined(_MSC_VER) && ARCH_X86_64) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
Are they really different (ARCH_X86_64)? If not, I think you should try to avoid the duplication. Could you add the compilation error you see that makes patch 5 necessary? (Sorry if you did already.) Carl Eugen
On 8 February 2014 20:25, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
Next round of patches
They do not apply, please rebase your local checkout.
check_cc <<EOF && enable inline_asm_direct_symbol_refs void foo(void){ int test; __asm__ volatile("movl test2, %eax"); } #EOF
Isn't the following sufficient? check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 31cb36a..f4b3a24 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -33,6 +33,11 @@ #else # define BROKEN_COMPILER 0 #endif +#if (defined(__INTEL_COMPILER) && defined(_MSC_VER)) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index e71dbf8..ba01412 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -24,7 +24,13 @@ #ifndef AVCODEC_X86_VP56_ARITH_H #define AVCODEC_X86_VP56_ARITH_H
+#if (defined(__INTEL_COMPILER) && defined(_MSC_VER) && ARCH_X86_64) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
Are they really different (ARCH_X86_64)? If not, I think you should try to avoid the duplication.
Could you add the compilation error you see that makes patch 5 necessary? (Sorry if you did already.)
Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
They do not apply, please rebase your local checkout.
Sorry these patches were written back when I started trying to submit these a month or so ago so my apologies for them getting out of date. I will fix. Is it all of the 6 patches or some in particular that I need to reed do?
Isn't the following sufficient?
Need to also be able to declare 'int test' as other build chains may fail due to missing declaration. check_inline_asm can be used but I though that some things had issues with the absence of test being declared so I wanted to make it explicit exactly what was being tested (In this case direct references to existing variables).
Are they really different (ARCH_X86_64)?
Intel compiler is really temperamental when it comes to inline asm. The code works fine in 32bit but fails miserably in 64bit. The asm assembler doesnt handle the leal instruction properly and uses the wrong register type (i.e. 32/64bit) and then generates an error about mismatching register types. This doesnt happen in 32 bit because all registers are 32 bit and its fine but in 64 bit it seems to mix and match between using 32b/64b registers for variables passed through the asm interface and then errors. I tried finding a way around it but short of explicitly loading in the variables and managing the registers manually there is no way to fix it (its just an Intel bug). And I was trying to minimise code impact which is why I didnt do that (and the generated code on other platforms may take a slight hit). Strangely it only happens on the leal instruction and so far only that lea instruction. It seems to be because all 3 inputs in that instruction are interface variables and that is what is throwing the compiler for a loop.
Could you add the compilation error you see that makes patch 5 necessary?
The first is because Intel compiler doesnt like RAX being used as the register in movzbl. So this is a 64bit issue only that generates the following error: \libavcodec\x86\mpegvideoenc_template.c(144): error : Unsupported instruction form in asm instruction movzbl. Swapping MMX and MMXEXT around is due to the following line: #if COMPILE_TEMPLATE_MMXEXT DECLARE_ASM_CONST(8, int16_t, mask1101[4]) = {-1,-1, 0,-1}; etc. When MMX is done first then the compiler generates a series of errors about missing the maskXXXX variables. Specifically: ..\libswscale\x86\yuv2rgb_template.c(321): error : identifier "mask1101" is undefined and many others. It is possible to fix this by renaming the #if to instead do it "#if COMPILE_TEMPLATE_MMX" but I instead swapped the order in case there was some reasoning that I wasnt seeing as to why the declaration is only for MMXEXT.
Matt Oliver <protogonoi <at> gmail.com> writes:
Isn't the following sufficient?
(Any reason why you cut the following line?)
check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
Need to also be able to declare 'int test' as other build chains may fail due to missing declaration.
Looking at your patch 1 I find that very unlikely or do I miss something? [...]
Could you add the compilation error you see that makes patch 5 necessary?
The first is
[...] Without looking at the patch again, this seems to imply that you may / should split the patch.
Swapping MMX and MMXEXT around is due to the following line:
#if COMPILE_TEMPLATE_MMXEXT DECLARE_ASM_CONST(8, int16_t, mask1101[4]) = {-1,-1, 0,-1}; etc.
When MMX is done first then the compiler generates a series of errors about missing the maskXXXX variables. Specifically: ..\libswscale\x86\yuv2rgb_template.c(321): error : identifier "mask1101" is undefined and many others.
It is possible to fix this by renaming the #if to instead do it "#if COMPILE_TEMPLATE_MMX"
This sounds as if compilation with --disable-mmxext would still fail with your patch, am I correct? I know I am a very bad example myself but please consider to fix your quoting, I believe this mail from you shows how important this is. Carl Eugen
On 9 February 2014 03:16, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
Isn't the following sufficient?
(Any reason why you cut the following line?)
check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
Need to also be able to declare 'int test' as other build chains may fail due to missing declaration.
Looking at your patch 1 I find that very unlikely or do I miss something?
[...]
Could you add the compilation error you see that makes patch 5 necessary?
The first is
[...]
Without looking at the patch again, this seems to imply that you may / should split the patch.
Swapping MMX and MMXEXT around is due to the following line:
#if COMPILE_TEMPLATE_MMXEXT DECLARE_ASM_CONST(8, int16_t, mask1101[4]) = {-1,-1, 0,-1}; etc.
When MMX is done first then the compiler generates a series of errors about missing the maskXXXX variables. Specifically: ..\libswscale\x86\yuv2rgb_template.c(321): error : identifier "mask1101" is undefined and many others.
It is possible to fix this by renaming the #if to instead do it "#if COMPILE_TEMPLATE_MMX"
This sounds as if compilation with --disable-mmxext would still fail with your patch, am I correct?
I know I am a very bad example myself but please consider to fix your quoting, I believe this mail from you shows how important this is.
Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Looking at your patch 1 I find that very unlikely or do I miss something?
The main thing I was trying to avoid is that when checking for direct symbol references that the line '"mov test, %eax\n"' fails because direct symbols are not supported and not because the compiler has no idea what 'test' is where it is from. The fact patch 1 is needed is because Intel needs variables declared but clearly as it hasnt been needed previously then the current compilers dont appear to have that problem. However I was trying to be forward thinking as should Intel update there compiler with direct symbol references then the check will pick it up even if Intel still has the declaration issue. And of course there may be other compilers out there that have similar issues so the thinking was to make sure it was done right the first time and make it clear exactly what was being tested.
This sounds as if compilation with --disable-mmxext would still fail with your patch, am I correct?
Correct. Nice pick up as that didnt occur to me. Id have to change it so that it will test if they have already been declared (perhaps add an extra define). The other option would be to move them to yuv2rgb.c but given these variables are used in yuv2rgb_template.c it may be better to keep them in there so theres no risk of the declarations getting mistakenly orphaned by future code changes.
OK, so I have done a complete rebase so the patches should apply fine. The only issues where changes to configure that were added to master after my patches were written. So I should point out that as several of these patches modify configure then applying them in the wrong order will cause merge conflicts. That aside here are the 6 patches again. Patch 1: add missing external declarations (unmodified from previous) Patch 2: Add nonlocal inline asm label check (unmodified from previous except for rebase) Patch 3: Asm direct symbol reference check and support (rebased with minor addition to yuv2rgb_template.c that fixes previous Patch 5 issue) Patch 4: Workaround for "register allocation failed" errors found in intel compiler (unmodified from previous) Patch 5: Fixed 64bit conformance with movzbl. Fixes "Unsupported instruction form in asm instruction movzbl" found in intel compiler. (only contains first half of previous patch5). The previous patch 5 had a workaround for missing declarations in MMX and MMXEXT mode, these declarations are only needed in MMXEXT anyway so they have been handled more elegantly directly in the new Patch3 so the old fixes are no longer needed. Thanks to Carl for pointing out the error. Patch 6: Fix for missing cdq mnemonic support (unmodified from previous except for rebase)
Matt Oliver <protogonoi <at> gmail.com> writes:
Patch 1: add missing external declarations (unmodified from previous)
+ extern uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63];
Is including cabac_functions.h an alternative?
//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c)
s/swscale_mmx.c/swscale.c
Patch 3: Asm direct symbol reference check and support (rebased with minor addition to yuv2rgb_template.c that fixes previous Patch 5 issue)
+check_cc <<EOF && enable inline_asm_direct_symbol_refs +void foo(void){ int test; __asm__ volatile("movl test, %eax"); } +EOF
Please simplify as discussed.
Patch 4: Workaround for "register allocation failed" errors found in intel compiler (unmodified from previous)
+#if (defined(__INTEL_COMPILER) && defined(_MSC_VER)) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif +#if (defined(__INTEL_COMPILER) && defined(_MSC_VER) && ARCH_X86_64) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif I still wonder why this has to be duplicated.
Patch 5: Fixed 64bit conformance with movzbl. Fixes "Unsupported instruction form in asm instruction movzbl" found in intel compiler.
(I probably just don't understand this patch:)
- "movzb %%al, %%"REG_a" \n\t" // last_non_zero_p1 + "movzbl %%al, %%eax \n\t" // last_non_zero_p1
Why isn't the new line also using '%%"REG_a"'? Carl Eugen
On 9 February 2014 18:43, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
Patch 1: add missing external declarations (unmodified from previous)
+ extern uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63];
Is including cabac_functions.h an alternative?
//Declared in swscale_mmx.c (and referenced from rgb2rgb_template.c)
s/swscale_mmx.c/swscale.c
Patch 3: Asm direct symbol reference check and support (rebased with minor addition to yuv2rgb_template.c that fixes previous Patch 5 issue)
+check_cc <<EOF && enable inline_asm_direct_symbol_refs +void foo(void){ int test; __asm__ volatile("movl test, %eax"); } +EOF
Please simplify as discussed.
Patch 4: Workaround for "register allocation failed" errors found in intel compiler (unmodified from previous)
+#if (defined(__INTEL_COMPILER) && defined(_MSC_VER)) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
+#if (defined(__INTEL_COMPILER) && defined(_MSC_VER) && ARCH_X86_64) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
I still wonder why this has to be duplicated.
Patch 5: Fixed 64bit conformance with movzbl. Fixes "Unsupported instruction form in asm instruction movzbl" found in intel compiler.
(I probably just don't understand this patch:)
- "movzb %%al, %%"REG_a" \n\t" // last_non_zero_p1 + "movzbl %%al, %%eax \n\t" // last_non_zero_p1
Why isn't the new line also using '%%"REG_a"'?
Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Is including cabac_functions.h an alternative?
Possibly, But I figured just adding a couple of externs instead of an entire header keeps things a bit simpler for the compiler.
s/swscale_mmx.c/swscale.c
Sorry I dont understand what your comment is referring to here. Do you want me to remove that comment line from the patch?
Please simplify as discussed.
OK, as i said I was trying to be forward thinking in avoiding future issues but if youd prefer it simplified then I will do it that way.
I still wonder why this has to be duplicated.
Because both generate an error due to register allocation but one only generates an error in 64bit mode whereas the other generates an error in both 32bit/64bit. However your right in that the second 64bit only error is a slightly different register error than the first so I will give it a separate define name to illustrate the slight differences better.
Why isn't the new line also using '%%"REG_a"'?
When compiling in 64bit REG_a is set to RAX. movzbl is a 32bit instruction that works on the 32bit EAX register. So you have to explicitly state eax even in 64bit compilation otherwise you get an "Unsupported instruction form in asm instruction movzbl" error. GCC is smart enough to handle the conversion for you but intel is very strict.
Matt Oliver <protogonoi <at> gmail.com> writes:
s/swscale_mmx.c/swscale.c
Sorry I dont understand what your comment is referring to here. Do you want me to remove that comment line from the patch?
No, please replace "swscale_mmx.c" in the comment with "swscale.c" (or confirm that I am wrong). (And please fix your quoting to make my answer to your mail easier to read.)
Please simplify as discussed.
OK, as i said I was trying to be forward thinking in avoiding future issues but if youd prefer it simplified then I will do it that way.
Or consider waiting for a comment from somebody else. Thank you for the other explanations, Carl Eugen
On 9 February 2014 19:43, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
s/swscale_mmx.c/swscale.c
Sorry I dont understand what your comment is referring to here. Do you want me to remove that comment line from the patch?
No, please replace "swscale_mmx.c" in the comment with "swscale.c" (or confirm that I am wrong).
(And please fix your quoting to make my answer to your mail easier to read.)
Please simplify as discussed.
OK, as i said I was trying to be forward thinking in avoiding future issues but if youd prefer it simplified then I will do it that way.
Or consider waiting for a comment from somebody else.
Thank you for the other explanations, Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
No, please replace "swscale_mmx.c" in the comment with "swscale.c" (or confirm that I am wrong).
No need you were correct (although its specifically in x86/swscale.c). And ive used sed enough that I should have understood what you meant (also if the formatting of my emails is off then I do apologise as its fine on my end so i havnt noticed). Anyway I updated the patch1 so that the comment now is for x86/swscale.c. Patch4 was updated so the second BROKEN_REGISTER_ALLOCATION define has been renamed so that it is now much clearer it is a 64bit register allocation error causing mismatches as compared to the other one which is a register allocation issue that occurs all the time.
Or consider waiting for a comment from somebody else.
Ill save sometime on this. I had actually tested this (and then forgot) but the check for inline_asm_direct_symbol_refs has to be done the way it is currently. Just using check_inline_asm doesnt declare the 'int test' variable and does cause issues. Even gcc will fail the test if done that way so it has to stay as it stands currently. Gcc is more forgiving about extern variables than intel but it still needs them to be somewhere. Anyway thanks for the feedback Carl Eugen. Given the last few fixes have just been comments and small things hopefully this is close to being ready ;)
Matt Oliver <protogonoi <at> gmail.com> writes:
I had actually tested this (and then forgot) but the check for inline_asm_direct_symbol_refs has to be done the way it is currently.
I thought we both agreed that it works fine with: check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
Just using check_inline_asm doesnt declare the 'int test' variable and does cause issues.
What kind of issues?
Even gcc will fail the test if done that way so it has to stay as it stands currently.
Which version did you test? It works fine here with 4.4, 4.7 and 4.8. (and 2.95.3) Carl Eugen
Carl Eugen Hoyos <cehoyos <at> ag.or.at> writes:
+check_cc <<EOF && enable inline_asm_direct_symbol_refs +void foo(void){ int test; __asm__ volatile("movl test, %eax"); } +EOF
Please simplify as discussed.
And please move the patch in the same block as the EBP/EBX test. Carl Eugen
On 9 February 2014 23:20, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Carl Eugen Hoyos <cehoyos <at> ag.or.at> writes:
+check_cc <<EOF && enable inline_asm_direct_symbol_refs +void foo(void){ int test; __asm__ volatile("movl test, %eax"); } +EOF
Please simplify as discussed.
And please move the patch in the same block as the EBP/EBX test.
Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
I thought we both agreed that it works fine with: check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
I assumed it did to but when i retested with 4.8.2 and my MinGW it was actually failing the test and so HAVE_INLINE_DIRECT_SYMBOL_REFS was being set to 0. Of course everything still compiled and worked fine because gcc supports the workaround named interfaces but the point is to only enable the workaround for compilers that cant support the existing MANGLE and leave all the others as is. So the issue I referred to was simply that my version of mingw was being set as not supporting direct symbol references when using the suggested change.
And please move the patch in the same block as the EBP/EBX test.
Given that the tests uses x86 opcodes then yes your absolutely right they should be in the x86 section. Guess I spend to much time thinking x86 as default and forget about the other architectures. Anyway patches updated! And again thanks for the speedy feedback.
Matt Oliver <protogonoi <at> gmail.com> writes:
I thought we both agreed that it works fine with: check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"'
I assumed it did to but when i retested with 4.8.2 and my MinGW it was actually failing the test and so HAVE_INLINE_DIRECT_SYMBOL_REFS was being set to 0.
Please provide the relevant (!!) part of config.log (starts with "check_inline_asm inline_asm_direct_symbol_refs") Carl Eugen diff --git a/configure b/configure index 6f572f6..dac6cc6 100755 --- a/configure +++ b/configure @@ -1375,6 +1375,7 @@ CONFIG_LIST=" hardcoded_tables incompatible_libav_abi incompatible_fork_abi +inline_asm_direct_symbol_refs lsp lzo mdct @@ -4189,6 +4190,7 @@ elif enabled x86; then check_builtin rdtsc intrin.h "__rdtsc()" check_builtin mm_empty mmintrin.h "_mm_empty()" +check_inline_asm inline_asm_direct_symbol_refs '"mov test, %eax\n"' enable local_aligned_8 local_aligned_16
Hi, On Sat, Feb 8, 2014 at 10:02 AM, Matt Oliver <protogonoi@gmail.com> wrote:
On 8 February 2014 20:25, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index e71dbf8..ba01412 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -24,7 +24,13 @@ #ifndef AVCODEC_X86_VP56_ARITH_H #define AVCODEC_X86_VP56_ARITH_H
+#if (defined(__INTEL_COMPILER) && defined(_MSC_VER) && ARCH_X86_64) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
If not, I think you should try to avoid the duplication. Are they really different (ARCH_X86_64)?
Intel compiler is really temperamental when it comes to inline asm. The code works fine in 32bit but fails miserably in 64bit. The asm assembler doesnt handle the leal instruction properly and uses the wrong register type (i.e. 32/64bit) and then generates an error about mismatching register types. This doesnt happen in 32 bit because all registers are 32 bit and its fine but in 64 bit it seems to mix and match between using 32b/64b registers for variables passed through the asm interface and then errors. I tried finding a way around it but short of explicitly loading in the variables and managing the registers manually there is no way to fix it (its just an Intel bug). And I was trying to minimise code impact which is why I didnt do that (and the generated code on other platforms may take a slight hit). Strangely it only happens on the leal instruction and so far only that lea instruction. It seems to be because all 3 inputs in that instruction are interface variables and that is what is throwing the compiler for a loop.
I'm not going to argue against this being an icl bug, but I'm surprised you can't come up with a concept that works. Doesn't something like "leal (%l2, %l3), %l3" work? Also, which one does it convert to 64bit? Let's not workaround bugs by adding more bugs. Let's fix bugs. Ronald
On Thu, Feb 06, 2014 at 12:35:13PM +1100, Matt Oliver wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since the labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
I don't trust that this is always true, and I see no reason to do things different than all other places I could find. So I changed that.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
You changed one uint8_t to int8_t, I fixed that before applying. Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead.
On 10 February 2014 09:21, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On Thu, Feb 06, 2014 at 12:35:13PM +1100, Matt Oliver wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since the labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
I don't trust that this is always true, and I see no reason to do things different than all other places I could find. So I changed that.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
You changed one uint8_t to int8_t, I fixed that before applying. Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Please provide the relevant (!!) part of config.log Sorry Carl, I rescind my previous statement. Gcc works fine it was my MinGW that was failing and after checking the logs a second time I realised it was actually due to a random write permission error in creating the temp file that has started cropping up since I moved to Win8.1. So it could be changed if thats what people want. In not 100% about the change myself as if Intel do update there compiler with direct symbol references then due to the way they resolve references currently without the 'test' declaration it would still fail. This is a future proof thing so Im happy to concede to whatever the group consensus is.
I'm not going to argue against this being an icl bug, but I'm surprised you can't come up with a concept that works. Doesn't something like "leal (%l2, %l3), %l3" work? Also, which one does it convert to 64bit?
Ive tried everything I can think of so Im certainly open to suggestions. Ive tried every combination of constraints I could think off (although Intel doesnt support all of them) and just could not get it to work. As to which operand register is being set to either 32bit/64bit im not sure as the error message doesnt specify so the only way would be to try and find the line in the compiler intermediary output (which im understandably in no hurry to attempt). All i can ascertain from the error message is one of %2/%3 is 32bit and the other is 64bit. As to why the difference I have no idea as they both have the same constraint and are both uint. I tried your suggestion about prefixing operands with 'l' (although im not familiar with this technique) a direct substitution resulted in the error: "Substitution directive specifies non-existent operand in asm instruction". Although as I said im not familiar with that technique (im guessing the prefix forces it to use long sized registers?) i may be missing something. But nothing ive tried works, even trying to change the leal to just lea or something generates errors (illegal reg in address for those who are interested). So I ran out of ideas. Basically everything else ive tried generates the "Unsupported instruction form" error. Intel just does not like lea instructions where the input are not explicit registers. Thats the only way I know of to fix it is to move say %2 into an explicit register and then use that but that would potentially negatively affect other buildchains. If there is a fix I would love to know it. You changed one uint8_t to int8_t, I fixed that before applying.
Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead.
Must have missed that when i updated, Thanks Reimar for picking it up and fixing it. Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility (I didnt add it to the previous patch so that for those who have already looked over and ok'ed the current version dont have to recheck them).
Matt Oliver <protogonoi <at> gmail.com> writes:
Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility
Please merge it into the previous patch. Carl Eugen
On 10 February 2014 21:20, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility
Please merge it into the previous patch.
Carl Eugen
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Please merge it into the previous patch. Looking over the previous patch descriptions this new one doesnt really fit in with any of the others. Given previously ive been told to keep them separated by each individual issue then adding it into a previous patch would go a bit against that as its a slightly different fix than the other patches. If you believe there is one that it would be suitable to add it to then by all means let me know.
Hi, On Mon, Feb 10, 2014 at 2:53 AM, Matt Oliver <protogonoi@gmail.com> wrote:
On 10 February 2014 09:21, Reimar Döffinger <Reimar.Doeffinger@gmx.de
wrote:
On Thu, Feb 06, 2014 at 12:35:13PM +1100, Matt Oliver wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since the labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
I don't trust that this is always true, and I see no reason to do things different than all other places I could find. So I changed that.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
You changed one uint8_t to int8_t, I fixed that before applying. Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Please provide the relevant (!!) part of config.log
Sorry Carl, I rescind my previous statement. Gcc works fine it was my MinGW that was failing and after checking the logs a second time I realised it was actually due to a random write permission error in creating the temp file that has started cropping up since I moved to Win8.1. So it could be changed if thats what people want. In not 100% about the change myself as if Intel do update there compiler with direct symbol references then due to the way they resolve references currently without the 'test' declaration it would still fail. This is a future proof thing so Im happy to concede to whatever the group consensus is.
I'm not going to argue against this being an icl bug, but I'm surprised you can't come up with a concept that works. Doesn't something like "leal (%l2, %l3), %l3" work? Also, which one does it convert to 64bit?
Ive tried everything I can think of so Im certainly open to suggestions. Ive tried every combination of constraints I could think off (although Intel doesnt support all of them) and just could not get it to work. As to which operand register is being set to either 32bit/64bit im not sure as the error message doesnt specify so the only way would be to try and find the line in the compiler intermediary output (which im understandably in no hurry to attempt). All i can ascertain from the error message is one of %2/%3 is 32bit and the other is 64bit. As to why the difference I have no idea as they both have the same constraint and are both uint. I tried your suggestion about prefixing operands with 'l' (although im not familiar with this technique) a direct substitution resulted in the error: "Substitution directive specifies non-existent operand in asm instruction".
It means I read the wrong section of the gcc inline asm manual, it's %k2/%k3, not %l2/%l3. Please try again with k instead of l. Ronald
On 11 February 2014 02:01, Ronald S. Bultje <rsbultje@gmail.com> wrote:
Hi,
On Mon, Feb 10, 2014 at 2:53 AM, Matt Oliver <protogonoi@gmail.com> wrote:
On 10 February 2014 09:21, Reimar Döffinger <Reimar.Doeffinger@gmx.de
wrote:
On Thu, Feb 06, 2014 at 12:35:13PM +1100, Matt Oliver wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de
wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things
To
start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
> Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving
commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since
easier. the the
labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
I don't trust that this is always true, and I see no reason to do things different than all other places I could find. So I changed that.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
You changed one uint8_t to int8_t, I fixed that before applying. Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Please provide the relevant (!!) part of config.log
Sorry Carl, I rescind my previous statement. Gcc works fine it was my MinGW that was failing and after checking the logs a second time I realised it was actually due to a random write permission error in creating the temp file that has started cropping up since I moved to Win8.1. So it could be changed if thats what people want. In not 100% about the change myself as if Intel do update there compiler with direct symbol references then due to the way they resolve references currently without the 'test' declaration it would still fail. This is a future proof thing so Im happy to concede to whatever the group consensus is.
I'm not going to argue against this being an icl bug, but I'm surprised you can't come up with a concept that works. Doesn't something like "leal (%l2, %l3), %l3" work? Also, which one does it convert to 64bit?
Ive tried everything I can think of so Im certainly open to suggestions. Ive tried every combination of constraints I could think off (although Intel doesnt support all of them) and just could not get it to work. As to which operand register is being set to either 32bit/64bit im not sure as the error message doesnt specify so the only way would be to try and find the line in the compiler intermediary output (which im understandably in no hurry to attempt). All i can ascertain from the error message is one of %2/%3 is 32bit and the other is 64bit. As to why the difference I have no idea as they both have the same constraint and are both uint. I tried your suggestion about prefixing operands with 'l' (although im not familiar with this technique) a direct substitution resulted in the error: "Substitution directive specifies non-existent operand in asm instruction".
It means I read the wrong section of the gcc inline asm manual, it's %k2/%k3, not %l2/%l3. Please try again with k instead of l.
Ronald _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Dont worry I think weve all been there. Anyway retried with %k2/%k3 and get the same error. It appears icl doesnt support the k prefix. I tried with leal and lea just in case but no luck. For those interested error is: "error : operand 1: illegal reg in address in asm instruction lea."
On Mon, Feb 10, 2014 at 06:53:23PM +1100, Matt Oliver wrote:
On 10 February 2014 09:21, Reimar Döffinger <Reimar.Doeffinger@gmx.de>wrote:
On Thu, Feb 06, 2014 at 12:35:13PM +1100, Matt Oliver wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things easier. To start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since the labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
I don't trust that this is always true, and I see no reason to do things different than all other places I could find. So I changed that.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
You changed one uint8_t to int8_t, I fixed that before applying. Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Please provide the relevant (!!) part of config.log
Sorry Carl, I rescind my previous statement. Gcc works fine it was my MinGW that was failing and after checking the logs a second time I realised it was actually due to a random write permission error in creating the temp file that has started cropping up since I moved to Win8.1. So it could be changed if thats what people want. In not 100% about the change myself as if Intel do update there compiler with direct symbol references then due to the way they resolve references currently without the 'test' declaration it would still fail. This is a future proof thing so Im happy to concede to whatever the group consensus is.
I'm not going to argue against this being an icl bug, but I'm surprised you can't come up with a concept that works. Doesn't something like "leal (%l2, %l3), %l3" work? Also, which one does it convert to 64bit?
Ive tried everything I can think of so Im certainly open to suggestions. Ive tried every combination of constraints I could think off (although Intel doesnt support all of them) and just could not get it to work. As to which operand register is being set to either 32bit/64bit im not sure as the error message doesnt specify so the only way would be to try and find the line in the compiler intermediary output (which im understandably in no hurry to attempt). All i can ascertain from the error message is one of %2/%3 is 32bit and the other is 64bit. As to why the difference I have no idea as they both have the same constraint and are both uint. I tried your suggestion about prefixing operands with 'l' (although im not familiar with this technique) a direct substitution resulted in the error: "Substitution directive specifies non-existent operand in asm instruction". Although as I said im not familiar with that technique (im guessing the prefix forces it to use long sized registers?) i may be missing something. But nothing ive tried works, even trying to change the leal to just lea or something generates errors (illegal reg in address for those who are interested). So I ran out of ideas. Basically everything else ive tried generates the "Unsupported instruction form" error. Intel just does not like lea instructions where the input are not explicit registers. Thats the only way I know of to fix it is to move say %2 into an explicit register and then use that but that would potentially negatively affect other buildchains. If there is a fix I would love to know it.
You changed one uint8_t to int8_t, I fixed that before applying.
Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead.
Must have missed that when i updated, Thanks Reimar for picking it up and fixing it.
Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility (I didnt add it to the previous patch so that for those who have already looked over and ok'ed the current version dont have to recheck them).
dca.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dfdf0508b391e5e0f7f68344b6798802289af7ee 7-6-Additional-icl-inline-asm-fix.patch From 7929bc1ae54be0f79b4407b8916d5e42d69f4fcf Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Mon, 10 Feb 2014 18:51:48 +1100 Subject: [PATCH] [7/6] Additional icl inline asm fix.
--- libavcodec/x86/dca.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/x86/dca.h b/libavcodec/x86/dca.h index 6415129..cefac59 100644 --- a/libavcodec/x86/dca.h +++ b/libavcodec/x86/dca.h @@ -31,7 +31,7 @@ static inline void int8x8_fmul_int32(av_unused DCADSPContext *dsp, { DECLARE_ALIGNED(16, static const uint32_t, inverse16) = 0x3D800000; __asm__ volatile ( - "cvtsi2ss %2, %%xmm0 \n\t" + "cvtsi2ssl %2, %%xmm0 \n\t" "mulss %3, %%xmm0 \n\t" "movq (%1), %%xmm1 \n\t" "punpcklbw %%xmm1, %%xmm1 \n\t"
In file included from ffmpeg/libavcodec/dcadec.c:1: In file included from ffmpeg/libavcodec/dcadec.c:53: ffmpeg/libavcodec/x86/dca.h:34:9: error: invalid instruction mnemonic 'cvtsi2ssl' "cvtsi2ssl %2, %%xmm0 \n\t" ^ <inline asm>:1:2: note: instantiated into assembly here cvtsi2ssl -44(%rbp), %xmm0 ^~~~~~~~~ btw iam starting to think that the issue should be fixed on the icl side or some wraper script be written to do all these translations [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
On 11 February 2014 03:33, Michael Niedermayer <michaelni@gmx.at> wrote:
On 10 February 2014 09:21, Reimar Döffinger <Reimar.Doeffinger@gmx.de wrote:
On Thu, Feb 06, 2014 at 12:35:13PM +1100, Matt Oliver wrote:
On 6 February 2014 05:45, Reimar Döffinger <Reimar.Doeffinger@gmx.de
wrote:
On Wed, Feb 05, 2014 at 11:41:38AM +1100, Matt Oliver wrote:
Cheers for the feedback. Ill split up the patches to make things
To
start off I have split the libmpcodec patches into some smaller easily digestible chunks.
Patch 1: Changes a couple of inline asm labels for using named labels to standard numbered labels. This has no affect but to allow for compilation with compilers that dont support named labels.
If you use numbered labels I believe you need to append the jump direction. I.e. jnz 1b instead of jnz 1 if you mean the 1: label that comes before. At least that is what I see in e.g. libavcodec/x86/snowdsp.c and many more files.
> Well, having the DECLARE_ALIGNED changes separately would be nice since I think that part can be applied without further review.
Patch 2: Is just the declare aligned fixes. This uses the existing cross platform specific declare aligned macro instead of the gcc only attribute. Seperated as Reimar suggested.
You seem to have lost the very first "static". Otherwise it looks ok to me.
Patch 3: Removes unnecessary commas from some inline asm. Leaving the commas in with nothing following them causes icl compilation errors. removing them has no impact on anything else as ive seen this used else where in ffmpeg so this should have no impact.
Looks good to me as well. If nobody has any other comments I will try to get it applied to MPlayer soon to try to keep the codebases in sync (or if I'm too slow anyone with commit access there is of course free to apply them). _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
If you use numbered labels I believe you need to append the jump direction.
You only have to do this if you have multiple labels with the same name. In this case the forward/backward identifiers are so the assembler knows which label you are referring to (closest in front or closest behind). Since
easier. the
labels in the patch are all unique then there is only one so we dont need to specify which direction to find it.
I don't trust that this is always true, and I see no reason to do
On Mon, Feb 10, 2014 at 06:53:23PM +1100, Matt Oliver wrote: things
different than all other places I could find. So I changed that.
You seem to have lost the very first "static". Otherwise it looks ok to me.
That I did, fixed in updated patch attached. I changed to using the predefined ASM_CONSTANT macro that auto includes static const.
You changed one uint8_t to int8_t, I fixed that before applying. Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Please provide the relevant (!!) part of config.log
Sorry Carl, I rescind my previous statement. Gcc works fine it was my MinGW that was failing and after checking the logs a second time I realised it was actually due to a random write permission error in creating the temp file that has started cropping up since I moved to Win8.1. So it could be changed if thats what people want. In not 100% about the change myself as if Intel do update there compiler with direct symbol references then due to the way they resolve references currently without the 'test' declaration it would still fail. This is a future proof thing so Im happy to concede to whatever the group consensus is.
I'm not going to argue against this being an icl bug, but I'm surprised you can't come up with a concept that works. Doesn't something like "leal (%l2, %l3), %l3" work? Also, which one does it convert to 64bit?
Ive tried everything I can think of so Im certainly open to suggestions. Ive tried every combination of constraints I could think off (although Intel doesnt support all of them) and just could not get it to work. As to which operand register is being set to either 32bit/64bit im not sure as the error message doesnt specify so the only way would be to try and find the line in the compiler intermediary output (which im understandably in no hurry to attempt). All i can ascertain from the error message is one of %2/%3 is 32bit and the other is 64bit. As to why the difference I have no idea as they both have the same constraint and are both uint. I tried your suggestion about prefixing operands with 'l' (although im not familiar with this technique) a direct substitution resulted in the error: "Substitution directive specifies non-existent operand in asm instruction". Although as I said im not familiar with that technique (im guessing the prefix forces it to use long sized registers?) i may be missing something. But nothing ive tried works, even trying to change the leal to just lea or something generates errors (illegal reg in address for those who are interested). So I ran out of ideas. Basically everything else ive tried generates the "Unsupported instruction form" error. Intel just does not like lea instructions where the input are not explicit registers. Thats the only way I know of to fix it is to move say %2 into an explicit register and then use that but that would potentially negatively affect other buildchains. If there is a fix I would love to know it.
You changed one uint8_t to int8_t, I fixed that before applying.
Otherwise all patches have been applied to MPlayer's libmpcodecs. I have _not_ synced the FFmpeg code, if someone can easily do that please go ahead.
Must have missed that when i updated, Thanks Reimar for picking it up and fixing it.
Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility (I didnt add it to the previous patch so that for those who have already looked over and ok'ed the current version dont have to recheck them).
dca.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) dfdf0508b391e5e0f7f68344b6798802289af7ee 7-6-Additional-icl-inline-asm-fix.patch From 7929bc1ae54be0f79b4407b8916d5e42d69f4fcf Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Mon, 10 Feb 2014 18:51:48 +1100 Subject: [PATCH] [7/6] Additional icl inline asm fix.
--- libavcodec/x86/dca.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/x86/dca.h b/libavcodec/x86/dca.h index 6415129..cefac59 100644 --- a/libavcodec/x86/dca.h +++ b/libavcodec/x86/dca.h @@ -31,7 +31,7 @@ static inline void int8x8_fmul_int32(av_unused DCADSPContext *dsp, { DECLARE_ALIGNED(16, static const uint32_t, inverse16) = 0x3D800000; __asm__ volatile ( - "cvtsi2ss %2, %%xmm0 \n\t" + "cvtsi2ssl %2, %%xmm0 \n\t" "mulss %3, %%xmm0 \n\t" "movq (%1), %%xmm1 \n\t" "punpcklbw %%xmm1, %%xmm1 \n\t"
In file included from ffmpeg/libavcodec/dcadec.c:1: In file included from ffmpeg/libavcodec/dcadec.c:53: ffmpeg/libavcodec/x86/dca.h:34:9: error: invalid instruction mnemonic 'cvtsi2ssl' "cvtsi2ssl %2, %%xmm0 \n\t" ^ <inline asm>:1:2: note: instantiated into assembly here cvtsi2ssl -44(%rbp), %xmm0 ^~~~~~~~~
btw iam starting to think that the issue should be fixed on the icl side or some wraper script be written to do all these translations
[...]
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Your right in that it would be much easier if icl would just fix there stuff (hell id do it if theyd let me) but from what I understand its a low priority. However if cvtsi2ssl is causing errors then I can add it to the existing patch that detects between cdq/cltd. Given that one already tries to detect intel mnemonics then we can just add cvtsi2ss as an additional one and treat it the same as cdq. Hopefully there wont be any others but if there is we can at least add them to the mnemonic list (or find someone at Intel to help fix it).
Hi, 2014-02-10 8:53 GMT+01:00 Matt Oliver <protogonoi@gmail.com>:
Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility (I didnt add it to the previous patch so that for those who have already looked over and ok'ed the current version dont have to recheck them).
Ideally, the patch in "[PATCH] dcadsp: move test out of loop and dspize" would fix this in an alternate and probably better way (but I'm biased). -- Christophe
On 11 February 2014 07:27, Christophe Gisquet <christophe.gisquet@gmail.com>wrote:
Hi,
2014-02-10 8:53 GMT+01:00 Matt Oliver <protogonoi@gmail.com>:
Also some recent changes in master have added some new asm in the file dca.h. Attached is a standalone patch that fixes that for intel compatibility (I didnt add it to the previous patch so that for those who have already looked over and ok'ed the current version dont have to recheck them).
Ideally, the patch in "[PATCH] dcadsp: move test out of loop and dspize" would fix this in an alternate and probably better way (but I'm biased).
-- Christophe _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Well should I update the previous patch with a new one that adds cvtsi2ss to the intel mnemonic list or just leave them as is and wait for the status of the above patch to be updated first? Im leaving the country tomorrow after which I wont be able to work on this for a week or 2 so let me know of any changes before then otherwise ill just have to get to them when I get back.
Since the asm in x86/dca.h is no longer being used then the previous patch to fix it is no longer required. As such I will resubmit the previous patches again. It has been several weeks and there hasnt been any issues raised with the last set so no major changes need to be be made. So I will place them here all together again. Also for completeness I will add the additional 2 extra patches that I had previously submitted. This includes a fourth patch for libmpcodecs (the first 3 have according to Reimar been applied to the libmpcodec repos but has not been synced in to FFmpegs yet). This patch requires the direct symbol reference patch for FFmpeg (patch 3) to be applied first as it uses the symbol mangling changes for direct symbol references. Lastly there is the final patch that enables inline asm for icl within configure. This obviously can only be done once all the other patches have been applied. So here they all are:
Matt Oliver <protogonoi <at> gmail.com> writes: [...]
From a quick look, the configure change(s) seems incorrect (did you test with gcc?), the new constants you add (inline_asm_*) have to be added to the HAVE_LIST.
And I don't think the inline_asm_direct_symbol_refs test can work: You need to MANGLE() the symbol "test". (For the moment, I suggest you simply set the define for icl, the test can still be done later.) Carl Eugen
From a quick look, the configure change(s) seems incorrect
(did you test with gcc?), the new constants you add
(inline_asm_*) have to be added to the HAVE_LIST.
Yes they were all tested with gcc. And all the inline_asm_* *are* added to the HAVE_LIST. Pretty much the first change in each patch is to add to the HAVE_LIST. (Although from looking at some of the line numbers they might have changed a bit with some of the recent patches to master but hopefully still applies anyway). So in tests both gcc and icl generate the expected config values (which are always the direct opposite of each other) and all values are correctly exported to the config.h and compilation completes exactly as expected. And I don't think the inline_asm_direct_symbol_refs test
can work: You need to MANGLE() the symbol "test".
In code i would agree but im not sure how I can use MANGLE given that it is not defined within the configure script (given its a macro in libavutil/asm.h and all). Also as the test just does a compilation pass to see if direct symbols are allowed so it doesnt then do any linking so the name mangling should never be an issue.
Matt Oliver <protogonoi <at> gmail.com> writes:
From a quick look, the configure change(s) seems incorrect
(did you test with gcc?), the new constants you add (inline_asm_*) have to be added to the HAVE_LIST.
Yes they were all tested with gcc. And all the inline_asm_* *are* added to the HAVE_LIST.
Yes, sorry: The reason is that your patches either don't apply to current git head or that there is a special order that is not obvious from the numbering in your email: 0002-2-6-Check-for-nonlocal-inline-asm-labels.patch fails here (after applying 0001-1-6-Add-missing-external-declarations.patch). [...]
And I don't think the inline_asm_direct_symbol_refs test can work: You need to MANGLE() the symbol "test".
In code i would agree but im not sure how I can use MANGLE given that it is not defined within the configure script (given its a macro in libavutil/asm.h and all).
Of course.
Also as the test just does a compilation pass to see if direct symbols are allowed so it doesnt then do any linking so the name mangling should never be an issue.
Then please remove "int test" which is only confusing. Carl Eugen
The reason is that your patches either don't apply to current git head or that there is a special order that is not obvious from the numbering in your email
Numbering should be self explanatory, but it appears the patches need to be rebased again due to changes in master (thats the problem with these patches having been around for many weeks while master keeps getting updated). Ill rebase these again and put them up tomorrow. The changes will stay exactly the same just some of the line numbers need to be updated due to additions in other parts of configure.
OK In the last couple of days their have been a couple of commits to master that altered the order of items in the HAVE_LIST in configure so thats why the patches were not applying. Those are fixed now so as long as there are not any more changes to configure between now and when you test these then all should be good (cross fingers). So take 2. Here are the patches (only patch 2,3,6,7 needed rebasing) with all of them supplied for completeness. The patches should be applied in order (i.e from 1/6 to 6/6) for ffmpeg. Then there is the fourth patch for libmpcodecs (first three already applied upstream). Finally the last patch to enable all inline asm for icl. On 14 March 2014 02:28, Matt Oliver <protogonoi@gmail.com> wrote:
The reason is that your patches either
don't apply to current git head or that there is a special order that is not obvious from the numbering in your email
Numbering should be self explanatory, but it appears the patches need to be rebased again due to changes in master (thats the problem with these patches having been around for many weeks while master keeps getting updated). Ill rebase these again and put them up tomorrow. The changes will stay exactly the same just some of the line numbers need to be updated due to additions in other parts of configure.
On Fri, Mar 14, 2014 at 04:20:15PM +1100, Matt Oliver wrote:
OK In the last couple of days their have been a couple of commits to master that altered the order of items in the HAVE_LIST in configure so thats why the patches were not applying. Those are fixed now so as long as there are not any more changes to configure between now and when you test these then all should be good (cross fingers).
So take 2. Here are the patches (only patch 2,3,6,7 needed rebasing) with all of them supplied for completeness.
The patches should be applied in order (i.e from 1/6 to 6/6) for ffmpeg. Then there is the fourth patch for libmpcodecs (first three already applied upstream). Finally the last patch to enable all inline asm for icl.
I have not tested or reviewed too closely but I think at least 1 - 6 are ok, except for nits below.. I have a few doubts about the last ones I would need to double-check. A few small comments/nits: In the very first patch you seem to have a space at the start of the line before "extern"? And for the CTLD patch: inline asm code is normal strings, there is no point in writing ""CTLD just use CLTD
In the very first patch you seem to have a space at the start of the
line before "extern"? Fixed, thanks. And for the CTLD patch: inline asm code is normal strings, there is no
point in writing ""CTLD just use CLTD
Fixed, I knew the double "'s was unnecessary but i initially left them in there to make it very clear to other devs that CLTD is string. Of course any dev playing round with the asm would probably have worked that out anyway so its removed. The patches have been rebased again. Recent configure changes moved the way items are listed. So now the changes are added to TOOLCHAIN_FEATURES instead of HAVE_LIST directly so that its inline with those recent upstream modifications (also upstream merge of Diegos "K&R formatting cosmetics" necessitated another rebase). And again all of them included together for simplicity. Constantly rebasing and fixing merge conflicts is time consuming so if there is no interest in this then let me know so I can save some effort.
On Sun, Mar 16, 2014 at 03:10:40PM +1100, Matt Oliver wrote:
In the very first patch you seem to have a space at the start of the
line before "extern"?
Fixed, thanks.
And for the CTLD patch: inline asm code is normal strings, there is no
point in writing ""CTLD just use CLTD
Fixed, I knew the double "'s was unnecessary but i initially left them in there to make it very clear to other devs that CLTD is string. Of course any dev playing round with the asm would probably have worked that out anyway so its removed.
Hm, it still seems to be there... I'd suggest if there are no more objections to go ahead with applying 1-6 to avoid further work due to having to rebase (and remove the pointless "" afterwards or while applying, or just only apply 1-5). I'd be happy if someone else could take a look at the remaining ones I didn't manage to review properly yet, otherwise I'll try to find time later.
On Sun, Mar 16, 2014 at 03:10:40PM +1100, Matt Oliver wrote:
In the very first patch you seem to have a space at the start of the
line before "extern"?
Fixed, thanks.
And for the CTLD patch: inline asm code is normal strings, there is no
point in writing ""CTLD just use CLTD
Fixed, I knew the double "'s was unnecessary but i initially left them in there to make it very clear to other devs that CLTD is string. Of course any dev playing round with the asm would probably have worked that out anyway so its removed.
The patches have been rebased again. Recent configure changes moved the way items are listed. So now the changes are added to TOOLCHAIN_FEATURES instead of HAVE_LIST directly so that its inline with those recent upstream modifications (also upstream merge of Diegos "K&R formatting cosmetics" necessitated another rebase). And again all of them included together for simplicity. Constantly rebasing and fixing merge conflicts is time consuming so if there is no interest in this then let me know so I can save some effort.
libavcodec/x86/cabac.h | 2 ++ libavcodec/x86/constants.h | 2 ++ libswscale/x86/rgb2rgb.c | 7 +++++++ 3 files changed, 11 insertions(+) 912d3c23cb308940b787bf45bef48de2647dbdcc 0001-1-6-Add-missing-external-declarations.patch From f0eb0084d6453e08d589019391c1072d1f6b69a5 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 16 Mar 2014 14:40:53 +1100 Subject: [PATCH 1/6] [1/6] Add missing external declarations.
--- libavcodec/x86/cabac.h | 2 ++ libavcodec/x86/constants.h | 2 ++ libswscale/x86/rgb2rgb.c | 7 +++++++ 3 files changed, 11 insertions(+)
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 781c636..7acda3c 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -118,6 +118,8 @@ #define TABLES_ARG #define RIP_ARG
+extern uint8_t ff_h264_cabac_tables[512 + 4*2*64 + 4*64 + 63]; + #if HAVE_FAST_CMOV #define BRANCHLESS_GET_CABAC_UPDATE(ret, low, range, tmp)\ "mov "tmp" , %%ecx \n\t"\
In file included from ffmpeg/libavcodec/cabac_functions.h:42:0, from ffmpeg/libavcodec/cabac.c:33: ffmpeg/libavcodec/x86/cabac.h:116:16: warning: redundant redeclaration of ‘ff_h264_cabac_tables’ [-Wredundant-decls] ffmpeg/libavcodec/cabac.h:34:16: note: previous declaration of ‘ff_h264_cabac_tables’ was here
diff --git a/libavcodec/x86/constants.h b/libavcodec/x86/constants.h index 8097bc4..4bf74ff 100644 --- a/libavcodec/x86/constants.h +++ b/libavcodec/x86/constants.h @@ -31,6 +31,7 @@ extern const xmm_reg ff_pw_3; extern const xmm_reg ff_pw_4; extern const xmm_reg ff_pw_5; extern const xmm_reg ff_pw_8; +extern const xmm_reg ff_pw_9; extern const uint64_t ff_pw_15; extern const xmm_reg ff_pw_16; extern const xmm_reg ff_pw_18; @@ -45,6 +46,7 @@ extern const uint64_t ff_pw_255;
extern const xmm_reg ff_pb_1; extern const xmm_reg ff_pb_3; +extern const xmm_reg ff_pb_80; extern const xmm_reg ff_pb_F8; extern const uint64_t ff_pb_FC;
diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c index 8cc99c6..89677d2 100644 --- a/libswscale/x86/rgb2rgb.c +++ b/libswscale/x86/rgb2rgb.c @@ -76,6 +76,13 @@ DECLARE_ASM_CONST(8, uint64_t, mul15_mid) = 0x4200420042004200ULL; DECLARE_ASM_CONST(8, uint64_t, mul15_hi) = 0x0210021002100210ULL; DECLARE_ASM_CONST(8, uint64_t, mul16_mid) = 0x2080208020802080ULL;
+DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YOffset); +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2YCoeff); +DECLARE_ALIGNED(8, extern const uint64_t, ff_w1111);
+DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2UCoeff); +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2VCoeff); +DECLARE_ALIGNED(8, extern const uint64_t, ff_bgr2UVOffset);
these are unused [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras
On Sun, Mar 16, 2014 at 03:10:40PM +1100, Matt Oliver wrote:
In the very first patch you seem to have a space at the start of the
line before "extern"?
Fixed, thanks.
And for the CTLD patch: inline asm code is normal strings, there is no
point in writing ""CTLD just use CLTD
Fixed, I knew the double "'s was unnecessary but i initially left them in there to make it very clear to other devs that CLTD is string. Of course any dev playing round with the asm would probably have worked that out anyway so its removed.
The patches have been rebased again. Recent configure changes moved the way items are listed. So now the changes are added to TOOLCHAIN_FEATURES instead of HAVE_LIST directly so that its inline with those recent upstream modifications (also upstream merge of Diegos "K&R formatting cosmetics" necessitated another rebase). And again all of them included together for simplicity. Constantly rebasing and fixing merge conflicts is time consuming so if there is no interest in this then let me know so I can save some effort.
[...] [...]
diff --git a/libavcodec/x86/h264_i386.h b/libavcodec/x86/h264_i386.h index f6a8043..da112c4 100644 --- a/libavcodec/x86/h264_i386.h +++ b/libavcodec/x86/h264_i386.h @@ -55,6 +55,7 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, __asm__ volatile( "lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t" : "=&r"(tables) + : NAMED_CONSTRAINTS(ff_h264_cabac_tables) ); #endif
@@ -130,6 +131,7 @@ static int decode_significance_8x8_x86(CABACContext *c, __asm__ volatile( "lea "MANGLE(ff_h264_cabac_tables)", %0 \n\t" : "=&r"(tables) + : NAMED_CONSTRAINTS(ff_h264_cabac_tables) ); #endif
diff --git a/libavcodec/x86/idct_sse2_xvid.c b/libavcodec/x86/idct_sse2_xvid.c index af4790c..e1878fa 100644 --- a/libavcodec/x86/idct_sse2_xvid.c +++ b/libavcodec/x86/idct_sse2_xvid.c @@ -147,7 +147,7 @@ DECLARE_ASM_CONST(16, int32_t, walkenIdctRounders)[] = {
#endif
-#define ROUND(x) "paddd "MANGLE(x) +#define ROUND(x) "paddd "x
#define JZ(reg, to) \ "testl "reg","reg" \n\t" \ @@ -347,13 +347,13 @@ inline void ff_idct_xvid_sse2(short *block) { __asm__ volatile( "movq "MANGLE(m127)", %%mm0 \n\t" - iMTX_MULT("(%0)", MANGLE(iTab1), ROUND(walkenIdctRounders), PUT_EVEN(ROW0)) - iMTX_MULT("1*16(%0)", MANGLE(iTab2), ROUND(walkenIdctRounders+1*16), PUT_ODD(ROW1)) - iMTX_MULT("2*16(%0)", MANGLE(iTab3), ROUND(walkenIdctRounders+2*16), PUT_EVEN(ROW2)) + iMTX_MULT("(%0)", MANGLE(iTab1), ROUND(MANGLE(walkenIdctRounders)), PUT_EVEN(ROW0)) + iMTX_MULT("1*16(%0)", MANGLE(iTab2), ROUND("1*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW1)) + iMTX_MULT("2*16(%0)", MANGLE(iTab3), ROUND("2*16+"MANGLE(walkenIdctRounders)), PUT_EVEN(ROW2))
TEST_TWO_ROWS("3*16(%0)", "4*16(%0)", "%%eax", "%%ecx", CLEAR_ODD(ROW3), CLEAR_EVEN(ROW4)) JZ("%%eax", "1f") - iMTX_MULT("3*16(%0)", MANGLE(iTab4), ROUND(walkenIdctRounders+3*16), PUT_ODD(ROW3)) + iMTX_MULT("3*16(%0)", MANGLE(iTab4), ROUND("3*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW3))
TEST_TWO_ROWS("5*16(%0)", "6*16(%0)", "%%eax", "%%edx", CLEAR_ODD(ROW5), CLEAR_EVEN(ROW6)) TEST_ONE_ROW("7*16(%0)", "%%esi", CLEAR_ODD(ROW7)) @@ -368,20 +368,20 @@ inline void ff_idct_xvid_sse2(short *block) "2: \n\t" iMTX_MULT("4*16(%0)", MANGLE(iTab1), "#", PUT_EVEN(ROW4)) "3: \n\t" - iMTX_MULT("5*16(%0)", MANGLE(iTab4), ROUND(walkenIdctRounders+4*16), PUT_ODD(ROW5)) + iMTX_MULT("5*16(%0)", MANGLE(iTab4), ROUND("4*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW5)) JZ("%%edx", "1f") "4: \n\t" - iMTX_MULT("6*16(%0)", MANGLE(iTab3), ROUND(walkenIdctRounders+5*16), PUT_EVEN(ROW6)) + iMTX_MULT("6*16(%0)", MANGLE(iTab3), ROUND("5*16+"MANGLE(walkenIdctRounders)), PUT_EVEN(ROW6)) JZ("%%esi", "1f") "5: \n\t" - iMTX_MULT("7*16(%0)", MANGLE(iTab2), ROUND(walkenIdctRounders+5*16), PUT_ODD(ROW7)) + iMTX_MULT("7*16(%0)", MANGLE(iTab2), ROUND("5*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW7))
the change to round could be in a seperate patch [...]
mpegvideoenc_template.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 2b12c0ec5941fd82fe2c38c5646db8c6583ad574 0005-5-6-Fixed-64bit-conformance-with-mvzbl.patch From 754b9dc487260dedfae4be38c88dc60734561f67 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 9 Feb 2014 17:10:12 +1100 Subject: [PATCH 5/6] [5/6] Fixed 64bit conformance with mvzbl.
patch applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB When you are offended at any man's fault, turn to yourself and study your own failings. Then you will forget your anger. -- Epictetus
Heres an update to patch 1 that fixes the warnings (some variables got orphaned since i originally wrote the patch). Also an updated patch 6 with the "'s removed (they snuck back in when rebasing somehow). the change to round could be in a separate patch The changes to round are required as otherwise the syntax used to apply the offset (i.e. 2*16) is incorrect when using named constraints (icl will error like crazy). Which is why its in the same patch as otherwise the changes wont work anyway and I didnt think a broken patch was all that useful. f you want me to separate them then Although if its easier for you if I separate them then let me know. So which patches have been applied and which do you want me to rework?
On Mon, Mar 17, 2014 at 10:44:56AM +1100, Matt Oliver wrote:
Heres an update to patch 1 that fixes the warnings (some variables got orphaned since i originally wrote the patch).
Also an updated patch 6 with the "'s removed (they snuck back in when rebasing somehow).
the change to round could be in a separate patch
The changes to round are required as otherwise the syntax used to apply the offset (i.e. 2*16) is incorrect when using named constraints (icl will error like crazy). Which is why its in the same patch as otherwise the changes wont work anyway and I didnt think a broken patch was all that useful. f you want me to separate them then Although if its easier for you if I separate them then let me know.
the change to ROUND should be fine before the rest
So which patches have been applied
9eb3f11 Add missing external declarations. 590805b Fixed 64bit conformance with mvzbl.
and which do you want me to rework?
some of the patches seem to not apply cleanly [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB It is dangerous to be right in matters on which the established authorities are wrong. -- Voltaire
some of the patches seem to not apply cleanly
Had to do a rebase again. This time patch 2 and 3 needed updating due to a changes in 1 and some upstream modifications. I created a clean repo and applied all the patches without error so should be good now.
On Mon, Mar 17, 2014 at 12:08:50PM +1100, Matt Oliver wrote:
some of the patches seem to not apply cleanly
Had to do a rebase again. This time patch 2 and 3 needed updating due to a changes in 1 and some upstream modifications.
as you mention rebases with some touch of "ohh shit i hate this work" (which i can understand of course ...) If this patchset is applied it will need someone to maintain it otherwise it will probably be more broken than working most of the time. I mean changes to asm will likely break the intel specia cases and would need someone regularly testing with affected compilers and updating things ...
I created a clean repo and applied all the patches without error so should be good now.
configure | 6 ++++++ libavcodec/x86/mlpdsp.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) fab12562f034a123084e2f5d626ee66d5fbd1271 0002-2-6-Check-for-nonlocal-inline-asm-labels.patch From afa726326ece927f4959a3b575b181c7bba42f93 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 16 Mar 2014 14:53:39 +1100 Subject: [PATCH 2/6] [2/6] Check for nonlocal inline asm labels.
--- configure | 6 ++++++ libavcodec/x86/mlpdsp.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) mode change 100755 => 100644 configure
diff --git a/configure b/configure index 34200a3..14475ae --- a/configure +++ b/configure @@ -1689,6 +1689,7 @@ TOOLCHAIN_FEATURES=" gnu_windres ibm_asm inline_asm_labels + inline_asm_nonlocal_labels pragma_deprecated rsync_contimeout symver_asm_label
@@ -1917,6 +1918,9 @@ fast_unaligned_if_any="aarch64 ppc x86"
need_memalign="altivec neon sse"
+inline_asm_labels_deps="inline_asm"
unrelated
+inline_asm_nonlocal_labels_deps="inline_asm" + # system capabilities log2_deps="!libc_msvcrt"
is this actually needed ? [...] [...]
index af4790c..e1878fa 100644 --- a/libavcodec/x86/idct_sse2_xvid.c +++ b/libavcodec/x86/idct_sse2_xvid.c @@ -147,7 +147,7 @@ DECLARE_ASM_CONST(16, int32_t, walkenIdctRounders)[] = {
#endif
-#define ROUND(x) "paddd "MANGLE(x) +#define ROUND(x) "paddd "x
#define JZ(reg, to) \ "testl "reg","reg" \n\t" \ @@ -347,13 +347,13 @@ inline void ff_idct_xvid_sse2(short *block) { __asm__ volatile( "movq "MANGLE(m127)", %%mm0 \n\t" - iMTX_MULT("(%0)", MANGLE(iTab1), ROUND(walkenIdctRounders), PUT_EVEN(ROW0)) - iMTX_MULT("1*16(%0)", MANGLE(iTab2), ROUND(walkenIdctRounders+1*16), PUT_ODD(ROW1)) - iMTX_MULT("2*16(%0)", MANGLE(iTab3), ROUND(walkenIdctRounders+2*16), PUT_EVEN(ROW2)) + iMTX_MULT("(%0)", MANGLE(iTab1), ROUND(MANGLE(walkenIdctRounders)), PUT_EVEN(ROW0)) + iMTX_MULT("1*16(%0)", MANGLE(iTab2), ROUND("1*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW1)) + iMTX_MULT("2*16(%0)", MANGLE(iTab3), ROUND("2*16+"MANGLE(walkenIdctRounders)), PUT_EVEN(ROW2))
TEST_TWO_ROWS("3*16(%0)", "4*16(%0)", "%%eax", "%%ecx", CLEAR_ODD(ROW3), CLEAR_EVEN(ROW4)) JZ("%%eax", "1f") - iMTX_MULT("3*16(%0)", MANGLE(iTab4), ROUND(walkenIdctRounders+3*16), PUT_ODD(ROW3)) + iMTX_MULT("3*16(%0)", MANGLE(iTab4), ROUND("3*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW3))
TEST_TWO_ROWS("5*16(%0)", "6*16(%0)", "%%eax", "%%edx", CLEAR_ODD(ROW5), CLEAR_EVEN(ROW6)) TEST_ONE_ROW("7*16(%0)", "%%esi", CLEAR_ODD(ROW7)) @@ -368,20 +368,20 @@ inline void ff_idct_xvid_sse2(short *block) "2: \n\t" iMTX_MULT("4*16(%0)", MANGLE(iTab1), "#", PUT_EVEN(ROW4)) "3: \n\t" - iMTX_MULT("5*16(%0)", MANGLE(iTab4), ROUND(walkenIdctRounders+4*16), PUT_ODD(ROW5)) + iMTX_MULT("5*16(%0)", MANGLE(iTab4), ROUND("4*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW5)) JZ("%%edx", "1f") "4: \n\t" - iMTX_MULT("6*16(%0)", MANGLE(iTab3), ROUND(walkenIdctRounders+5*16), PUT_EVEN(ROW6)) + iMTX_MULT("6*16(%0)", MANGLE(iTab3), ROUND("5*16+"MANGLE(walkenIdctRounders)), PUT_EVEN(ROW6)) JZ("%%esi", "1f") "5: \n\t" - iMTX_MULT("7*16(%0)", MANGLE(iTab2), ROUND(walkenIdctRounders+5*16), PUT_ODD(ROW7)) + iMTX_MULT("7*16(%0)", MANGLE(iTab2), ROUND("5*16+"MANGLE(walkenIdctRounders)), PUT_ODD(ROW7)) #if ARCH_X86_32 iLLM_HEAD #endif iLLM_PASS("%0")
applied hunks above [...]
diff --git a/libswscale/x86/swscale_template.c b/libswscale/x86/swscale_template.c index c7a1bb4..6ea3f6d 100644 --- a/libswscale/x86/swscale_template.c +++ b/libswscale/x86/swscale_template.c @@ -171,7 +171,8 @@ static void RENAME(yuv2yuvX)(const int16_t *filter, int filterSize, #define YSCALEYUV2PACKEDX_END \ :: "r" (&c->redDither), \ "m" (dummy), "m" (dummy), "m" (dummy),\ - "r" (dest), "m" (dstW_reg), "m"(uv_off) \ + "r" (dest), "m" (dstW_reg), "m"(uv_off) +#define YSCALEYUV2PACKEDX_END2 \ : "%"REG_a, "%"REG_d, "%"REG_S \ );
@@ -360,12 +361,14 @@ static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter, "packuswb %%mm7, %%mm1 \n\t" WRITEBGR32(%4, %5, %%REGa, %%mm3, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm2, %%mm6) YSCALEYUV2PACKEDX_END + YSCALEYUV2PACKEDX_END2 } else { YSCALEYUV2PACKEDX_ACCURATE YSCALEYUV2RGBX "pcmpeqd %%mm7, %%mm7 \n\t" WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) YSCALEYUV2PACKEDX_END + YSCALEYUV2PACKEDX_END2 } }
this looks a bit more complex than needed you should be able to just unconditionally add the NAMED_CONSTRAINTS_ADD() to the existing macro this would also decrease the likelhood of future changes breaking this code [...]
diff --git a/libswscale/x86/yuv2rgb_template.c b/libswscale/x86/yuv2rgb_template.c index c879102..0e39a7b 100644 --- a/libswscale/x86/yuv2rgb_template.c +++ b/libswscale/x86/yuv2rgb_template.c @@ -138,6 +138,8 @@ : "+r" (index), "+r" (image) \ : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), \ "r" (py - 2*index) \ + +#define YUV2RGB_OPERANDS2 \ : "memory" \ ); \ } \ @@ -146,9 +148,6 @@ : "+r" (index), "+r" (image) \ : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), \ "r" (py - 2*index), "r" (pa - 2*index) \ - : "memory" \ - ); \ - } \
#define YUV2RGB_ENDFUNC \ __asm__ volatile (SFENCE"\n\t" \ @@ -207,6 +206,8 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[],
YUV2RGB_ENDLOOP(2) YUV2RGB_OPERANDS + NAMED_CONSTRAINTS_ADD(mmx_00ffw,pb_03,mmx_redmask,pb_e0) + YUV2RGB_OPERANDS2 YUV2RGB_ENDFUNC
same issue here
}
@@ -235,6 +236,8 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, const uint8_t *src[],
YUV2RGB_ENDLOOP(2) YUV2RGB_OPERANDS + NAMED_CONSTRAINTS_ADD(mmx_00ffw,pb_07,mmx_redmask,pb_e0) + YUV2RGB_OPERANDS2 YUV2RGB_ENDFUNC } #endif /* !COMPILE_TEMPLATE_MMXEXT */ @@ -260,6 +263,8 @@ DECLARE_ASM_CONST(8, int16_t, mask0010[4]) = { 0, 0,-1, 0}; DECLARE_ASM_CONST(8, int16_t, mask0110[4]) = { 0,-1,-1, 0}; DECLARE_ASM_CONST(8, int16_t, mask1001[4]) = {-1, 0, 0,-1}; DECLARE_ASM_CONST(8, int16_t, mask0100[4]) = { 0,-1, 0, 0}; +#undef RGB_PACK24_B_OPERANDS +#define RGB_PACK24_B_OPERANDS NAMED_CONSTRAINTS_ADD(mask1101,mask0110,mask0100,mask0010,mask1001) #undef RGB_PACK24_B #define RGB_PACK24_B\ "pshufw $0xc6, %%mm2, %%mm1 \n"\ @@ -283,6 +288,8 @@ DECLARE_ASM_CONST(8, int16_t, mask0100[4]) = { 0,-1, 0, 0};
and here [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In fact, the RIAA has been known to suggest that students drop out of college or go to community college in order to be able to afford settlements. -- The RIAA
If this patchset is applied it will need someone to maintain it otherwise it will probably be more broken than working most of the time.
Figured as much. The reason ive been updating these patches for the last few months is that I have my own repo that I use for compiling ffmpeg for Windows that I use in a project im working on. So for a while atleast I will be compiling ffmpeg using icl (and the proposed changes) so its easier for me to locate bugs and I will be fixing them in my own repo so its not to much effort to provide them upstream. The rebasing is kind of a pain, but thats mainly because these patches were initially written up last year and have been working in my repo for ages. The rebasing is just so I can get the patches relative to upstream head so that you guys can apply it easily. And all the rebasing is pretty much always because configure is modified pretty much every day. Once the configure changes are in from the initial patches future updates will mostly be just re-tweaking some asm and shouldn't have so many issues and wouldnt need constant rebasing. Either way consider me able and willing to support the icl asm for awhile.
+inline_asm_nonlocal_labels_deps="inline_asm"
+ # system capabilities log2_deps="!libc_msvcrt"
is this actually needed ?
Possibly not, the nonlocal labels should not be used if inline asm is disabled as the code will never get called. But as far as the config.h header is concerned I figured for completeness there is no point having the option enabled in the header when it clearly cant be because all inline asm is disabled. I assumed it was logical to include it but if you want it removed anyway let me know. this looks a bit more complex than needed
you should be able to just unconditionally add the NAMED_CONSTRAINTS_ADD() to the existing macro
I though of doing that but there are several locations ( line 392, 759, 781 to name a few) where there are no additional named constraints added. There are also several locations where only 1 named constraint is required. So by adding all of them to the existing macro then it would be adding named constraints that are only needed in some but not all instances. This raises compilation warnings about unused named references so I opted to keep things as clean and efficient as possible. So again Ill leave this up to you. If youd prefer the possible safety of just adding all named constraints to the existing macro but have some of them be unused at various times then let me know. This also goes for the RGB_PACK24_B_OPERANDS as combining them will result in additional unneeded constraints being added to asm blocks that dont use them.
On Mon, Mar 17, 2014 at 03:32:59PM +1100, Matt Oliver wrote:
If this patchset is applied it will need someone to maintain it otherwise it will probably be more broken than working most of the time.
Figured as much. The reason ive been updating these patches for the last few months is that I have my own repo that I use for compiling ffmpeg for Windows that I use in a project im working on. So for a while atleast I will be compiling ffmpeg using icl (and the proposed changes) so its easier for me to locate bugs and I will be fixing them in my own repo so its not to much effort to provide them upstream. The rebasing is kind of a pain, but thats mainly because these patches were initially written up last year and have been working in my repo for ages. The rebasing is just so I can get the patches relative to upstream head so that you guys can apply it easily. And all the rebasing is pretty much always because configure is modified pretty much every day. Once the configure changes are in from the initial patches future updates will mostly be just re-tweaking some asm and shouldn't have so many issues and wouldnt need constant rebasing.
Either way consider me able and willing to support the icl asm for awhile.
ok, thanks
+inline_asm_nonlocal_labels_deps="inline_asm"
+ # system capabilities log2_deps="!libc_msvcrt"
is this actually needed ?
Possibly not, the nonlocal labels should not be used if inline asm is disabled as the code will never get called. But as far as the config.h header is concerned I figured for completeness there is no point having the option enabled in the header when it clearly cant be because all inline asm is disabled. I assumed it was logical to include it but if you want it removed anyway let me know.
i think its better not to have unneeded code in there, so if its needed it should stay, if not it should be removed
this looks a bit more complex than needed
you should be able to just unconditionally add the NAMED_CONSTRAINTS_ADD() to the existing macro
I though of doing that but there are several locations ( line 392, 759, 781 to name a few) where there are no additional named constraints added. There are also several locations where only 1 named constraint is required. So by adding all of them to the existing macro then it would be adding named constraints that are only needed in some but not all instances. This raises compilation warnings about unused named references so I opted to keep things as clean and efficient as possible. So again Ill leave this up to you. If youd prefer the possible safety of just adding all named constraints to the existing macro but have some of them be unused at various times then let me know. This also goes for the RGB_PACK24_B_OPERANDS as combining them will result in additional unneeded constraints being added to asm blocks that dont use them.
These constraints are there because of limitions/shortcommings of intels asm() support on windows. IMO we should keep such workarounds to the minimum possible [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Everything should be made as simple as possible, but not simpler. -- Albert Einstein
i think its better not to have unneeded code in there, so if its needed it should stay, if not it should be removed
Removed. These constraints are there because of limitions/shortcommings of
intels asm() support on windows. IMO we should keep such workarounds to the minimum possible
Fair enough, I updated the patches accordingly. These are basically the minimum workarounds possible. The main changes occurred in yuv2rgb_template where all references were added to the YUV2RGB_OPERANDS macro. This added 5 constraints (although in many situations only 1 is actually used). The one thing ill point out is that these additional named constraints are variables that are not actually from the YUV2RGB macro (which is why they weren't initially put in there) so this may make the code a little less readable for other devs as all these variables are used by the other functions that use the YUV2RGB macro not from within the macro itself. Also I had to add an #if to define RGB_PACK24_B_OPERANDS as these variables are only defined if COMPILE_TEMPLATE_MMXEXT so having them all the time will result in errors. This again may be a little unclear for other developers as the variables in question (mask1101 etc.) havnt even been declared at this point in code. And of course the variables are not relevant to YUV2RGB macro and are only used in a couple of the later functions as they are only relevant to the RGB_PACK24_B macro and the functions that use it. Trying to separate the RGB_PACK24_B variables cant be simply done, in fact the simplest way to separate them is pretty much the way the original patch was done. So its up to you which one you prefer.
On Tue, Mar 18, 2014 at 04:52:55PM +1100, Matt Oliver wrote:
i think its better not to have unneeded code in there, so if its needed it should stay, if not it should be removed
Removed.
These constraints are there because of limitions/shortcommings of
intels asm() support on windows. IMO we should keep such workarounds to the minimum possible
Fair enough, I updated the patches accordingly. These are basically the minimum workarounds possible. The main changes occurred in yuv2rgb_template where all references were added to the YUV2RGB_OPERANDS macro. This added 5 constraints (although in many situations only 1 is actually used). The one thing ill point out is that these additional named constraints are variables that are not actually from the YUV2RGB macro (which is why they weren't initially put in there) so this may make the code a little less readable for other devs as all these variables are used by the other functions that use the YUV2RGB macro not from within the macro itself.
Also I had to add an #if to define RGB_PACK24_B_OPERANDS as these variables are only defined if COMPILE_TEMPLATE_MMXEXT so having them all the time will result in errors. This again may be a little unclear for other developers as the variables in question (mask1101 etc.) havnt even been declared at this point in code. And of course the variables are not relevant to YUV2RGB macro and are only used in a couple of the later functions as they are only relevant to the RGB_PACK24_B macro and the functions that use it. Trying to separate the RGB_PACK24_B variables cant be simply done, in fact the simplest way to separate them is pretty much the way the original patch was done. So its up to you which one you prefer.
configure | 3 +++ libavcodec/x86/mlpdsp.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) b89e0bced3342badd213b5dccc454a829cc37658 0002-2-6-Check-for-nonlocal-inline-asm-labels.patch From 5674f153f6e45cf487907bbe67b7109f5d7a83c0 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Tue, 18 Mar 2014 15:29:14 +1100 Subject: [PATCH 2/6] [2/6] Check for nonlocal inline asm labels.
applied [...]
configure | 3 +++ libavcodec/x86/cabac.h | 3 ++- libavcodec/x86/cavsdsp.c | 2 ++ libavcodec/x86/dsputil_mmx.c | 1 + libavcodec/x86/h264_i386.h | 2 ++ libavcodec/x86/idct_sse2_xvid.c | 2 +- libavcodec/x86/lpc.c | 3 +++ libavcodec/x86/motion_est.c | 7 ++++--- libavcodec/x86/simple_idct.c | 1 + libavcodec/x86/vc1dsp_mmx.c | 6 ++++++ libavutil/x86/asm.h | 36 +++++++++++++++++++++++++++++++++++- libpostproc/postprocess_template.c | 7 +++++++ libswresample/x86/resample_mmx.h | 2 ++ libswscale/x86/rgb2rgb_template.c | 11 +++++++++++ libswscale/x86/swscale_template.c | 12 ++++++++++++ libswscale/x86/yuv2rgb_template.c | 9 +++++++++ 16 files changed, 101 insertions(+), 6 deletions(-) 74d49e1ba28eff2023cc9738d5db65796c179c39 0003-3-6-Check-for-inline-asm-direct-symbol-reference.patch From 1f3868943e761d1826f4a56e6ec9951273d47d40 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Tue, 18 Mar 2014 15:53:26 +1100 Subject: [PATCH 3/6] [3/6] Check for inline asm direct symbol reference.
applied most of it [...]
cabac.h | 9 +++++++-- h264_i386.h | 4 ++-- vp56_arith.h | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) 389c1c1629a1f08bb7b8b4d2b85ad6335ecf9202 0004-4-6-Fix-for-broken-register-allocation-issues-with-I.patch From 8450aea3c8bbfabea218d9b1980eebe4bda24643 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Tue, 18 Mar 2014 15:54:27 +1100 Subject: [PATCH 4/6] [4/6] Fix for broken register allocation issues with Intel.
--- libavcodec/x86/cabac.h | 9 +++++++-- libavcodec/x86/h264_i386.h | 4 ++-- libavcodec/x86/vp56_arith.h | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 0a68b7b..efcb192 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -33,6 +33,11 @@ #else # define BROKEN_COMPILER 0 #endif +#if (defined(__INTEL_COMPILER) && defined(_MSC_VER)) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
i assume this is because the code gets miscompiled ? did you report the miscompilation to intel ? [...]
mpegvideoenc_template.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 2b12c0ec5941fd82fe2c38c5646db8c6583ad574 0005-5-6-Fixed-64bit-conformance-with-mvzbl.patch From 754b9dc487260dedfae4be38c88dc60734561f67 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 9 Feb 2014 17:10:12 +1100 Subject: [PATCH 5/6] [5/6] Fixed 64bit conformance with mvzbl.
this has aready been applied also feel free to send a patch that adds yourself to MAINTAINERs for all these intel compiler workarounds [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
On 19 March 2014 10:45, Michael Niedermayer <michaelni@gmx.at> wrote:
i think its better not to have unneeded code in there, so if its needed it should stay, if not it should be removed
Removed.
These constraints are there because of limitions/shortcommings of
intels asm() support on windows. IMO we should keep such workarounds to the minimum possible
Fair enough, I updated the patches accordingly. These are basically the minimum workarounds possible. The main changes occurred in yuv2rgb_template where all references were added to the YUV2RGB_OPERANDS macro. This added 5 constraints (although in many situations only 1 is actually used). The one thing ill point out is that these additional named constraints are variables that are not actually from the YUV2RGB macro (which is why they weren't initially put in there) so this may make the code a little less readable for other devs as all these variables are used by the other functions that use the YUV2RGB macro not from within the macro itself.
Also I had to add an #if to define RGB_PACK24_B_OPERANDS as these variables are only defined if COMPILE_TEMPLATE_MMXEXT so having them all the time will result in errors. This again may be a little unclear for other developers as the variables in question (mask1101 etc.) havnt even been declared at this point in code. And of course the variables are not relevant to YUV2RGB macro and are only used in a couple of the later functions as they are only relevant to the RGB_PACK24_B macro and the functions that use it. Trying to separate the RGB_PACK24_B variables cant be simply done, in fact the simplest way to separate them is pretty much the way the original patch was done. So its up to you which one you
On Tue, Mar 18, 2014 at 04:52:55PM +1100, Matt Oliver wrote: prefer.
configure | 3 +++ libavcodec/x86/mlpdsp.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) b89e0bced3342badd213b5dccc454a829cc37658 0002-2-6-Check-for-nonlocal-inline-asm-labels.patch From 5674f153f6e45cf487907bbe67b7109f5d7a83c0 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Tue, 18 Mar 2014 15:29:14 +1100 Subject: [PATCH 2/6] [2/6] Check for nonlocal inline asm labels.
applied
[...]
configure | 3 +++ libavcodec/x86/cabac.h | 3 ++- libavcodec/x86/cavsdsp.c | 2 ++ libavcodec/x86/dsputil_mmx.c | 1 + libavcodec/x86/h264_i386.h | 2 ++ libavcodec/x86/idct_sse2_xvid.c | 2 +- libavcodec/x86/lpc.c | 3 +++ libavcodec/x86/motion_est.c | 7 ++++--- libavcodec/x86/simple_idct.c | 1 + libavcodec/x86/vc1dsp_mmx.c | 6 ++++++ libavutil/x86/asm.h | 36 +++++++++++++++++++++++++++++++++++- libpostproc/postprocess_template.c | 7 +++++++ libswresample/x86/resample_mmx.h | 2 ++ libswscale/x86/rgb2rgb_template.c | 11 +++++++++++ libswscale/x86/swscale_template.c | 12 ++++++++++++ libswscale/x86/yuv2rgb_template.c | 9 +++++++++ 16 files changed, 101 insertions(+), 6 deletions(-) 74d49e1ba28eff2023cc9738d5db65796c179c39 0003-3-6-Check-for-inline-asm-direct-symbol-reference.patch From 1f3868943e761d1826f4a56e6ec9951273d47d40 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Tue, 18 Mar 2014 15:53:26 +1100 Subject: [PATCH 3/6] [3/6] Check for inline asm direct symbol reference.
applied most of it
[...]
cabac.h | 9 +++++++-- h264_i386.h | 4 ++-- vp56_arith.h | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-) 389c1c1629a1f08bb7b8b4d2b85ad6335ecf9202 0004-4-6-Fix-for-broken-register-allocation-issues-with-I.patch From 8450aea3c8bbfabea218d9b1980eebe4bda24643 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Tue, 18 Mar 2014 15:54:27 +1100 Subject: [PATCH 4/6] [4/6] Fix for broken register allocation issues with Intel.
--- libavcodec/x86/cabac.h | 9 +++++++-- libavcodec/x86/h264_i386.h | 4 ++-- libavcodec/x86/vp56_arith.h | 8 +++++++- 3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/libavcodec/x86/cabac.h b/libavcodec/x86/cabac.h index 0a68b7b..efcb192 100644 --- a/libavcodec/x86/cabac.h +++ b/libavcodec/x86/cabac.h @@ -33,6 +33,11 @@ #else # define BROKEN_COMPILER 0 #endif +#if (defined(__INTEL_COMPILER) && defined(_MSC_VER)) +# define BROKEN_REGISTER_ALLOCATION 1 +#else +# define BROKEN_REGISTER_ALLOCATION 0 +#endif
i assume this is because the code gets miscompiled ? did you report the miscompilation to intel ?
[...]
mpegvideoenc_template.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 2b12c0ec5941fd82fe2c38c5646db8c6583ad574 0005-5-6-Fixed-64bit-conformance-with-mvzbl.patch From 754b9dc487260dedfae4be38c88dc60734561f67 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 9 Feb 2014 17:10:12 +1100 Subject: [PATCH 5/6] [5/6] Fixed 64bit conformance with mvzbl.
this has aready been applied
also feel free to send a patch that adds yourself to MAINTAINERs for all these intel compiler workarounds
[...]
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
thanks for that. i assume this is because the code gets miscompiled ?
did you report the miscompilation to intel ?
Yeh the syntax of all the instructions is correct and ive tested the function independently and it is correct with respect to what icl technically supports but once you actually use it within the context of FFmpeg the compiler throws an internal error as it is not capable of correctly allocating enough registers. Now that were moving ahead with getting the icl patches included I will direct intel to the code and the error. However I dont expect it be fixed for a compiler version or 2. applied most of it Ill see if I can find another way to get icl to compile while still using MANGLE but if memory serves I tried basically every combination I could think off and couldnt get it to compile any other way. Are there any issues with fixing it the way I did?
applied most of it
Ill see if I can find another way to get icl to compile while still using MANGLE but if memory serves I tried basically every combination I could think off and couldnt get it to compile any other way. Are there any issues with fixing it the way I did?
OK so I couldnt get icl to play nice with that 1 MANGLE line. The only way ive been able to get it to work is to add round_tab[2] to the asm interface instead of having it as a direct symbol reference. This should not be a problem as this is how all the other sad_xxx functions use round_tab (see x86/motion_est.c lines 351, 366, 408, 423 ). The patch is attached. Also now that the named reference patch has been applied to ffmpeg then the corresponding changes to libmpcodec can now be applied (patch 4/4 also attached). libmpcodes is the only part that hasnt been updated yet with the new changes (this may also be useful for the lto problem Carl was working on). Reimar Döffinger apparently applied the last set of patches (patches 1/4 -> 3/4) to upstream mplayer so if he or someone else can get this applied upstream (assuming everything looks good of course). Once that is done then the upstream libmpcodec can be merged into ffmpeg as the first 3 fixes applied upstream over a month ago still havnt been synced.
On Sat, Mar 22, 2014 at 04:24:27PM +1100, Matt Oliver wrote:
applied most of it
Ill see if I can find another way to get icl to compile while still using MANGLE but if memory serves I tried basically every combination I could think off and couldnt get it to compile any other way. Are there any issues with fixing it the way I did?
OK so I couldnt get icl to play nice with that 1 MANGLE line. The only way ive been able to get it to work is to add round_tab[2] to the asm interface instead of having it as a direct symbol reference. This should not be a problem as this is how all the other sad_xxx functions use round_tab (see x86/motion_est.c lines 351, 366, 408, 423 ). The patch is attached.
Also now that the named reference patch has been applied to ffmpeg then the corresponding changes to libmpcodec can now be applied (patch 4/4 also attached). libmpcodes is the only part that hasnt been updated yet with the new changes (this may also be useful for the lto problem Carl was working on). Reimar Döffinger apparently applied the last set of patches (patches 1/4 -> 3/4) to upstream mplayer so if he or someone else can get this applied upstream (assuming everything looks good of course). Once that is done then the upstream libmpcodec can be merged into ffmpeg as the first 3 fixes applied upstream over a month ago still havnt been synced.
motion_est.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) eee662e5bd3c1afcbf175174527587342f999cd0 Additional-icl-inline-asm-fix.patch From 3aed84433ff4dd10ce3194b69905377559527149 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sat, 22 Mar 2014 15:59:12 +1100 Subject: [PATCH] Additional icl inline asm fix.
applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Let us carefully observe those good qualities wherein our enemies excel us and endeavor to excel them, by avoiding what is faulty, and imitating what is excellent in them. -- Plutarch
OK here is a slightly different approach to fixing the missing CLTD instruction support for icl inline asm. After looking into the situation further I noticed that CLTD is only used in 2 places and in both places it is for generating a sign mask. Since on most modern processors CLTD (CDQ technically) is a 2 clock cycle instruction then a sign mask can alternately be created using an arithmetic right shift (which is always a 1 clock cycle instruction). Although this often requires an extra mov instruction to backup the register contents this extra mov is again 1 clock cycle so the net difference is nothing. So on most current processors replacing it has zero net difference (in fact the uops for cdq are often an mov/sar anyway). Its only different on older processors such as AMDs K8/K9/Jaguar and PentiumM etc. that actually have a 1 clock cycle cdq. To try and rectify I renamed some registers to optimize performance through removing pipeline stalls and allowing throughput optimization so that the mov/sar can be dual issued on any processor that supports it. This should reduce times by 1 clock cycle. So the net performance difference depends on processor but it will either be zero diff or potentially 1 clock cycle faster (changing it in MASK_ABS removes the fixed eax/edx register requirements and allows the compiler to arrange things as it wants. This allows it to remove a mov or 2 aswell). Since we are talking 1 clock cycle here then benchmarking shows no real world difference between the 2 approaches. However this second approach does work on icl whereas the previous does not. So I want technically call this an optimization as it has no real world performance diff but it does fix icl inline asm support.
On Sat, Mar 29, 2014 at 03:18:44PM +1100, Matt Oliver wrote:
OK here is a slightly different approach to fixing the missing CLTD instruction support for icl inline asm. After looking into the situation further I noticed that CLTD is only used in 2 places and in both places it is for generating a sign mask.
Since on most modern processors CLTD (CDQ technically) is a 2 clock cycle instruction then a sign mask can alternately be created using an arithmetic right shift (which is always a 1 clock cycle instruction). Although this often requires an extra mov instruction to backup the register contents this extra mov is again 1 clock cycle so the net difference is nothing. So on most current processors replacing it has zero net difference (in fact the uops for cdq are often an mov/sar anyway). Its only different on older processors such as AMDs K8/K9/Jaguar and PentiumM etc. that actually have a 1 clock cycle cdq. To try and rectify I renamed some registers to optimize performance through removing pipeline stalls and allowing throughput optimization so that the mov/sar can be dual issued on any processor that supports it. This should reduce times by 1 clock cycle.
2 instructions instead of 1 increase pressure on the code cache and codecs like h264 are complex enough so the code cache size should have signifiant effects
So the net performance difference depends on processor but it will either be zero diff or potentially 1 clock cycle faster (changing it in MASK_ABS removes the fixed eax/edx register requirements and allows the compiler to arrange things as it wants. This allows it to remove a mov or 2 aswell). Since we are talking 1 clock cycle here then benchmarking shows no real world difference between the 2 approaches. However this second approach does work on icl whereas the previous does not. So I want technically call this an optimization as it has no real world performance diff but it does fix icl inline asm support.
did you benchmark this ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Democracy is the form of government in which you can choose your dictator
Hi, On Sat, Mar 29, 2014 at 12:18 AM, Matt Oliver <protogonoi@gmail.com> wrote:
OK here is a slightly different approach to fixing the missing CLTD instruction support for icl inline asm. After looking into the situation further I noticed that CLTD is only used in 2 places and in both places it is for generating a sign mask.
Why not create a macro that expands to the correct instruction supported for each compiler? #if some stuff #define CLTD_CDQ "cdq" #else #define CLTD_CDQ "cltd" #endif We do that for e.g. register size detection (e.g. REG_a for eax vs. rax), I think it's fine here also. Ronald
On 29.03.2014, at 18:12, "Ronald S. Bultje" <rsbultje@gmail.com> wrote:
Hi,
On Sat, Mar 29, 2014 at 12:18 AM, Matt Oliver <protogonoi@gmail.com> wrote:
OK here is a slightly different approach to fixing the missing CLTD instruction support for icl inline asm. After looking into the situation further I noticed that CLTD is only used in 2 places and in both places it is for generating a sign mask.
Why not create a macro that expands to the correct instruction supported for each compiler?
#if some stuff #define CLTD_CDQ "cdq" #else #define CLTD_CDQ "cltd" #endif
We do that for e.g. register size detection (e.g. REG_a for eax vs. rax), I think it's fine here also.
It's probably more the assembler used than the compiler actually. Plus, we all seem to not have any of the affected systems at hand. I admit I didn't expect we'd spend quite as much time on this. Maybe we should indeed just switch it and figure out a solution if and when someone actually complains and we thus have a proper test-case?
On Sat, Mar 29, 2014 at 06:22:26PM +0100, Reimar Döffinger wrote:
On 29.03.2014, at 18:12, "Ronald S. Bultje" <rsbultje@gmail.com> wrote:
Hi,
On Sat, Mar 29, 2014 at 12:18 AM, Matt Oliver <protogonoi@gmail.com> wrote:
OK here is a slightly different approach to fixing the missing CLTD instruction support for icl inline asm. After looking into the situation further I noticed that CLTD is only used in 2 places and in both places it is for generating a sign mask.
Why not create a macro that expands to the correct instruction supported for each compiler?
#if some stuff #define CLTD_CDQ "cdq" #else #define CLTD_CDQ "cltd" #endif
We do that for e.g. register size detection (e.g. REG_a for eax vs. rax), I think it's fine here also.
It's probably more the assembler used than the compiler actually. Plus, we all seem to not have any of the affected systems at hand. I admit I didn't expect we'd spend quite as much time on this.
Maybe we should indeed just switch it and figure out a solution if and when someone actually complains and we thus have a proper test-case?
yes, maybe can someone provide a patch or push with matching commit message ? [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
did you read what i wrote ? ;)
Yeh, got what you meant, If this were to be applied then some more benchmarking would probably be in order first but if cdq is valid then as said this is rather all moot (I will make sure I include such results in the future though). Why not create a macro that expands to the correct instruction supported
for each compiler?
Actually this is what I did in the first place (see previous patch in this email chain). But that patch wasnt applied so this patch was more just providing an alternative solution so people could decide which they preferred. I should point out that a patch such as thist one would not be my preferred approach it was just a different attempt to find a solution.
Maybe we should indeed just switch it and figure out a solution if and when someone actually complains and we thus have a proper test-case? yes, maybe can someone provide a patch or push with matching commit message ?
If cdq works for everyone then obviously the best and cleanest solution would be just changing it back. I have attached the necessary patch.
On Sun, Mar 30, 2014 at 12:45:42PM +1100, Matt Oliver wrote:
did you read what i wrote ? ;)
Yeh, got what you meant, If this were to be applied then some more benchmarking would probably be in order first but if cdq is valid then as said this is rather all moot (I will make sure I include such results in the future though).
Why not create a macro that expands to the correct instruction supported
for each compiler?
Actually this is what I did in the first place (see previous patch in this email chain). But that patch wasnt applied so this patch was more just providing an alternative solution so people could decide which they preferred. I should point out that a patch such as thist one would not be my preferred approach it was just a different attempt to find a solution.
Maybe we should indeed just switch it and figure out a solution if and when someone actually complains and we thus have a proper test-case? yes, maybe can someone provide a patch or push with matching commit message ?
If cdq works for everyone then obviously the best and cleanest solution would be just changing it back. I have attached the necessary patch.
cabac.h | 4 ++-- mathops.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 7c9da7074a9dc21159ec82db666e8d8124d5d809 Use-intel-compliant-CDQ-instead-of-CLTD-in-inline-as.patch From 7c40d0f7109cb45a09d274a7feaa33b71df71177 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 30 Mar 2014 12:34:49 +1100 Subject: [PATCH] Use intel compliant CDQ instead of CLTD in inline asm.
patch applied [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB You can kill me, but you cannot change the truth.
Heres an additional patch that modifies some of the inline asm to make it work under icl. One previous issue was a lea instruction that would not compile under 64b icl. It seems icl has some sort of conformance checks which fail due to a 32 bit lea operation on what it must assume is an address (which is why it only fails in 64b due to the mismatch in forcing a 32b value). On a second look the lea is only being used to perform an add operation without modifying the flags register. This however is actually used to create a value that previously already existed in register (the code subtracts a value and then uses the lea to re-add it). So the lea can be removed and the original value can just be used instead. This requires an additional register to store the old value for a couple of instructions but based on where the code is used there doesnt appear to be much issue with that (as the removal of a add operation outweighs the extra register cost). The function itself benches as being ~5.3% faster when tested over a 100 million iterations on random data. To test the affect of the changed register usage I tested it within vp9s decode_coeffs_b_generic and vp5s vp5_parse_vector_adjustment. The performance gains where obviously less due to the rest of the function overhead (0.5%, 3.9% respectively) but there was no performance degradation and this new function compiles under 64b icl. The only remaining inline asm still in master that does not compile under icl is BRANCHLESS_GET_CABAC in x86/cabac.h. So if no one has any objections I was going to move that to external asm.
On Sat, Apr 05, 2014 at 02:17:41PM +1100, Matt Oliver wrote:
Heres an additional patch that modifies some of the inline asm to make it work under icl.
One previous issue was a lea instruction that would not compile under 64b icl. It seems icl has some sort of conformance checks which fail due to a 32 bit lea operation on what it must assume is an address (which is why it only fails in 64b due to the mismatch in forcing a 32b value).
On a second look the lea is only being used to perform an add operation without modifying the flags register. This however is actually used to create a value that previously already existed in register (the code subtracts a value and then uses the lea to re-add it). So the lea can be removed and the original value can just be used instead. This requires an additional register to store the old value for a couple of instructions but based on where the code is used there doesnt appear to be much issue with that (as the removal of a add operation outweighs the extra register cost).
The function itself benches as being ~5.3% faster when tested over a 100 million iterations on random data. To test the affect of the changed register usage I tested it within vp9s decode_coeffs_b_generic and vp5s vp5_parse_vector_adjustment. The performance gains where obviously less due to the rest of the function overhead (0.5%, 3.9% respectively) but there was no performance degradation and this new function compiles under 64b icl.
The only remaining inline asm still in master that does not compile under icl is BRANCHLESS_GET_CABAC in x86/cabac.h. So if no one has any objections I was going to move that to external asm.
i dont think that this will work out benchmark/speed wise
vp56_arith.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 7e6ff58f6fdb0924a46b7a875467b8f66163685c Remove-leal-op-to-fix-icl-inline-asm.patch From 5f53a57bc8fedcd221164c95846471fc033095df Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sat, 5 Apr 2014 14:00:13 +1100 Subject: [PATCH] Remove leal op to fix icl inline asm.
--- libavcodec/x86/vp56_arith.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index e71dbf8..570885a 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -28,25 +28,22 @@ #define vp56_rac_get_prob vp56_rac_get_prob static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) { - unsigned int code_word = vp56_rac_renorm(c); - unsigned int high = c->high; - unsigned int low = 1 + (((high - 1) * prob) >> 8); + c->code_word = vp56_rac_renorm( c ); + unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
declaration after statement [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides
On Sat, Apr 5, 2014 at 5:17 AM, Matt Oliver <protogonoi@gmail.com> wrote:
The only remaining inline asm still in master that does not compile under icl is BRANCHLESS_GET_CABAC in x86/cabac.h. So if no one has any objections I was going to move that to external asm.
CABAC needs to be inline asm to really benefit. Add the call overhead and the limitations on reordering code, and the benefit melts away. If ICL can't build it, it should just be excluded, but external asm doesn't work for the CABAC case without performance regressions. - Hendrik
declaration after statement
Sorry, fixed in new patch.
CABAC needs to be inline asm to really benefit. Add the call overhead and the limitations on reordering code, and the benefit melts away. If ICL can't build it, it should just be excluded, but external asm doesn't work for the CABAC case without performance regressions.
I figured as much which is why I asked in the first place (although I had a spare hour or 2 and wrote it up after sending that email anyway). I did have a previous patch that just excluded the cabac stuff when icl was detected but it hasnt as yet been applied. If the current patch gets applied ill write up a new one so that cabac is excluded under icl.
On Sat, Apr 05, 2014 at 11:52:59PM +1100, Matt Oliver wrote:
declaration after statement
Sorry, fixed in new patch.
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
Interestingly both compilers I tested with didnt show any errors and had the upper bits zeroed. However as the function returns a 32b int and any code that calls this function would also assume 32b then a xor to set to 0 initially is still probably the way to go. Using uint8 would save that instruction but would add one later to clear the upper bytes should it ever be used for anything larger than 1B. So fixed to add back the set to 0.
On Sun, Apr 06, 2014 at 12:21:54AM +1100, Matt Oliver wrote:
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
Interestingly both compilers I tested with didnt show any errors and had the upper bits zeroed. However as the function returns a 32b int and any code that calls this function would also assume 32b then a xor to set to 0 initially is still probably the way to go. Using uint8 would save that instruction but would add one later to clear the upper bytes should it ever be used for anything larger than 1B. So fixed to add back the set to 0.
I think it is better like this since it's an unrelated change. However when it comes to performance it might be better to use uint8_t, since this code as-is is very likely to cause partial register stalls as far as I can tell. A movzx would increase code size, but not increase number of instructions and avoid this issue. It would also free a register if it was moved last and = instead of =& used (if the compiler manages to figure it out). Of course only benchmarking would tell if it really is an improvement.
On 6 April 2014 00:47, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote:
On Sun, Apr 06, 2014 at 12:21:54AM +1100, Matt Oliver wrote:
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
Interestingly both compilers I tested with didnt show any errors and had the upper bits zeroed. However as the function returns a 32b int and any code that calls this function would also assume 32b then a xor to set to 0 initially is still probably the way to go. Using uint8 would save that instruction but would add one later to clear the upper bytes should it ever be used for anything larger than 1B. So fixed to add back the set to 0.
I think it is better like this since it's an unrelated change. However when it comes to performance it might be better to use uint8_t, since this code as-is is very likely to cause partial register stalls as far as I can tell. A movzx would increase code size, but not increase number of instructions and avoid this issue. It would also free a register if it was moved last and = instead of =& used (if the compiler manages to figure it out). Of course only benchmarking would tell if it really is an improvement. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
The way it is currently (as of last patch) is 5.4% faster. However changing it to a uint8 (and using = as suggested) is actually only 0.97% faster. Whether a movzx is added explicitly to the asm or allowing the compiler to do the convert on return results in identical performance. The function could be changed to return a uint8 but on inspection only vp5 will benefit from this (it has a lot of if(rac_get_prob) that can work directly on uint8) as all the others work directly on int's which would add the conversion which benchmarking shows provided limited benefit. In fact I tested it with the vp5 function and it didnt add any benefit over the current patch. So from the benchmark results it appears the patch as of the last update provides the best performance. On another note I was looking at the cabac functions in x86/cabac.h and at present the x86 optimised get_cabac_inline is excluded by the BROKEN_COMPILER define. However the functions in x86/h264_i386.h are not excluded. I find this interesting as get_cabac_inline just has a single implementation of the BRANCHLESS_GET_CABAC macro which is apparently broken. While for instance the function decode_significance in h264_i386 has multiple BRANCHLESS_GET_CABAC's which I would have assumed would also be broken. Should BROKEN_COMPILER also exclude these functions? icl is broken under any function that calls BRANCHLESS_GET_CABAC so if the existing BROKEN_COMPILER should also be used to exclude the functions in h264_i386 then icl can just be added on to the existing define. otherwise a new one must be added just for icl. Adding it to the existing one would be cleaner and with the smallest amount of changes and I wonder if this is actually the correct way anyway as I would assume the h264_i386 should be marked as broken under those compilers anyway.
On 06.04.2014, at 06:29, Matt Oliver <protogonoi@gmail.com> wrote:
On 6 April 2014 00:47, Reimar Döffinger <Reimar.Doeffinger@gmx.de> wrote: The way it is currently (as of last patch) is 5.4% faster. However changing it to a uint8 (and using = as suggested) is actually only 0.97% faster.
This is confusing, I thought the speedup was from removing the lea? Changing the type would be on top. So you mean that after the first patch, changing the type causes a ca. 4% slowdown?
The function could be changed to return a uint8 but on inspection only vp5 will benefit from this (it has a lot of if(rac_get_prob) that can work directly on uint8)
That should be wrong. All the ifs should be using the _branchy variant which does not use the asm code at all.
This is confusing, I thought the speedup was from removing the lea? Changing the type would be on top. So you mean that after the first patch, changing the type causes a ca. 4% slowdown?
Yeh, both variants are in fact faster than what is there currently as the speedup is from replacing the lea. But the version with uint8 is not as fast as the one provided in the last patch.
That should be wrong. All the ifs should be using the _branchy variant which does not use the asm code at all.
Well if it should be then its not. All the functions in vp5.c use vp56_rac_get_prob not the branchy version. Look at vp5_parse_vector_models for example. It appears vp8 and vp9 use the branchy version which is why i singled out vp5 as one that may benefit. However it appears that vp5.c may be in need of some updates to use the branchy version. If these should be using the branchy version then there is really no reason to use uint8. So the current patch would appear to be the way to go.
On Sun, Apr 06, 2014 at 12:21:54AM +1100, Matt Oliver wrote:
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
Interestingly both compilers I tested with didnt show any errors and had the upper bits zeroed. However as the function returns a 32b int and any code that calls this function would also assume 32b then a xor to set to 0 initially is still probably the way to go. Using uint8 would save that instruction but would add one later to clear the upper bytes should it ever be used for anything larger than 1B. So fixed to add back the set to 0.
Just to clarify: this patch looks good to me and I think it should be applied unless someone has objections. The discussion afterwards on whether it could be optimized further is kind of unrelated.
On Sun, Apr 06, 2014 at 12:21:54AM +1100, Matt Oliver wrote:
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
Interestingly both compilers I tested with didnt show any errors and had the upper bits zeroed. However as the function returns a 32b int and any code that calls this function would also assume 32b then a xor to set to 0 initially is still probably the way to go. Using uint8 would save that instruction but would add one later to clear the upper bytes should it ever be used for anything larger than 1B. So fixed to add back the set to 0.
vp56_arith.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 7a259454956d08f2c3e8375715c253a3327780d4 Remove-leal-op-to-fix-icl-inline-asm.patch From 995c066d7b48d2a6603bb46649badba74e757dd5 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 6 Apr 2014 00:11:21 +1100 Subject: [PATCH] Remove leal op to fix icl inline asm.
--- libavcodec/x86/vp56_arith.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index e71dbf8..6cc97dd 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -29,24 +29,21 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) { unsigned int code_word = vp56_rac_renorm(c); - unsigned int high = c->high; - unsigned int low = 1 + (((high - 1) * prob) >> 8); + unsigned int low = 1 + (((c->high - 1) * prob) >> 8); unsigned int low_shift = low << 16; int bit = 0; + c->code_word = code_word;
__asm__( "subl %4, %1 \n\t" "subl %3, %2 \n\t" - "leal (%2, %3), %3 \n\t" "setae %b0 \n\t" "cmovb %4, %1 \n\t" - "cmovb %3, %2 \n\t" - : "+q"(bit), "+r"(high), "+r"(code_word), "+r"(low_shift) - : "r"(low) + "cmovb %5, %2 \n\t" + : "+q"(bit), "+r"(c->high), "+r"(c->code_word) + : "r"(low_shift), "r"(low), "r"(code_word) );
- c->high = high; - c->code_word = code_word;
this patch breaks fate-vp6a-skip_alpha, fate-vp6f and fate-vp6a possibly also others, didnt test with -k [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Everything should be made as simple as possible, but not simpler. -- Albert Einstein
On Sun, Apr 06, 2014 at 03:29:39PM +0200, Michael Niedermayer wrote:
On Sun, Apr 06, 2014 at 12:21:54AM +1100, Matt Oliver wrote:
If you do not initialize "bit", making it an output-only paramenter, you should use =&q instead of +q as constraint. However neither is correct as-is, setae sets only a single byte, thus not initializing it will result in uninitialized data, IOW the code as is is broken. If you want to do that kind of change, you would have to use uint8_t instead as type.
Interestingly both compilers I tested with didnt show any errors and had the upper bits zeroed. However as the function returns a 32b int and any code that calls this function would also assume 32b then a xor to set to 0 initially is still probably the way to go. Using uint8 would save that instruction but would add one later to clear the upper bytes should it ever be used for anything larger than 1B. So fixed to add back the set to 0.
vp56_arith.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 7a259454956d08f2c3e8375715c253a3327780d4 Remove-leal-op-to-fix-icl-inline-asm.patch From 995c066d7b48d2a6603bb46649badba74e757dd5 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Sun, 6 Apr 2014 00:11:21 +1100 Subject: [PATCH] Remove leal op to fix icl inline asm.
--- libavcodec/x86/vp56_arith.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/libavcodec/x86/vp56_arith.h b/libavcodec/x86/vp56_arith.h index e71dbf8..6cc97dd 100644 --- a/libavcodec/x86/vp56_arith.h +++ b/libavcodec/x86/vp56_arith.h @@ -29,24 +29,21 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob) { unsigned int code_word = vp56_rac_renorm(c); - unsigned int high = c->high; - unsigned int low = 1 + (((high - 1) * prob) >> 8); + unsigned int low = 1 + (((c->high - 1) * prob) >> 8); unsigned int low_shift = low << 16; int bit = 0; + c->code_word = code_word;
__asm__( "subl %4, %1 \n\t" "subl %3, %2 \n\t" - "leal (%2, %3), %3 \n\t" "setae %b0 \n\t" "cmovb %4, %1 \n\t" - "cmovb %3, %2 \n\t" - : "+q"(bit), "+r"(high), "+r"(code_word), "+r"(low_shift) - : "r"(low) + "cmovb %5, %2 \n\t" + : "+q"(bit), "+r"(c->high), "+r"(c->code_word) + : "r"(low_shift), "r"(low), "r"(code_word) );
- c->high = high; - c->code_word = code_word;
this patch breaks fate-vp6a-skip_alpha, fate-vp6f and fate-vp6a possibly also others, didnt test with -k
I think all the in-out parameters must be +& instead of just +. Note that this was incorrect even before, but it probably shows up only now since now it is trivial for the compiler to figure out that c->code_word and code_word are the same thing, and without early clobber it can place them onto the same register. This of course invalidates all previous benchmarks...
this patch breaks fate-vp6a-skip_alpha, fate-vp6f and fate-vp6a possibly also others, didnt test with -k
Interesting, I always run a local FATE test before submitting anything and it worked fine on mine so that would suggest it is compiler dependent. I think all the in-out parameters must be +& instead of just +.
Note that this was incorrect even before, but it probably shows up only now since now it is trivial for the compiler to figure out that c->code_word and code_word are the same thing, and without early clobber it can place them onto the same register. This of course invalidates all previous benchmarks...
Thanks, I was scratching my head trying to work out what was going on (as stated previously fate worked for me). I was trying to keep the patch to a minimum change wise so it never occurred to me to check that the constraints were correct even in the current git master. I have updated the constraints and, fate still tests as correct using my compilers. I reran the benchmarks and got a slight change in performance but its still 4.6% faster.
On Mon, Apr 07, 2014 at 04:29:32PM +1000, Matt Oliver wrote:
this patch breaks fate-vp6a-skip_alpha, fate-vp6f and fate-vp6a possibly also others, didnt test with -k
Interesting, I always run a local FATE test before submitting anything and it worked fine on mine so that would suggest it is compiler dependent.
I think all the in-out parameters must be +& instead of just +.
Note that this was incorrect even before, but it probably shows up only now since now it is trivial for the compiler to figure out that c->code_word and code_word are the same thing, and without early clobber it can place them onto the same register. This of course invalidates all previous benchmarks...
Thanks, I was scratching my head trying to work out what was going on (as stated previously fate worked for me). I was trying to keep the patch to a minimum change wise so it never occurred to me to check that the constraints were correct even in the current git master.
I have updated the constraints and, fate still tests as correct using my compilers. I reran the benchmarks and got a slight change in performance but its still 4.6% faster.
vp56_arith.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 1421f9dacaf77b65e802781eaf8b09ee873e7be6 Remove-leal-op-to-fix-icl-inline-asm.patch From 97a73c83c9f9202d2d20911a5cf738b6491f7111 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Mon, 7 Apr 2014 13:25:28 +1000 Subject: [PATCH] Remove leal op to fix icl inline asm.
applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The bravest are surely those who have the clearest vision of what is before them, glory and danger alike, and yet notwithstanding go out to meet it. -- Thucydides
Heres the patch to exclude BRANCHLESS_GET_CABAC under icl. Its added to the existing BROKEN_COMPILER which is in turn added to h265_i386.h. This is the simplest and cleanest way to add it to the existing code. Based on the issues in ticket 2999 that resulted in BROKEN_COMPILER being were it is i believe that this patch is correct for the existing use of BROKEN_COMPILER (its most certainly correct for icl).
On Thu, Apr 10, 2014 at 05:28:30PM +1000, Matt Oliver wrote:
Heres the patch to exclude BRANCHLESS_GET_CABAC under icl. Its added to the existing BROKEN_COMPILER which is in turn added to h265_i386.h. This is the simplest and cleanest way to add it to the existing code. Based on the issues in ticket 2999 that resulted in BROKEN_COMPILER being were it is i believe that this patch is correct for the existing use of BROKEN_COMPILER (its most certainly correct for icl).
cabac.h | 5 +++-- h264_i386.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) ca53f2f6166c843a6effa5c9760f45bacd74ba11 Exclude-broken-get_cabac-under-icl.patch From c40e94e70c618a59c5682eb2ef884cd085033cf9 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Thu, 10 Apr 2014 17:19:11 +1000 Subject: [PATCH] Exclude broken get_cabac under icl.
applied thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The worst form of inequality is to try to make unequal things equal. -- Aristotle
On 11 April 2014 01:48, Michael Niedermayer <michaelni@gmx.at> wrote:
Heres the patch to exclude BRANCHLESS_GET_CABAC under icl. Its added to
existing BROKEN_COMPILER which is in turn added to h265_i386.h. This is
On Thu, Apr 10, 2014 at 05:28:30PM +1000, Matt Oliver wrote: the the
simplest and cleanest way to add it to the existing code. Based on the issues in ticket 2999 that resulted in BROKEN_COMPILER being were it is i believe that this patch is correct for the existing use of BROKEN_COMPILER (its most certainly correct for icl).
cabac.h | 5 +++-- h264_i386.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) ca53f2f6166c843a6effa5c9760f45bacd74ba11 Exclude-broken-get_cabac-under-icl.patch From c40e94e70c618a59c5682eb2ef884cd085033cf9 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Thu, 10 Apr 2014 17:19:11 +1000 Subject: [PATCH] Exclude broken get_cabac under icl.
applied
thanks
[...]
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The worst form of inequality is to try to make unequal things equal. -- Aristotle
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Well the last thing that is required for icl compatibility now is the libmpcodec patch. The first 3 have been applied in mplayer upstream but havnt been synced to ffmpeg yet. The last remaining patch is attached. This patch adds the named constraints to libmpcodec inline asm which is required for icl (as done previously in ffmpeg) and is potentially also useful for lto as per previous discussion on using named constraints with link time optimization. Is there someone here who can look over it and apply it upstream or do I need to submit it directly to mplayer? With this last patch (and the upstream sync) ffmpeg will finally have complete icl asm support.
On Sun, Apr 13, 2014 at 05:24:54PM +1000, Matt Oliver wrote:
On 11 April 2014 01:48, Michael Niedermayer <michaelni@gmx.at> wrote:
Heres the patch to exclude BRANCHLESS_GET_CABAC under icl. Its added to
existing BROKEN_COMPILER which is in turn added to h265_i386.h. This is
On Thu, Apr 10, 2014 at 05:28:30PM +1000, Matt Oliver wrote: the the
simplest and cleanest way to add it to the existing code. Based on the issues in ticket 2999 that resulted in BROKEN_COMPILER being were it is i believe that this patch is correct for the existing use of BROKEN_COMPILER (its most certainly correct for icl).
cabac.h | 5 +++-- h264_i386.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) ca53f2f6166c843a6effa5c9760f45bacd74ba11 Exclude-broken-get_cabac-under-icl.patch From c40e94e70c618a59c5682eb2ef884cd085033cf9 Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Thu, 10 Apr 2014 17:19:11 +1000 Subject: [PATCH] Exclude broken get_cabac under icl.
applied
thanks
[...]
-- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
The worst form of inequality is to try to make unequal things equal. -- Aristotle
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Well the last thing that is required for icl compatibility now is the libmpcodec patch. The first 3 have been applied in mplayer upstream but havnt been synced to ffmpeg yet. The last remaining patch is attached. This patch adds the named constraints to libmpcodec inline asm which is required for icl (as done previously in ffmpeg) and is potentially also useful for lto as per previous discussion on using named constraints with link time optimization.
Is there someone here who can look over it and apply it upstream or do I need to submit it directly to mplayer?
i could apply it but it feels wrong to apply things to mplayer that where posted to ffmpeg and not mplayer. Please submit it to mplayer (and in case noone reviews/applies it there, ping me and ill do it) [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
i could apply it but it feels wrong to apply things to mplayer that where posted to ffmpeg and not mplayer. Please submit it to mplayer (and in case noone reviews/applies it there, ping me and ill do it)
Fair enough and thanks, I submitted it to mplayer mailing list so well see how that goes. On an additional note I was playing with some icl settings and found a small error. Seems idct_sse2_xvid.c has a stray inline declaration on one of its functions. The standard or mmx/mmext versions dont have the inline just the sse2 version. Given this is in a .c file and the function is used externally the inline has no affect and seems to cause icl to not export the function properly. Attached is a small patch.
On Mon, Apr 14, 2014 at 03:23:15PM +1000, Matt Oliver wrote:
i could apply it but it feels wrong to apply things to mplayer that where posted to ffmpeg and not mplayer. Please submit it to mplayer (and in case noone reviews/applies it there, ping me and ill do it)
Fair enough and thanks, I submitted it to mplayer mailing list so well see how that goes.
On an additional note I was playing with some icl settings and found a small error. Seems idct_sse2_xvid.c has a stray inline declaration on one of its functions. The standard or mmx/mmext versions dont have the inline just the sse2 version. Given this is in a .c file and the function is used externally the inline has no affect and seems to cause icl to not export the function properly. Attached is a small patch.
idct_sse2_xvid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 6f9f511a83f3fee3b3c4ed0dc1b3538436266183 idct-Remove-redundant-inline-from-xvid_sse.patch From 77ffd0464c8b24b1c87289f5c5c4695e2921309a Mon Sep 17 00:00:00 2001 From: Matt Oliver <protogonoi@gmail.com> Date: Mon, 14 Apr 2014 15:15:59 +1000 Subject: [PATCH] idct: Remove redundant inline from xvid_sse
--- libavcodec/x86/idct_sse2_xvid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavcodec/x86/idct_sse2_xvid.c b/libavcodec/x86/idct_sse2_xvid.c index e1878fa..a02bfae 100644 --- a/libavcodec/x86/idct_sse2_xvid.c +++ b/libavcodec/x86/idct_sse2_xvid.c @@ -343,7 +343,7 @@ DECLARE_ASM_CONST(16, int32_t, walkenIdctRounders)[] = { "movdqa %%xmm6, 4*16("dct") \n\t" \ "movdqa "SREG2", 7*16("dct") \n\t"
-inline void ff_idct_xvid_sse2(short *block) +void ff_idct_xvid_sse2(short *block)
fixed differently [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB While the State exists there can be no freedom; when there is freedom there will be no State. -- Vladimir Lenin
Now that the last of the required icl patches have been applied (the last being the upstream pull of the libmpcodec changes) inline asm can now be enabled for icl within configure. Ive tested several different config options and all seem to work fine for me. The only issue is that EBP/EBX is not available when compiling asm in debug mode. If anyone finds any other issues with enabling this then let me know (in case anyone has issues with different compiler versions etc.) Also added a patch to add me to the maintainers for future icl support. Patches Attached.
On Sat, May 03, 2014 at 07:46:54PM +1000, Matt Oliver wrote:
Now that the last of the required icl patches have been applied (the last being the upstream pull of the libmpcodec changes) inline asm can now be enabled for icl within configure. Ive tested several different config options and all seem to work fine for me. The only issue is that EBP/EBX is not available when compiling asm in debug mode. If anyone finds any other issues with enabling this then let me know (in case anyone has issues with different compiler versions etc.) Also added a patch to add me to the maintainers for future icl support. Patches Attached.
applied thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In a rich man's house there is no place to spit but his face. -- Diogenes of Sinope
On Mon, Feb 03, 2014 at 08:45:24AM +0100, Reimar Döffinger wrote:
On 03.02.2014, at 08:13, Matt Oliver <protogonoi@gmail.com> wrote:
On 27 January 2014 12:07, Matt Oliver <protogonoi@gmail.com> wrote:
Matt Oliver <protogonoi <at> gmail.com> writes:
[...]
Patch 1: Removed 2 minor fixes that are independent of inline asm and are required just to get intel compiler to work in general. These are found in this patch.
Looks good to me.
applied thanks [....] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Concerning the gods, I have no means of knowing whether they exist or not or of what sort they may be, because of the obscurity of the subject, and the brevity of human life -- Protagoras
- __asm__ ("cltd \n\t" \ + __asm__ ("cdq \n\t" \
This one will break Solaris for example.
- "pand "MANGLE(mask0010)", %%mm0 \n" /* -- -- -- -- G1 B1 -- -- */\ + "pand "#_mask0010", %%mm0 \n" /* -- -- -- -- G1 B1 -- -- */\
This one should have told you that ICC doesn't have a problem with the symbols but that MANGLE isn't working right.
libavutil/x86/asm.h:# define LOCAL_MANGLE(a) #a "(%%rip)" libavutil/x86/asm.h:# define LOCAL_MANGLE(a) #a libavutil/x86/asm.h:#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
As long as EXTERN_PREFIX is "_" as it should be on Windows, these two lines above should produce _exactly_ the same string.
On Sat, Dec 28, 2013 at 03:23:51PM +0100, Reimar Döffinger wrote:
- __asm__ ("cltd \n\t" \ + __asm__ ("cdq \n\t" \
This one will break Solaris for example.
- "pand "MANGLE(mask0010)", %%mm0 \n" /* -- -- -- -- G1 B1 -- -- */\ + "pand "#_mask0010", %%mm0 \n" /* -- -- -- -- G1 B1 -- -- */\
This one should have told you that ICC doesn't have a problem with the symbols but that MANGLE isn't working right.
Sorry, I quoted badly. The _mask0010 is a macro argument after the patch, so my comment/conclusion doesn't apply.
libavutil/x86/asm.h:# define LOCAL_MANGLE(a) #a "(%%rip)" libavutil/x86/asm.h:# define LOCAL_MANGLE(a) #a libavutil/x86/asm.h:#define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a)
As long as EXTERN_PREFIX is "_" as it should be on Windows, these two lines above should produce _exactly_ the same string. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
On Sat, Dec 28, 2013 at 03:23:51PM +0100, Reimar Döffinger wrote:
- __asm__ ("cltd \n\t" \ + __asm__ ("cdq \n\t" \
This one will break Solaris for example.
have you tested this ? i get no error when compiling asm cdq on opensolaris [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB When you are offended at any man's fault, turn to yourself and study your own failings. Then you will forget your anger. -- Epictetus
On Sat, Mar 29, 2014 at 01:58:01PM +0100, Michael Niedermayer wrote:
On Sat, Dec 28, 2013 at 03:23:51PM +0100, Reimar Döffinger wrote:
- __asm__ ("cltd \n\t" \ + __asm__ ("cdq \n\t" \
This one will break Solaris for example.
have you tested this ?
i get no error when compiling asm cdq on opensolaris
Not recently, it's a bit hard to get my hands on. Note that I mean using suncc on Solaris, in case you only tested gcc.
On Sat, Mar 29, 2014 at 02:14:00PM +0100, Reimar Döffinger wrote:
On Sat, Mar 29, 2014 at 01:58:01PM +0100, Michael Niedermayer wrote:
On Sat, Dec 28, 2013 at 03:23:51PM +0100, Reimar Döffinger wrote:
- __asm__ ("cltd \n\t" \ + __asm__ ("cdq \n\t" \
This one will break Solaris for example.
have you tested this ?
i get no error when compiling asm cdq on opensolaris
Not recently, it's a bit hard to get my hands on. Note that I mean using suncc on Solaris, in case you only tested gcc.
i tried both but i havnt checked what they generated version is Sun Ceres C 5.10 SunOS_i386 2009/03/06 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have never wished to cater to the crowd; for what I know they do not approve, and what they approve I do not know. -- Epicurus
On Sat, Mar 29, 2014 at 02:30:05PM +0100, Michael Niedermayer wrote:
On Sat, Mar 29, 2014 at 02:14:00PM +0100, Reimar Döffinger wrote:
On Sat, Mar 29, 2014 at 01:58:01PM +0100, Michael Niedermayer wrote:
On Sat, Dec 28, 2013 at 03:23:51PM +0100, Reimar Döffinger wrote:
- __asm__ ("cltd \n\t" \ + __asm__ ("cdq \n\t" \
This one will break Solaris for example.
have you tested this ?
i get no error when compiling asm cdq on opensolaris
Not recently, it's a bit hard to get my hands on. Note that I mean using suncc on Solaris, in case you only tested gcc.
i tried both but i havnt checked what they generated
version is Sun Ceres C 5.10 SunOS_i386 2009/03/06
Strange. Seems they must have fixed it shortly after my tests (and it's actually/of course binutils that causes the issues, not the compiler). See: http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2008-February/046323.html Though maybe it's reasonable to just change it back then.
have you tested this ? i get no error when compiling asm cdq on opensolaris
cdq works fine for me with icl and gcc but I dont have access to suncc so its beyond my testing capabilities. What I can confirm is that cltd is not supported by icl. 2 instructions instead of 1 increase pressure on the code cache
and codecs like h264 are complex enough so the code cache size should have signifiant effects
That depends on the hardware, modern processors have a 2 uop version of CDQ so for processors that cache at the uop level its already 2 instructions. did you benchmark this ? Generated some random data and then ran a few thousand loops over get_cabac_bypass_sign. It was a quick test but didnt show any real world difference (outside of random testing variation). That said I only tested it on my pc which is one of those with a 2 clock cycle cdq and a uop cache so it may be different on others. i tried both but i havnt checked what they generated Of course if cdq is actually supported then I guess all the changes are somewhat moot.
On Sun, Mar 30, 2014 at 12:38:14AM +1100, Matt Oliver wrote:
have you tested this ? i get no error when compiling asm cdq on opensolaris
cdq works fine for me with icl and gcc but I dont have access to suncc so its beyond my testing capabilities. What I can confirm is that cltd is not supported by icl.
2 instructions instead of 1 increase pressure on the code cache
and codecs like h264 are complex enough so the code cache size should have signifiant effects
That depends on the hardware, modern processors have a 2 uop version of CDQ so for processors that cache at the uop level its already 2 instructions.
did you benchmark this ?
Generated some random data and then ran a few thousand loops over get_cabac_bypass_sign. It was a quick test but didnt show any real world difference (outside of random testing variation). That said I only tested it on my pc which is one of those with a 2 clock cycle cdq and a uop cache so it may be different on others.
did you read what i wrote ? ;) its the pressure on the code cache that might make a longer version slower, running thousands of loops over the trivial function wont have this effect. It needs to be inside h264*.c or another more complex decoder for this to be benchmarkable not sure maybe cachegrind could be used but possibly the point is moot if simply switching to cdq would be an option [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB What does censorship reveal? It reveals fear. -- Julian Assange
participants (7)
-
Carl Eugen Hoyos -
Christophe Gisquet -
Hendrik Leppkes -
Matt Oliver -
Michael Niedermayer -
Reimar Döffinger -
Ronald S. Bultje