// This test exercises various optimziations in the backend lowering code
int main(void)
{
    // Splat from first vector
    printf("\ntest 1: ");
    printVector(__builtin_shufflevector(VECA, VECB, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));
        // CHECK: test 1: 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38

    // Splat from second vector
    printf("\ntest 2: ");
    printVector(__builtin_shufflevector(VECA, VECB, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17));
        // CHECK: test 2: 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54

    // Copy first vector
    printf("\ntest 3: ");
    printVector(__builtin_shufflevector(VECA, VECB, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
        // CHECK: test 3: 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

    // Copy second vector
    printf("\ntest 4: ");
    printVector(__builtin_shufflevector(VECA, VECB, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31));
        // CHECK: test 4: 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

    // Identity shuffle, converts to masked move
    printf("\ntest 5: ");
    printVector(__builtin_shufflevector(VECA, VECB, 0, 17, 2, 19, 4, 21, 6, 23, 8, 25, 10, 27, 12, 29, 14, 31));
        // CHECK: test 5: 37 54 39 56 41 58 43 60 45 62 47 64 49 66 51 68

    // Shuffle first vector only
    printf("\ntest 6: ");
    printVector(__builtin_shufflevector(VECA, VECB, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
        // CHECK: test 6: 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37

    // Shuffle second vector only
    printf("\ntest 7: ");
    printVector(__builtin_shufflevector(VECA, VECB, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16));
        // CHECK: test 7: 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53

    // Shuffle and mix both vectors
    printf("\ntest 8: ");
    printVector(__builtin_shufflevector(VECA, VECB, 31, 14, 29, 12, 27, 10, 25, 8, 23, 6, 21, 4, 19, 2, 17, 0));
        // CHECK: test 8: 68 51 66 49 64 47 62 45 60 43 58 41 56 39 54 37

    // Same vector is passed for both params
    printf("\ntest 9: ");
    printVector(__builtin_shufflevector(VECA, VECA, 31, 14, 29, 12, 27, 10, 25, 8, 23, 6, 21, 4, 19, 2, 17, 0));
        // CHECK: test 9: 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37
}
예제 #2
0
void axpby(float alpha, float *x, float beta, float *y, int N) {
	// y = a * x + b * y
	int i=0;
	float4 scl = {alpha, alpha, beta, beta};
	for (i = 0; i < N; i += 2) {
		// y[i] = alpha * x[i] + beta * y[i];
		float4 v = {x[i], x[i+1], y[i], y[i+1]};
		// multiply by scalars
		float4 w = scl * v; 

		v = __builtin_shufflevector(w, w, 2, 3, 0, 1); // v = {y1, y2, x1, x2}

		v = v + w;

		y[i] = v[0];
		y[i+1] = v[1];
		// y[i+1] = alpha * x[i+1] + beta * y[i+1];
	}
}
예제 #3
0
// CHECK-LABEL: define void @clang_shufflevector_v_v(
void clang_shufflevector_v_v( float4* A, float4 x, uint4 mask ) {
// CHECK: [[MASK:%.*]] = and <4 x i32> {{%.*}}, <i32 3, i32 3, i32 3, i32 3>
// CHECK: [[I:%.*]] = extractelement <4 x i32> [[MASK]], i32 0
// CHECK: [[E:%.*]] = extractelement <4 x float> [[X:%.*]], i32 [[I]]
//
// Here is where ToT Clang code generation makes a mistake.  
// It uses [[I]] as the insertion index instead of 0.
// Similarly on the remaining insertelement.
// CHECK: [[V:%[a-zA-Z0-9._]+]] = insertelement <4 x float> undef, float [[E]], i32 0

// CHECK: [[I:%.*]] = extractelement <4 x i32> [[MASK]], i32 1
// CHECK: [[E:%.*]] = extractelement <4 x float> [[X]], i32 [[I]]
// CHECK: [[V2:%.*]] = insertelement <4 x float> [[V]], float [[E]], i32 1
// CHECK: [[I:%.*]] = extractelement <4 x i32> [[MASK]], i32 2
// CHECK: [[E:%.*]] = extractelement <4 x float> [[X]], i32 [[I]]
// CHECK: [[V3:%.*]] = insertelement <4 x float> [[V2]], float [[E]], i32 2
// CHECK: [[I:%.*]] = extractelement <4 x i32> [[MASK]], i32 3
// CHECK: [[E:%.*]] = extractelement <4 x float> [[X]], i32 [[I]]
// CHECK: [[V4:%.*]] = insertelement <4 x float> [[V3]], float [[E]], i32 3
// CHECK: store <4 x float> [[V4]], <4 x float>* {{%.*}},
  *A = __builtin_shufflevector( x, mask );
}
예제 #4
0
v4si a(v4si x, v4si y) {return __builtin_shufflevector(x, y, 3, 2, 5, 7);}
예제 #5
0
// CHECK-LABEL: define void @clang_shufflevector_v_v_undef(
void clang_shufflevector_v_v_undef( float4* A, float4 x, float4 y) {
// CHECK: [[V:%.*]] = shufflevector <4 x float> {{%.*}}, <4 x float> {{%.*}}, <4 x i32> <i32 0, i32 4, i32 undef, i32 5>
// CHECK: store <4 x float> [[V]], <4 x float>* {{%.*}}
  *A = __builtin_shufflevector( x, y, 0, 4, -1, 5 );
}
 void f(T t, U u, double2 a, double2 b) {
   (void)__builtin_shufflevector(t, u, N, M); // expected-error{{index}}
   (void)__builtin_shufflevector(a, b, N, M);
   (void)__builtin_shufflevector(a, b, 2, 1);
 }