[cairo] Problem compiling pixman-sse.c under Win32, blame it on MSVC !!
Vladimir Vukicevic
vladimir at pobox.com
Mon Aug 18 15:37:23 PDT 2008
Not sure if this got sent to the cairo list -- Soeren, does this patch
from Andre reasonable? It looks fine here.
- Vlad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pixman-win32.patch
Type: text/x-patch
Size: 44951 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20080818/b554604f/attachment-0001.bin
-------------- next part --------------
On Aug 13, 2008, at 4:14 AM, Andr? Tupinamb? wrote:
> Hi Vlad,
>
> Check the patch in attach.
>
> []'s
> Andr?
>
> On Fri, Aug 8, 2008 at 10:43 PM, Vladimir Vukicevic <vladimir at pobox.com
> > wrote:
>>
>> No worries, thanks for taking a look! If the pixman-sse.c you
>> attached is
>> good to go, I can push it upstream if you'd like (with Soeren's
>> permission
>> -- not sure if you have commit access).
>>
>> - Vlad
>>
>> On Aug 8, 2008, at 3:23 PM, Andr? Tupinamb? wrote:
>>
>>> Hi Vlad,
>>>
>>> Well I know, I'm little late ;)
>>> Sometimes I get so busy (job + free-lances) to work with pixman,
>>> but I
>>> finnished the tests.
>>>
>>> The perf tests ran ok, so we can use this modifications, but I found
>>> some bugs in the implementation. See the pixman-sse.c file in
>>> attach.
>>>
>>> Regards,
>>>
>>> Andr? Tupinamb?
>>>
>>>
>>> On Thu, Aug 7, 2008 at 1:55 PM, Vladimir Vukicevic <vladimir at pobox.com
>>> >
>>> wrote:
>>>>
>>>> Hey Andre,
>>>>
>>>> Have you had a chance to take a look at this yet? I'd like to
>>>> get the
>>>> speed
>>>> boost on win32 at least, still have some stack alignment issues
>>>> to fix on
>>>> our end for linux.
>>>>
>>>> - Vlad
>>>>
>>>> On Jul 21, 2008, at 6:48 PM, Andr? Tupinamb? wrote:
>>>>
>>>>> Yes, It's a really possible, but I'll test it first and check the
>>>>> generated assembly (in GCC and MSVC).
>>>>>
>>>>> If we had some slowdowns or poor compiler optimization, I will
>>>>> try to
>>>>> change the inline functions to defines.
>>>>>
>>>>> Regards,
>>>>>
>>>>> Andr? Tupinamb?
>>>>>
>>>>>
>>>>> On Mon, Jul 21, 2008 at 10:05 PM, Rodrigo Kumpera <kumpera at gmail.com
>>>>> >
>>>>> wrote:
>>>>>>
>>>>>> Since most of these functions force inlining, argument passing by
>>>>>> pointer
>>>>>> or
>>>>>> by value
>>>>>> should not matter, modulo compiler inability to do the right
>>>>>> thing.
>>>>>>
>>>>>> I think that there are no issues from changing some args from
>>>>>> values to
>>>>>> regs
>>>>>> as long as GCC still manages to generate decent code. From what I
>>>>>> recall,
>>>>>> this is not
>>>>>> the case and some reasonable recent version of it should do the
>>>>>> trick.
>>>>>>
>>>>>> Fr?d?ric, do you mind testing that for gcc?
>>>>>>
>>>>>> Thanks,
>>>>>> Rodrigo
>>>>>>
>>>>>> On Mon, Jul 21, 2008 at 6:19 AM, Antoine Azar <cairo at antoineazar.com
>>>>>> >
>>>>>> wrote:
>>>>>>>
>>>>>>> Yep, I've tried everything on my side (playing with compiler
>>>>>>> switches,
>>>>>>> setting the function parameters as const references, wrapping in
>>>>>>> structs,
>>>>>>> changing stack size, etc) and didn't have more luck than Fred.
>>>>>>>
>>>>>>> VC++ always borks starting the fourth __m128i parameter only.
>>>>>>> The
>>>>>>> three
>>>>>>> first ones are always ok. It seems this is a limitation of VC+
>>>>>>> +, that
>>>>>>> it'll
>>>>>>> only handle a "pass by register" of up to three SSE
>>>>>>> intrinsics, and
>>>>>>> not
>>>>>>> one
>>>>>>> more.
>>>>>>>
>>>>>>> I don't think sending pointers would be much of an issue: this
>>>>>>> is
>>>>>>> already
>>>>>>> done at many other places in the code, and it'll avoid the
>>>>>>> overhead of
>>>>>>> passing by value 16 byte data structures.
>>>>>>> Otherwise, we can try rewriting functions so they always use
>>>>>>> at most 3
>>>>>>> SSE
>>>>>>> intrinsics that are passed by value, but that might be a pain.
>>>>>>>
>>>>>>> I'd be curious to see how the Intel Compiler handles this.
>>>>>>>
>>>>>>> Antoine
>>>>>>>
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: cairo-bounces at cairographics.org
>>>>>>>> [mailto:cairo-bounces at cairographics.org] On Behalf Of Fr?d?ric
>>>>>>>> Plourde
>>>>>>>> Sent: Sunday, July 20, 2008 10:03 PM
>>>>>>>> To: cairo at cairographics.org
>>>>>>>> Subject: [cairo] Problem compiling pixman-sse.c under
>>>>>>>> Win32,blame it on MSVC !!
>>>>>>>>
>>>>>>>> Hi !
>>>>>>>>
>>>>>>>> Vlad had emailled me with this problem compiling pixman
>>>>>>>> sith SSE2 stuff enabled.
>>>>>>>> In fact, here are the errors that we got :
>>>>>>>>
>>>>>>>> pixman-sse.c
>>>>>>>> pixman-sse.c(142) : error C2719: 'xmm3': formal parameter with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(195) : error C2719: 'alphaHi': formal parameter
>>>>>>>> with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(210) : error C2719: 'alphaDstHi': formal
>>>>>>>> parameter with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(210) : error C2719: 'dstLo': formal parameter with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(210) : error C2719: 'dstHi': formal parameter with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(210) : error C2719: 'alphaSrcLo': formal
>>>>>>>> parameter with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(210) : error C2719: 'alphaSrcHi': formal
>>>>>>>> parameter with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(246) : error C2719: 'alphaHi': formal parameter
>>>>>>>> with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(276) : error C2719: 'alphaHi': formal parameter
>>>>>>>> with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(276) : error C2719: 'maskLo': formal parameter
>>>>>>>> with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(276) : error C2719: 'maskHi': formal parameter
>>>>>>>> with
>>>>>>>> __declspec(align('16')) won't be aligned
>>>>>>>> pixman-sse.c(290) : warning C4133: 'function' : incompatible
>>>>>>>> types - from '__m128i *' to 'const char *'
>>>>>>>> pixman-sse.c(296) : warning C4133: 'function' : incompatible
>>>>>>>> types - from '__m128i *' to 'const char *'
>>>>>>>> pixman-sse.c(371) : error C2719: 'alphaSrc': formal parameter
>>>>>>>> with
>>>>>>>> __declspec(align('8')) won't be aligned
>>>>>>>> pixman-sse.c(398) : error C2719: 'dst': formal parameter with
>>>>>>>> __declspec(align('8')) won't be aligned
>>>>>>>> pixman-sse.c(4432) : error C2275: '__m128i' : illegal use of
>>>>>>>> this type as an expression
>>>>>>>> D:\msvs8\VC\INCLUDE\emmintrin.h(45) : see declaration
>>>>>>>> of '__m128i'
>>>>>>>> pixman-sse.c(4432) : error C2146: syntax error : missing ';'
>>>>>>>> before identifier 'xmm0'
>>>>>>>> pixman-sse.c(4432) : error C2065: 'xmm0' : undeclared
>>>>>>>> identifier
>>>>>>>> pixman-sse.c(4432) : error C2065: 'xmm1' : undeclared
>>>>>>>> identifier
>>>>>>>> pixman-sse.c(4432) : error C2065: 'xmm2' : undeclared
>>>>>>>> identifier
>>>>>>>> pixman-sse.c(4432) : error C2065: 'xmm3' : undeclared
>>>>>>>> identifier
>>>>>>>> pixman-sse.c(4434) : error C2440: '=' : cannot convert from
>>>>>>>> '__m128i' to 'int'
>>>>>>>> pixman-sse.c(4435) : error C2440: '=' : cannot convert from
>>>>>>>> '__m128i' to 'int'
>>>>>>>> pixman-sse.c(4436) : error C2440: '=' : cannot convert from
>>>>>>>> '__m128i' to 'int'
>>>>>>>> pixman-sse.c(4437) : error C2440: '=' : cannot convert from
>>>>>>>> '__m128i' to 'int'
>>>>>>>> pixman-sse.c(4439) : error C2440: 'function' : cannot convert
>>>>>>>> from 'int'
>>>>>>>> to '__m128i'
>>>>>>>> pixman-sse.c(4439) : warning C4024: 'save128Aligned' :
>>>>>>>> different types for formal and actual parameter 2
>>>>>>>> pixman-sse.c(4440) : error C2440: 'function' : cannot convert
>>>>>>>> from 'int'
>>>>>>>> to '__m128i'
>>>>>>>> pixman-sse.c(4440) : warning C4024: 'save128Aligned' :
>>>>>>>> different types for formal and actual parameter 2
>>>>>>>> pixman-sse.c(4441) : error C2440: 'function' : cannot convert
>>>>>>>> from 'int'
>>>>>>>> to '__m128i'
>>>>>>>> pixman-sse.c(4441) : warning C4024: 'save128Aligned' :
>>>>>>>> different types for formal and actual parameter 2
>>>>>>>> pixman-sse.c(4442) : error C2440: 'function' : cannot convert
>>>>>>>> from 'int'
>>>>>>>> to '__m128i'
>>>>>>>> pixman-sse.c(4442) : warning C4024: 'save128Aligned' :
>>>>>>>> different types for formal and actual parameter 2
>>>>>>>>
>>>>>>>>
>>>>>>>> We found the following :
>>>>>>>>
>>>>>>>>
>>>>>>>> for every C2719 errors, the solution is to avoid passing
>>>>>>>> __m128i values directly, because MSVC just doesn't allow
>>>>>>>> function parameters to be of types declared with the
>>>>>>>> "__declspec(align('#'))" modifier (this is the case of
>>>>>>>> __m128i). See:
>>>>>>>> http://msdn.microsoft.com/en-us/library/373ak2y1(VS.80).aspx
>>>>>>>>
>>>>>>>> More problematic is the behaviour of MSVC under these
>>>>>>>> assumptions... in fact, try removing ONLY the xmm3 function
>>>>>>>> parameter at line #142 in pixman-sse.c (and by commenting
>>>>>>>> references to xmm3 inside the function, of course), it will
>>>>>>>> compile. (!!). I've went through different forums for
>>>>>>>> developpers and it seems there are still some bugs with those
>>>>>>>> intrinsics in MSVC8. Very dissapointing!
>>>>>>>>
>>>>>>>> So my recommandation to misters Tupinamba and Kumpera would
>>>>>>>> be to pass POINTERS to those function parameters instead...
>>>>>>>> as :
>>>>>>>>
>>>>>>>> static inline __m128i
>>>>>>>> pack565_4x128_128 (__m128i *xmm0, __m128i *xmm1, __m128i
>>>>>>>> *xmm2, __m128i *xmm3) {
>>>>>>>> __m128i lo, hi;
>>>>>>>>
>>>>>>>> lo = _mm_packus_epi16 (pack565_2x128_128 ( *xmm0, *xmm1 ),
>>>>>>>> _mm_setzero_si128 ());
>>>>>>>> hi = _mm_packus_epi16 (_mm_setzero_si128 (),
>>>>>>>> pack565_2x128_128 ( *xmm2, *xmm3 ));
>>>>>>>>
>>>>>>>> return _mm_or_si128 (lo, hi);
>>>>>>>> }
>>>>>>>>
>>>>>>>> compiles perfectly.
>>>>>>>> However, this would maybe imply significant impacts on
>>>>>>>> performance... it should be addressed and profiled..
>>>>>>>>
>>>>>>>>
>>>>>>>> ******
>>>>>>>> Besides, for the C2275 error, it's even more embarassing for
>>>>>>>> microsoft... it's another case of MSVC being very capricious.
>>>>>>>> In some cases, with aligned variables, MSVC doesn't allow us
>>>>>>>> to declare
>>>>>>>> those variable in the middle of the function... We then need
>>>>>>>> to move the
>>>>>>>> declaration earlier.
>>>>>>>> see, at line 4432,
>>>>>>>>
>>>>>>>> __m128i xmm0, xmm1, xmm2, xmm3; needs to be moved up a
>>>>>>>> little... as :
>>>>>>>>
>>>>>>>> while (w >= 64)
>>>>>>>> {
>>>>>>>> __m128i xmm0, xmm1, xmm2, xmm3;
>>>>>>>>
>>>>>>>> /* 128 bytes ahead */
>>>>>>>> cachePrefetch (((__m128i*)s) + 8);
>>>>>>>> cachePrefetch (((__m128i*)d) + 8);
>>>>>>>>
>>>>>>>> compiles now...
>>>>>>>> ****************
>>>>>>>>
>>>>>>>> So here it is... a patch with those changes in pixman-sse.c
>>>>>>>> I'd like you guys (especcially Andr?) to look that over and
>>>>>>>> tell me what
>>>>>>>> you think. It's a first draft, but it compiles under all 3
>>>>>>>> major platforms.
>>>>>>>>
>>>>>>>> Best,
>>>>>>>> -fred-
>>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> cairo mailing list
>>>>>>> cairo at cairographics.org
>>>>>>> http://lists.cairographics.org/mailman/listinfo/cairo
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> cairo mailing list
>>>>>> cairo at cairographics.org
>>>>>> http://lists.cairographics.org/mailman/listinfo/cairo
>>>>>>
>>>>> _______________________________________________
>>>>> cairo mailing list
>>>>> cairo at cairographics.org
>>>>> http://lists.cairographics.org/mailman/listinfo/cairo
>>>>
>>>>
>>> <pixman-sse.c>
>>
>>
> <pixman-win32.patch>
More information about the cairo
mailing list