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

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


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v2.tar.gz
Type: application/octet-stream
Size: 973 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130109/3bb7640a/attachment.obj>


More information about the cfe-dev mailing list