Home | History | Annotate | Download | only in P_reduce_general_accumulator
      1 #!/usr/bin/perl -w
      2 
      3 # Generate trivial test cases to exercise accumulator types.
      4 
      5 use strict;
      6 
      7 my @basicTypesVectorable = ("half", "float", "double",
      8                             "char", "short", "int", "long",
      9                             "uchar", "ushort", "uint", "ulong");
     10 my @basicTypesUnvectorable = ("bool",
     11                               "rs_matrix2x2", "rs_matrix3x3", "rs_matrix4x4",
     12                               "rs_for_each_strategy_t", "rs_script_call_t", "rs_time_t", "rs_tm",
     13                               "MyEnum",
     14                               "MyPtrArray", "MyPtrFn", "MyPtrIncomplete", "MyPtrShort", "MyPtrVoid",
     15                               "MyStruct", "MyUnion",
     16                               "MyBlob");
     17 my @basicTypes = (@basicTypesVectorable, @basicTypesUnvectorable);
     18 
     19 # 1 signifies non-vector
     20 # 3 is not supported for exported types
     21 my @vecLengths = (1, 2, 4);
     22 
     23 print "// -target-api 0 -Wall -Werror\n";
     24 print "#pragma version(1)\n";
     25 print "#pragma rs java_package_name(accumulator)\n\n";
     26 print "// This test case was created by $0.\n";
     27 print "// It exercises various legal accumulator types, so that we can ensure\n";
     28 print "// (a) We do not choke when compiling them\n";
     29 print "// (b) They do not inhibit reflection\n";
     30 print "\n// One example enum type\n";
     31 print "typedef enum { E1, E2, E3 } MyEnum;\n";
     32 print "\n// Example pointer types\n";
     33 print "typedef float (*MyPtrArray)[3][11];\n";
     34 print "typedef int (*MyPtrFn)(double);\n";
     35 print "typedef struct Incomplete *MyPtrIncomplete;\n";
     36 print "typedef volatile short *MyPtrShort;\n";
     37 print "typedef const void *MyPtrVoid;\n";
     38 print "\n// One example struct type\n";
     39 print "typedef struct { float f; double d; char *c; } MyStruct;\n";
     40 print "\n// One example union type\n";
     41 print "typedef union { int i; long l; int a[5]; } MyUnion;\n";
     42 print "\n// One example of a more-complicated type\n";
     43 print "typedef struct { MyEnum e1, e2; MyPtrIncomplete p; MyStruct s; MyUnion u; } MyBlob;\n";
     44 
     45 foreach my $basicType (@basicTypes) {
     46   for (my $isArray = 0; $isArray <= 1; ++$isArray) {
     47     foreach my $vecLen (@vecLengths) {
     48 
     49       next if ($vecLen > 1) && !grep(/^${basicType}$/, @basicTypesVectorable);
     50 
     51       my $eltName = $basicType;
     52       $eltName .= $vecLen if ($vecLen > 1);
     53       my $resultName = ($isArray ? "array_${eltName}" : $eltName);
     54       my $reduceName = "my_${resultName}";
     55       my $accumName = "${reduceName}_accum";
     56       my $combName = "${reduceName}_comb";
     57       my $outName = "${reduceName}_out";
     58       print "\n";
     59       print "#pragma rs reduce(${reduceName}) accumulator(${accumName}) combiner(${combName}) outconverter(${outName})\n";
     60       print "typedef ${eltName} ${resultName}[7];\n" if ($isArray);
     61       print "static void ${accumName}(${resultName} *accum, int val) { }\n";
     62       print "static void ${combName}(${resultName} *accum, const ${resultName} *other) { }\n";
     63       print "static void ${outName}(int *out, const ${resultName} *accum) { }\n";
     64     }
     65   }
     66 }
     67