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