[LLVMdev] calling c-function with a vector
Nick Lewycky
nicholas at mxc.ca
Thu Nov 25 14:29:14 PST 2010
Jörg Werner wrote:
> Hi all,
>
> I have the following problem: I want to call a function from llvm
> (tryf in the following) which takes a vector as an argument. The
> function tryf is a c-function and should output the whole vector. But
> I only get 0.0. Looks like a problem with how the arguments are
> passed. I havn't found anything in the docs about how vectors are
> passed. Any help would be appreciated.
>
> The llvm-code looks like this:
> declare void @tryf(<4 x float>)
> define i32 @main() {
> entry:
> call void @tryf(<4 x float> <float 0x3FFB0A3D40000000, float
> 6.250000e+00, float 0x3F847AE160000000, float 1.600000e+01>)
> ret i32 3
> }
>
> The C-function is defined like this:
> #include<stdio.h>
> void tryf(float *a1)
That's not a vector. That's a pointer to a float. Assuming you're using
clang, try this:
#include <stdio.h>
typedef float float4 __attribute__((ext_vector_type(4)));
void tryf(float4 a1) {
fprintf(stderr, "%f %f %f %f\n", a1.x, a1.y, a1.z, a1.w);
}
There's also a syntax for this with gcc using 'vector_size' instead of
'ext_vector_type' but I don't know it offhand.
Nick
More information about the llvm-dev
mailing list