[cfe-dev] clang vector_size attribute compatibilty with gcc on x86

SENTHIL KUMAR THANGAVELU senthil.t at samsung.com
Wed Jan 9 06:24:21 PST 2013


Using the linux calling convention.

clang -v c.c
clang version 3.1 (branches/release_31)
Target: i386-pc-linux-gnu
Thread model: posix
 "/usr/local/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name c.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.20.51 -momit-leaf-frame-pointer -v -resource-dir /usr/local/bin/../lib/clang/3.1 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.1/include -internal-isystem /usr/lib/gcc/i686-linux-gnu/4.5/../../../gcc/i686-linux-gnu/4.5/include -internal-isystem /usr/lib/gcc/i686-linux-gnu/4.5/../../../gcc/i686-linux-gnu/4.5/include-fixed -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/camel/test/v2 -ferror-limit 19 -fmessage-length 205 -mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/c-MO7OKC.o -x c c.c
clang -cc1 version 3.1 based upon LLVM 3.1 default target i386-pc-linux-gnu

------- Original Message -------
Sender : David Chisnall<David.Chisnall at cl.cam.ac.uk>
Date : Jan 09, 2013 23:18 (GMT+09:00)
Title : Re: [cfe-dev] clang vector_size attribute compatibilty with gcc on x86

What platform are you using?  Clang has (at least) two calling conventions for passing vectors on x86 as, for example, Darwin and Linux differ in how they do this.

David

On 9 Jan 2013, at 14:06, SENTHIL KUMAR THANGAVELU wrote:

> 
> Hello all,
> I have attached the test case for which variable with attribute vector_size when passed by value from clang to gcc or vice versa is causing compatibility issue. Incase of clang  for vector_size attr, SIMD instructions are emitted as follows
> movaps -0x18(%ebp),%xmm0
> movdqa %xmm0,-0x28(%ebp)
> clang sends vector data by value, using vector registers, in the above case xmm0. gcc always uses stack to pass vector data by value for vector_size attr vars (even with -O3). clang and gcc don't understand each other's calling convention when vector by value is passed to functions. 
> To preserve compatibility one solution is to compile clang without SIMD using flags like "-mno-mmx -mno-sse" to pass vector value completely on stack. Still the calling conventions between clang and gcc don't agree. When clang passes vector completely on stack for char sized items clang writes consecutive vector bytes in non contiguous locations on stack. For e.g to pass a vector of char like 0xab 0xcd clang will write in stack as 
>  Address X  : 0xab 00 00 00
>           X+4: 0xcd 00 00 00
>  Whereas gcc will expect from clang the same data arranged as Address X  : 0xab 0xcd . Looks like clang sends char data with 3 byte padding for speeding up reads as word read instruction. Also forcing no SIMD is meaningless for vector_size attr.
> 
>  What is the good approach to achieve compatibility between gcc and clang when vector_size is used?
> 
>  PS: attachment has compile.sh compilation steps used. Also test case was simplified from gcc compatibility tests. Tests were done on 32 bit ubuntu X86, gcc version 4.4.5.
> 
> Regards
> Senthil Kumar_______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




Regards
Senthil Kumar




More information about the cfe-dev mailing list