Changes between Version 3 and Version 4 of SIMDVectorExampleInLLVM


Ignore:
Timestamp:
Oct 25, 2011 5:57:14 PM (2 years ago)
Author:
pmonday
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SIMDVectorExampleInLLVM

    v3 v4  
    99To 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): 
    1010{{{ 
     11#include <stdio.h> 
     12 
    1113int main() 
    1214{ 
     
    2426   z[1] = x[1] + y[1];  
    2527   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} 
    2831}}} 
    2932 
     
    3235This converts easily to LLVM human readable format (use the [http://llvm.org/demo/index.cgi online generator] if you'd like): 
    3336{{{ 
    34 ; ModuleID = '/tmp/webcompile/_20751_0.bc' 
     37; ModuleID = '/tmp/webcompile/_21191_0.bc' 
    3538target 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" 
    3639target triple = "x86_64-unknown-linux-gnu" 
     40 
     41@.str = private unnamed_addr constant [13 x i8] c"%f %f %f %f\0A\00" 
    3742 
    3843define i32 @main() nounwind { 
     
    8691  %33 = getelementptr inbounds [4 x float]* %z, i32 0, i64 3 
    8792  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 
    90108} 
     109 
     110declare i32 @printf(i8*, ...) 
    91111}}} 
    92112