• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/perl -w
2
3# Generate trivial test cases to exercise input types.
4
5use strict;
6
7my @basicTypes = ("half", "float", "double",
8                  "char", "short", "int", "long",
9                  "uchar", "ushort", "uint", "ulong",
10                  "bool",
11                  "rs_matrix2x2", "rs_matrix3x3", "rs_matrix4x4",
12                  "MyStruct");
13
14my @specialParameters = ("context", "x", "y", "z");
15my $specialParameterPowerSetCardinality = 2 ** (1 + $#specialParameters);
16
17# 1 signifies non-vector
18# 3 is not supported for exported types
19my @vecLengths = (1, 2, 4);
20
21print "// -Wall -Werror\n";
22print "#pragma version(1)\n";
23print "#pragma rs java_package_name(input)\n\n";
24print "// This test case was created by $0.\n";
25print "// It exercises various legal combinations of inputs and special parameters,\n";
26print "//  so that we can ensure\n";
27print "// (a) We do not choke when compiling them\n";
28print "// (b) We reflect them correctly\n\n";
29print "// One example struct type\n";
30print "typedef struct MyStruct { float f; double d; } MyStruct;\n\n";
31print "// Trivial combiner shared by all test cases\n";
32print "static void combiner(int *accum, const int *other) { }\n";
33
34foreach my $basicType (@basicTypes) {
35  foreach my $vecLen (@vecLengths) {
36
37    # There are no bool vectors or struct vectors
38    next if ($vecLen > 1) && (($basicType eq "bool") || ($basicType eq "MyStruct"));
39
40    # There are no matrix or object vectors
41    next if ($vecLen > 1) && (substr($basicType, 0, 3) eq "rs_");
42
43    my $eltName = $basicType;
44    $eltName .= $vecLen if ($vecLen > 1);
45
46    for (my $specials = 0; $specials < $specialParameterPowerSetCardinality; ++$specials) {
47      my $reduceName = "my_${eltName}_${specials}";
48      my $accumName = "${reduceName}_accum";
49      print "\n";
50      print "#pragma rs reduce(${reduceName}) accumulator(${accumName}) combiner(combiner)\n";
51      print "static void ${accumName}(int *accum, ${eltName} in";
52      for (my $special = 0; $special <= $#specialParameters; ++$special) {
53        if ($specials & 2**$special) {
54          print ", " . ($special ? "uint" : "rs_kernel_context") . " ${specialParameters[$special]}";
55        }
56      }
57      print ") { }\n";
58    }
59  }
60}
61