1 #!/bin/bash
  2 #
  3 # Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5 #
  6 # This code is free software; you can redistribute it and/or modify it
  7 # under the terms of the GNU General Public License version 2 only, as
  8 # published by the Free Software Foundation.  Oracle designates this
  9 # particular file as subject to the "Classpath" exception as provided
 10 # by Oracle in the LICENSE file that accompanied this code.
 11 #
 12 # This code is distributed in the hope that it will be useful, but WITHOUT
 13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 15 # version 2 for more details (a copy is included in the LICENSE file that
 16 # accompanied this code).
 17 #
 18 # You should have received a copy of the GNU General Public License version
 19 # 2 along with this work; if not, write to the Free Software Foundation,
 20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 21 #
 22 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 23 # or visit www.oracle.com if you need additional information or have any
 24 # questions.
 25 #
 26 
 27 generate_perf_tests=$1
 28 
 29 TEMPLATE_FOLDER="templates/"
 30 
 31 unit_output="unit_tests.template"
 32 perf_output="perf_tests.template"
 33 perf_scalar_output="perf_scalar_tests.template"
 34 
 35 unary="Unary-op"
 36 unary_masked="Unary-Masked-op"
 37 unary_scalar="Unary-Scalar-op"
 38 ternary="Ternary-op"
 39 ternary_masked="Ternary-Masked-op"
 40 ternary_broadcast="Ternary-Broadcast-op"
 41 ternary_broadcast_masked="Ternary-Broadcast-Masked-op"
 42 ternary_double_broadcast="Ternary-Double-Broadcast-op"
 43 ternary_double_broadcast_masked="Ternary-Double-Broadcast-Masked-op"
 44 ternary_scalar="Ternary-Scalar-op"
 45 binary="Binary-op"
 46 binary_masked="Binary-Masked-op"
 47 binary_broadcast="Binary-Broadcast-op"
 48 binary_broadcast_masked="Binary-Broadcast-Masked-op"
 49 binary_broadcast_long="Binary-Broadcast-Long-op"
 50 binary_broadcast_masked_long="Binary-Broadcast-Masked-Long-op"
 51 binary_scalar="Binary-Scalar-op"
 52 blend="Blend-op"
 53 test_template="Test"
 54 compare_template="Compare"
 55 compare_masked_template="Compare-Masked"
 56 compare_broadcast_template="Compare-Broadcast"
 57 reduction_scalar="Reduction-Scalar-op"
 58 reduction_scalar_min="Reduction-Scalar-Min-op"
 59 reduction_scalar_max="Reduction-Scalar-Max-op"
 60 reduction_scalar_masked="Reduction-Scalar-Masked-op"
 61 reduction_scalar_min_masked="Reduction-Scalar-Masked-Min-op"
 62 reduction_scalar_max_masked="Reduction-Scalar-Masked-Max-op"
 63 reduction_op="Reduction-op"
 64 reduction_op_min="Reduction-Min-op"
 65 reduction_op_max="Reduction-Max-op"
 66 reduction_op_masked="Reduction-Masked-op"
 67 reduction_op_min_masked="Reduction-Masked-Min-op"
 68 reduction_op_max_masked="Reduction-Masked-Max-op"
 69 unary_math_template="Unary-op-math"
 70 binary_math_template="Binary-op-math"
 71 binary_math_broadcast_template="Binary-Broadcast-op-math"
 72 bool_reduction_scalar="BoolReduction-Scalar-op"
 73 bool_reduction_template="BoolReduction-op"
 74 with_op_template="With-Op"
 75 shift_template="Shift-op"
 76 shift_masked_template="Shift-Masked-op"
 77 get_template="Get-op"
 78 rearrange_template="Rearrange"
 79 broadcast_template="Broadcast"
 80 zero_template="Zero"
 81 slice_template="Slice-op"
 82 slice1_template="Slice-bop"
 83 slice1_masked_template="Slice-Masked-bop"
 84 unslice_template="Unslice-op"
 85 unslice1_template="Unslice-bop"
 86 unslice1_masked_template="Unslice-Masked-bop"
 87 miscellaneous_template="Miscellaneous"
 88 
 89 function replace_variables {
 90   local filename=$1
 91   local output=$2
 92   local kernel=$3
 93   local test=$4
 94   local op=$5
 95   local init=$6
 96   local guard=$7
 97   local masked=$8
 98   local op_name=$9
 99   local kernel_smoke=${10}
100 
101   if [ "x${kernel}" != "x" ]; then
102     local kernel_escaped=$(echo -e "$kernel" | tr '\n' '`')
103     sed "s/\[\[KERNEL\]\]/${kernel_escaped}/g" $filename > ${filename}.current1
104     cat ${filename}.current1 | tr '`' "\n" > ${filename}.current
105     rm -f "${filename}.current1"
106   else
107     cp $filename ${filename}.current
108   fi
109 
110   # Check if we need to do multiple replacements
111   # If you want to emit for an operation using lanewise(VectorOperator.**, ..) and also using dedicated instruction (e.g. add(..)), then
112   # pass the 'test' argument as "OPERATOR_NAME+func_Name" (e.g. "ADD+add")
113   # if there is a masked version available for the operation add "withMask" to 'test' argument (e.g. "ADD+add+withMask")
114   local test_func=""
115   local withMask=""
116   local tests=($(awk -F+ '{$1=$1} 1' <<< $test))
117   if [ "${tests[2]}" == "withMask" ]; then
118     test=${tests[0]}
119     test_func=${tests[1]}
120     withMask=${tests[2]}
121   elif [ "${tests[1]}" == "withMask" ]; then
122     test=""
123     test_func=${tests[0]}
124     withMask=${tests[1]}
125   elif [ "${tests[1]}" != "" ]; then
126     test=${tests[0]}
127     test_func=${tests[1]}
128   fi
129 
130   sed_prog="
131     s/\<OPTIONAL\>\(.*\)\<\\OPTIONAL\>/\1/g
132     s/\[\[TEST_TYPE\]\]/${masked}/g
133     s/\[\[TEST_OP\]\]/${op}/g
134     s/\[\[TEST_INIT\]\]/${init}/g
135     s/\[\[OP_NAME\]\]/${op_name}/g
136   "
137   sed_prog_2="$sed_prog
138     s/\[\[TEST\]\]/${test_func}/g
139     s/[.][^(]*(VectorOperators.$test_func, /.$test_func(/g
140     s/[.][^(]*(VectorOperators.$test_func,/.$test_func(/g
141     s/[.][^(]*(VectorOperators.$test_func/.$test_func(/g
142   "
143   sed_prog="
144     $sed_prog
145     s/\[\[TEST\]\]/${test}/g
146   "
147 
148   # Guard the test if necessary
149   if [ "$guard" != "" ]; then
150     echo -e "#if[${guard}]\n" >> $output
151   fi
152   if [ "$test" != "" ]; then
153     sed -e "$sed_prog" < ${filename}.current >> $output
154   fi
155   # If we also have a dedicated function for the operation then use 2nd sed expression
156   if [[ "$filename" == *"Unit"* ]] && [ "$test_func" != "" ]; then
157     if [ "$masked" == "" ] || [ "$withMask" != "" ]; then
158       if [ ! -z "$kernel_smoke" ]; then
159         local kernel_smoke_escaped=$(echo -e "$kernel_smoke" | tr '\n' '`')
160         sed "s/\[\[KERNEL\]\]/${kernel_smoke_escaped}/g" $filename > ${filename}.scurrent1
161         cat ${filename}.scurrent1 | tr '`' "\n" > ${filename}.scurrent
162         rm -f "${filename}.scurrent1"
163       else
164         cp $filename.current ${filename}.scurrent
165       fi
166       sed -e "$sed_prog_2" < ${filename}.scurrent >> $output
167       rm -f ${filename}.scurrent
168     fi
169   fi
170   if [ "$guard" != "" ]; then
171     echo -e "#end[${guard}]\n" >> $output
172   fi
173 
174   rm -f ${filename}.current
175 }
176 
177 function gen_op_tmpl {
178   local template=$1
179   local test=$2
180   local op=$3
181   local guard=""
182   local init=""
183   if [ $# -gt 3 ]; then
184     guard=$4
185   fi
186   if [ $# == 5 ]; then
187     init=$5
188   fi
189 
190   local masked=""
191   if [[ $template == *"Masked"* ]]; then
192     masked="Masked"
193   fi
194 
195   local op_name=""
196   if [[ $template == *"Shift"* ]]; then
197     op_name="Shift"
198   elif [[ $template == *"Get"* ]]; then
199     op_name="extract"
200   fi
201 
202   local kernel_filename="${TEMPLATE_FOLDER}/Kernel-${template}.template"
203   local kernel_smoke_filename="${TEMPLATE_FOLDER}/Kernel-${template}-smoke.template"
204   local unit_filename="${TEMPLATE_FOLDER}/Unit-${template}.template"
205   if [ ! -f $unit_filename ]; then
206     # Leverage general unit code snippet if no specialization exists
207     unit_filename="${TEMPLATE_FOLDER}/Unit-${template%_*}.template"
208     echo $unit_filename
209   fi
210 
211   local kernel=""
212   if [ -f $kernel_filename ]; then
213     kernel="$(cat $kernel_filename)"
214   fi
215 
216   local kernel_smoke=""
217   if [ -f $kernel_smoke_filename ]; then
218     kernel_smoke="$(cat $kernel_smoke_filename)"
219   else
220     kernel_smoke="$kernel"
221   fi
222 
223   # Replace template variables in unit test files (if any)
224   replace_variables $unit_filename $unit_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" "$kernel_smoke"
225 
226   local gen_perf_tests=$generate_perf_tests
227   if [[ $template == *"-Broadcast-"* ]] || [[ $template == "Miscellaneous" ]] ||
228      [[ $template == *"Compare-Masked"* ]] || [[ $template == *"Compare-Broadcast"* ]]; then
229     gen_perf_tests=false
230   fi
231   if [ $gen_perf_tests == true ]; then
232     # Replace template variables in performance test files (if any)
233     local perf_wrapper_filename="${TEMPLATE_FOLDER}/Perf-wrapper.template"
234     local perf_vector_filename="${TEMPLATE_FOLDER}/Perf-${template}.template"
235     local perf_scalar_filename="${TEMPLATE_FOLDER}/Perf-Scalar-${template}.template"
236 
237     if [ -f $perf_vector_filename ]; then
238       replace_variables $perf_vector_filename  $perf_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" ""
239     elif [ -f $kernel_filename ]; then
240       replace_variables $perf_wrapper_filename $perf_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" ""
241     elif [[ $template != *"-Scalar-"* ]] && [[ $template != "Get-op" ]] && [[ $template != "With-Op" ]]; then
242       echo "Warning: missing perf: $@"
243     fi
244 
245     if [ -f $perf_scalar_filename ]; then
246       replace_variables $perf_scalar_filename $perf_scalar_output "$kernel" "$test" "$op" "$init" "$guard" "$masked" "$op_name" ""
247     elif [[ $template != *"-Scalar-"* ]] && [[ $template != "Get-op" ]] && [[ $template != "With-Op" ]]; then
248       echo "Warning: Missing PERF SCALAR: $perf_scalar_filename"
249     fi
250   fi
251 }
252 
253 function gen_binary_alu_op {
254   echo "Generating binary op $1 ($2)..."
255   gen_op_tmpl $binary "$@"
256   gen_op_tmpl $binary_masked "$@"
257 }
258 
259 function gen_binary_alu_bcst_op {
260   echo "Generating binary broadcast op $1 ($2)..."
261   gen_op_tmpl $binary_broadcast "$@"
262   gen_op_tmpl $binary_broadcast_masked "$@"
263 }
264 
265 function gen_binary_alu_bcst_long_op {
266   echo "Generating binary broadcast long op $1 ($2)..."
267   gen_op_tmpl $binary_broadcast_long "$@"
268   gen_op_tmpl $binary_broadcast_masked_long "$@"
269 }
270 
271 function gen_shift_cst_op {
272   echo "Generating Shift constant op $1 ($2)..."
273   gen_op_tmpl $shift_template "$@"
274   gen_op_tmpl $shift_masked_template "$@"
275 }
276 
277 function gen_unary_alu_op {
278   echo "Generating unary op $1 ($2)..."
279   gen_op_tmpl $unary_scalar "$@"
280   gen_op_tmpl $unary "$@"
281   gen_op_tmpl $unary_masked "$@"
282 }
283 
284 function gen_ternary_alu_op {
285   echo "Generating ternary op $1 ($2)..."
286   gen_op_tmpl $ternary_scalar "$@"
287   gen_op_tmpl $ternary "$@"
288   gen_op_tmpl $ternary_masked "$@"
289 }
290 
291 function gen_ternary_alu_bcst_op {
292   echo "Generating ternary broadcast op $1 ($2)..."
293   gen_op_tmpl $ternary_broadcast "$@"
294   gen_op_tmpl $ternary_broadcast_masked "$@"
295 }
296 
297 function gen_ternary_alu_double_bcst_op {
298   echo "Generating ternary double broadcast op $1 ($2)..."
299   gen_op_tmpl $ternary_double_broadcast "$@"
300   gen_op_tmpl $ternary_double_broadcast_masked "$@"
301 }
302 
303 function gen_binary_op {
304   echo "Generating binary op $1 ($2)..."
305 #  gen_op_tmpl $binary_scalar "$@"
306   gen_op_tmpl $binary "$@"
307   gen_op_tmpl $binary_masked "$@"
308 }
309 
310 function gen_binary_op_no_masked {
311   echo "Generating binary op $1 ($2)..."
312 #  gen_op_tmpl $binary_scalar "$@"
313   gen_op_tmpl $binary "$@"
314 }
315 
316 function gen_binary_bcst_op_no_masked {
317   echo "Generating binary broadcast op $1 ($2)..."
318   gen_op_tmpl $binary_broadcast "$@"
319 }
320 
321 function gen_compare_op {
322   echo "Generating compare op $1 ($2)..."
323   gen_op_tmpl $compare_template "$@"
324   gen_op_tmpl $compare_masked_template "$@"
325 }
326 
327 function gen_compare_bcst_op {
328   echo "Generating compare broadcast op $1 ($2)..."
329   gen_op_tmpl $compare_broadcast_template "$@"
330 }
331 
332 function gen_reduction_op {
333   echo "Generating reduction op $1 ($2)..."
334   gen_op_tmpl $reduction_scalar "$@"
335   gen_op_tmpl $reduction_op "$@"
336   gen_op_tmpl $reduction_scalar_masked "$@"
337   gen_op_tmpl $reduction_op_masked "$@"
338 }
339 
340 function gen_reduction_op_min {
341   echo "Generating reduction op $1 ($2)..."
342   gen_op_tmpl $reduction_scalar_min "$@"
343   gen_op_tmpl $reduction_op_min "$@"
344   gen_op_tmpl $reduction_scalar_min_masked "$@"
345   gen_op_tmpl $reduction_op_min_masked "$@"
346 }
347 
348 function gen_reduction_op_max {
349   echo "Generating reduction op $1 ($2)..."
350   gen_op_tmpl $reduction_scalar_max "$@"
351   gen_op_tmpl $reduction_op_max "$@"
352   gen_op_tmpl $reduction_scalar_max_masked "$@"
353   gen_op_tmpl $reduction_op_max_masked "$@"
354 }
355 
356 function gen_bool_reduction_op {
357   echo "Generating boolean reduction op $1 ($2)..."
358   gen_op_tmpl $bool_reduction_scalar "$@"
359   gen_op_tmpl $bool_reduction_template "$@"
360 }
361 
362 function gen_with_op {
363   echo "Generating with op $1 ($2)..."
364   gen_op_tmpl $with_op_template "$@"
365 }
366 
367 function gen_get_op {
368   echo "Generating get op $1 ($2)..."
369   gen_op_tmpl $get_template "$@"
370 }
371 
372 function gen_unit_header {
373   cat $TEMPLATE_FOLDER/Unit-header.template > $1
374 }
375 
376 function gen_unit_footer {
377   cat $TEMPLATE_FOLDER/Unit-footer.template >> $1
378 }
379 
380 function gen_perf_header {
381   cat $TEMPLATE_FOLDER/Perf-header.template > $1
382 }
383 
384 function gen_perf_footer {
385   cat $TEMPLATE_FOLDER/Perf-footer.template >> $1
386 }
387 
388 function gen_perf_scalar_header {
389   cat $TEMPLATE_FOLDER/Perf-Scalar-header.template > $1
390 }
391 
392 function gen_perf_scalar_footer {
393   cat $TEMPLATE_FOLDER/Perf-Scalar-footer.template >> $1
394 }
395 
396 gen_unit_header $unit_output
397 
398 if [ $generate_perf_tests == true ]; then
399   gen_perf_header $perf_output
400   gen_perf_scalar_header $perf_scalar_output
401 fi
402 
403 # ALU binary ops.
404 # Here "ADD+add+withMask" says VectorOperator name is "ADD", and we have a dedicate method too named 'add', and add() is also available with mask variant.
405 gen_binary_alu_op "ADD+add+withMask" "a + b"
406 gen_binary_alu_op "SUB+sub+withMask" "a - b"
407 gen_binary_alu_op "MUL+mul+withMask" "a \* b"
408 gen_binary_alu_op "DIV+div+withMask" "a \/ b" "FP"
409 gen_op_tmpl "Binary-op_bitwise-div" "DIV+div+withMask" "a \/ b" "BITWISE"
410 gen_op_tmpl "Binary-Masked-op_bitwise-div" "DIV+div+withMask" "a \/ b" "BITWISE"
411 gen_binary_alu_op "FIRST_NONZERO" "{#if[FP]?Double.doubleToLongBits}(a)!=0?a:b"
412 gen_binary_alu_op "AND+and"   "a \& b"  "BITWISE"
413 gen_binary_alu_op "AND_NOT" "a \& ~b" "BITWISE"
414 gen_binary_alu_op "OR+or"    "a | b"   "BITWISE"
415 # Missing:        "OR_UNCHECKED"
416 gen_binary_alu_op "XOR"   "a ^ b"   "BITWISE"
417 # Generate the broadcast versions
418 gen_binary_alu_bcst_op "add+withMask" "a + b"
419 gen_binary_alu_bcst_op "sub+withMask" "a - b"
420 gen_binary_alu_bcst_op "mul+withMask" "a \* b"
421 gen_binary_alu_bcst_op "div+withMask" "a \/ b" "FP"
422 gen_op_tmpl "Binary-Broadcast-op_bitwise-div" "div+withMask" "a \/ b" "BITWISE"
423 gen_op_tmpl "Binary-Broadcast-Masked-op_bitwise-div" "div+withMask" "a \/ b" "BITWISE"
424 gen_binary_alu_bcst_op "OR+or"    "a | b"   "BITWISE"
425 gen_binary_alu_bcst_op "AND+and"    "a \& b"   "BITWISE"
426 gen_binary_alu_bcst_long_op "OR"     "a | b"   "BITWISE"
427 gen_binary_alu_bcst_long_op "ADD"    "a + b"
428 
429 # Shifts
430 gen_binary_alu_op "LSHL" "(a << b)" "intOrLong"
431 gen_binary_alu_op "LSHL" "(a << (b \& 0x7))" "byte"
432 gen_binary_alu_op "LSHL" "(a << (b \& 0xF))" "short"
433 gen_binary_alu_op "ASHR" "(a >> b)" "intOrLong"
434 gen_binary_alu_op "ASHR" "(a >> (b \& 0x7))" "byte"
435 gen_binary_alu_op "ASHR" "(a >> (b \& 0xF))" "short"
436 gen_binary_alu_op "LSHR" "(a >>> b)" "intOrLong"
437 gen_binary_alu_op "LSHR" "((a \& 0xFF) >>> (b \& 0x7))" "byte"
438 gen_binary_alu_op "LSHR" "((a \& 0xFFFF) >>> (b \& 0xF))" "short"
439 gen_shift_cst_op  "LSHL" "(a << b)" "intOrLong"
440 gen_shift_cst_op  "LSHL" "(a << (b \& 7))" "byte"
441 gen_shift_cst_op  "LSHL" "(a << (b \& 15))" "short"
442 gen_shift_cst_op  "LSHR" "(a >>> b)" "intOrLong"
443 gen_shift_cst_op  "LSHR" "((a \& 0xFF) >>> (b \& 7))" "byte"
444 gen_shift_cst_op  "LSHR" "((a \& 0xFFFF) >>> (b \& 15))" "short"
445 gen_shift_cst_op  "ASHR" "(a >> b)" "intOrLong"
446 gen_shift_cst_op  "ASHR" "(a >> (b \& 7))" "byte"
447 gen_shift_cst_op  "ASHR" "(a >> (b \& 15))" "short"
448 gen_binary_alu_op "ROR" "ROR_scalar(a,b)" "BITWISE"
449 gen_binary_alu_op "ROL" "ROL_scalar(a,b)" "BITWISE"
450 gen_shift_cst_op  "ROR" "ROR_scalar(a,b)" "BITWISE"
451 gen_shift_cst_op  "ROL" "ROL_scalar(a,b)" "BITWISE"
452 
453 # Masked reductions.
454 gen_binary_op_no_masked "MIN+min" "Math.min(a, b)"
455 gen_binary_op_no_masked "MAX+max" "Math.max(a, b)"
456 gen_binary_bcst_op_no_masked "MIN+min" "Math.min(a, b)"
457 gen_binary_bcst_op_no_masked "MAX+max" "Math.max(a, b)"
458 
459 # Reductions.
460 gen_reduction_op "AND" "\&" "BITWISE" "-1"
461 gen_reduction_op "OR" "|" "BITWISE" "0"
462 gen_reduction_op "XOR" "^" "BITWISE" "0"
463 gen_reduction_op "ADD" "+" "" "0"
464 gen_reduction_op "MUL" "*" "" "1"
465 gen_reduction_op_min "MIN" "" "" "\$Wideboxtype\$.\$MaxValue\$"
466 gen_reduction_op_max "MAX" "" "" "\$Wideboxtype\$.\$MinValue\$"
467 #gen_reduction_op "reduce_FIRST_NONZERO" "lanewise_FIRST_NONZERO" "{#if[FP]?Double.doubleToLongBits}(a)=0?a:b" "" "1"
468 
469 # Boolean reductions.
470 gen_bool_reduction_op "anyTrue" "|" "BITWISE" "false"
471 gen_bool_reduction_op "allTrue" "\&" "BITWISE" "true"
472 
473 #Insert
474 gen_with_op "withLane" "" "" ""
475 
476 # Tests
477 gen_op_tmpl $test_template "IS_DEFAULT" "bits(a)==0"
478 gen_op_tmpl $test_template "IS_NEGATIVE" "bits(a)<0"
479 gen_op_tmpl $test_template "IS_FINITE" "\$Boxtype\$.isFinite(a)" "FP"
480 gen_op_tmpl $test_template "IS_NAN" "\$Boxtype\$.isNaN(a)" "FP"
481 gen_op_tmpl $test_template "IS_INFINITE" "\$Boxtype\$.isInfinite(a)" "FP"
482 
483 # Compares
484 gen_compare_op "LT+lt" "lt"
485 gen_compare_op "GT" "gt"
486 gen_compare_op "EQ+eq" "eq"
487 gen_compare_op "NE" "neq"
488 gen_compare_op "LE" "le"
489 gen_compare_op "GE" "ge"
490 
491 gen_compare_op "UNSIGNED_LT" "ult" "BITWISE"
492 gen_compare_op "UNSIGNED_GT" "ugt" "BITWISE"
493 gen_compare_op "UNSIGNED_LE" "ule" "BITWISE"
494 gen_compare_op "UNSIGNED_GE" "uge" "BITWISE"
495 
496 
497 gen_compare_bcst_op "LT" "<"
498 gen_compare_bcst_op "EQ" "=="
499 
500 # Blend.
501 gen_op_tmpl $blend "blend" ""
502 
503 # Rearrange
504 gen_op_tmpl $rearrange_template "rearrange" ""
505 
506 # Get
507 gen_get_op "lane" ""
508 
509 # Broadcast
510 gen_op_tmpl $broadcast_template "broadcast" ""
511 
512 # Zero
513 gen_op_tmpl $zero_template "zero" ""
514 
515 # Slice
516 gen_op_tmpl $slice_template "sliceUnary" ""
517 gen_op_tmpl $slice1_template "sliceBinary" ""
518 gen_op_tmpl $slice1_masked_template "slice" ""
519 
520 # Unslice
521 gen_op_tmpl $unslice_template "unsliceUnary" ""
522 gen_op_tmpl $unslice1_template "unsliceBinary" ""
523 gen_op_tmpl $unslice1_masked_template "unslice" ""
524 
525 # Math
526 gen_op_tmpl $unary_math_template "SIN" "Math.sin((double)a)" "FP"
527 gen_op_tmpl $unary_math_template "EXP" "Math.exp((double)a)" "FP"
528 gen_op_tmpl $unary_math_template "LOG1P" "Math.log1p((double)a)" "FP"
529 gen_op_tmpl $unary_math_template "LOG" "Math.log((double)a)" "FP"
530 gen_op_tmpl $unary_math_template "LOG10" "Math.log10((double)a)" "FP"
531 gen_op_tmpl $unary_math_template "EXPM1" "Math.expm1((double)a)" "FP"
532 gen_op_tmpl $unary_math_template "COS" "Math.cos((double)a)" "FP"
533 gen_op_tmpl $unary_math_template "TAN" "Math.tan((double)a)" "FP"
534 gen_op_tmpl $unary_math_template "SINH" "Math.sinh((double)a)" "FP"
535 gen_op_tmpl $unary_math_template "COSH" "Math.cosh((double)a)" "FP"
536 gen_op_tmpl $unary_math_template "TANH" "Math.tanh((double)a)" "FP"
537 gen_op_tmpl $unary_math_template "ASIN" "Math.asin((double)a)" "FP"
538 gen_op_tmpl $unary_math_template "ACOS" "Math.acos((double)a)" "FP"
539 gen_op_tmpl $unary_math_template "ATAN" "Math.atan((double)a)" "FP"
540 gen_op_tmpl $unary_math_template "CBRT" "Math.cbrt((double)a)" "FP"
541 gen_op_tmpl $binary_math_template "HYPOT" "Math.hypot((double)a, (double)b)" "FP"
542 gen_op_tmpl $binary_math_template "POW+pow" "Math.pow((double)a, (double)b)" "FP"
543 gen_op_tmpl $binary_math_template "ATAN2" "Math.atan2((double)a, (double)b)" "FP"
544 gen_op_tmpl $binary_math_broadcast_template "POW+pow" "Math.pow((double)a, (double)b)" "FP"
545 
546 # Ternary operations.
547 gen_ternary_alu_op "FMA+fma" "Math.fma(a, b, c)" "FP"
548 gen_ternary_alu_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE"
549 gen_ternary_alu_bcst_op "FMA" "Math.fma(a, b, c)" "FP"
550 gen_ternary_alu_bcst_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE"
551 gen_ternary_alu_double_bcst_op "FMA+fma" "Math.fma(a, b, c)" "FP"
552 gen_ternary_alu_double_bcst_op "BITWISE_BLEND+bitwiseBlend" "(a\&~(c))|(b\&c)" "BITWISE"
553 
554 # Unary operations.
555 gen_unary_alu_op "NEG+neg" "-((\$type\$)a)"
556 gen_unary_alu_op "ABS+abs" "Math.abs((\$type\$)a)"
557 gen_unary_alu_op "NOT+not" "~((\$type\$)a)" "BITWISE"
558 gen_unary_alu_op "ZOMO" "(a==0?0:-1)" "BITWISE"
559 gen_unary_alu_op "SQRT+sqrt" "Math.sqrt((double)a)" "FP"
560 
561 # Miscellaneous Smoke Tests
562 gen_op_tmpl $miscellaneous_template "MISC" "" ""
563 
564 gen_unit_footer $unit_output
565 
566 if [ $generate_perf_tests == true ]; then
567   gen_perf_footer $perf_output
568   gen_perf_scalar_footer $perf_scalar_output
569 fi
570 
571 rm -f templates/*.current*