Changes between Version 3 and Version 4 of SIMDVectorExampleInLLVM
- Timestamp:
- 10/25/11 10:57:14 (19 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
SIMDVectorExampleInLLVM
v3 v4 9 9 To demonstrate the vector instructions, we can start with a basic C program (just to illustrate ... remember, LLVM is not functional so starting in an imperative language makes a lot of sense): 10 10 {{{ 11 #include <stdio.h> 12 11 13 int main() 12 14 { … … 24 26 z[1] = x[1] + y[1]; 25 27 z[2] = x[2] + y[2]; 26 z[3] = x[3] + y[3]; 27 } 28 z[3] = x[3] + y[3]; 29 printf("%f %f %f %f\n", z[0], z[1], z[2], z[3]); 30 } 28 31 }}} 29 32 … … 32 35 This converts easily to LLVM human readable format (use the [http://llvm.org/demo/index.cgi online generator] if you'd like): 33 36 {{{ 34 ; ModuleID = '/tmp/webcompile/_2 0751_0.bc'37 ; ModuleID = '/tmp/webcompile/_21191_0.bc' 35 38 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" 36 39 target triple = "x86_64-unknown-linux-gnu" 40 41 @.str = private unnamed_addr constant [13 x i8] c"%f %f %f %f\0A\00" 37 42 38 43 define i32 @main() nounwind { … … 86 91 %33 = getelementptr inbounds [4 x float]* %z, i32 0, i64 3 87 92 store float %32, float* %33 88 %34 = load i32* %1 89 ret i32 %34 93 %34 = getelementptr inbounds [4 x float]* %z, i32 0, i64 0 94 %35 = load float* %34 95 %36 = fpext float %35 to double 96 %37 = getelementptr inbounds [4 x float]* %z, i32 0, i64 1 97 %38 = load float* %37 98 %39 = fpext float %38 to double 99 %40 = getelementptr inbounds [4 x float]* %z, i32 0, i64 2 100 %41 = load float* %40 101 %42 = fpext float %41 to double 102 %43 = getelementptr inbounds [4 x float]* %z, i32 0, i64 3 103 %44 = load float* %43 104 %45 = fpext float %44 to double 105 %46 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @.str, i32 0, i32 0), double %36, double %39, double %42, double %45) 106 %47 = load i32* %1 107 ret i32 %47 90 108 } 109 110 declare i32 @printf(i8*, ...) 91 111 }}} 92 112
