📄 ops-to-gp
字号:
#!/bin/sh# APPLE LOCAL file AltiVec# ops-to-gp -gcc vec.ops builtin.ops# Creates vec.h used by rs6000.carg0=`basename $0`err() { echo "$arg0: $*" 1>&2 exit 2}if [ $# -eq 0 ] ; then echo "Usage: $arg0 [ -mcc | -gcc ] builtin-ops ..." 1>&2 exit 1fiMCC=1GCC=0suffix="gp"if [ "$1" = "-mcc" ] ; then shift;elif [ "$1" = "-gcc" ] ; then GCC=1 MCC=0 suffix="h" shift;fioutput=`basename $1 .ops`gperf="gperf -G -a -o -k1-15 -p -t -D -T -N Is_Builtin_Function $output.gp";# Lines in the ops file have the form# @ @ betype betype-code type-spelling# @ fetype betype [code]# @ @ @ instruction type# generic op1 op2 ... opn = result specific when configure [addressible# [instruction [const_ptr_ok [volatile_ptr_ok [transform [predicate]]]]]]# Sort the ops file to put it in a canonical order.sort -u $* | \# Add specific function uid's, make generic functions from specific# functions, validate the types used, compute default parameters, and# compute parts of the default transform and predicate functions.awk 'BEGIN { i = 0 EQ = i++ RESULT = i++ SPECIFIC = i++ WHEN = i++ CONFIGURED = i++ ADDRESSIBLE = i++ INSTRUCTION = i++ CONST_PTR_OK = i++ VOLATILE_PTR_OK = i++ TRANSFORM = i++ PREDICATE = i++ n_lines = 1; tree[3] = "Make_Folded_4tree"; tree[2] = "Make_Folded_3tree"; tree[1] = "Make_Folded_Btree"; tree[0] = "Make_Utree"; optimize["vec_sub"] = 1; optimize["vec_subs"] = 1; optimize["vec_xor"] = 1; optimize["vec_andc"] = 1; optimize["vec_avg"] = 2; optimize["vec_or"] = 2; optimize["vec_and"] = 2; optimize["vec_max"] = 2; optimize["vec_min"] = 2; optimize["vec_sld"] = 3; optimize["vec_splat_s8"] = 4; optimize["vec_splat_s16"] = 5; optimize["vec_splat_s32"] = 6; optimize["vec_splat_u8"] = 4; optimize["vec_splat_u16"] = 5; optimize["vec_splat_u32"] = 6; optimize["vec_cmpeq"] = 7; optimize["vec_lvsl"] = 8; optimize["vec_lvsr"] = 9; # These operations need additional transformation. Key off the # optimize attribute to identify them. optimize["vec_cmplt"] = 10; optimize["vec_cmple"] = 10; optimize["vec_abs"] = 11; optimize["vec_abss"] = 11; } function no_type(t) { printf "%% Error: type %s not declared.\n", t; status = 1; exit; } # Record the type. $1 == "@" { if ($2 == "@") { if ($3 == "@") { # Definition of an instruction. insn_type[$4] = $5; # type } else { # Definition of a betype. becode[$3] = $4; # betype-code bespell[$3] = $5; # type-spelling gsub(/\=/, " ", bespell[$3]); } } else { # Definition of a fetype. print $0; if (!becode[$3]) no_type($3); # Must have defined the betype. betype[$2] = $3; # betype; if (NF == 3) code[$2] = ""; else code[$2] = $4; # code } } function no_equal(i,l) { printf "%% Syntax error %d: %s\n", i, l; status = 1; exit; } function error(f,a) { printf( ("%% error: " f), a); status = 1; exit; } # Ignore comment lines. $1 != "#" && $1 != "@" { # Generate the signature of the specific function, the predicate, # the transform, the arguments to the transform function, the # arguments to the predicate function, and the spelling of the # function type. signature = ""; predicate = ""; transform = ""; insn_code = ""; transform_args = ""; predicate_args = ""; function_type = ""; # First, consider the parameter types. for (i = 2; $i != "=" && i < NF; i++) { if ($i != "...") { if (!betype[$i]) no_type($i); signature = (signature " " $i); predicate = (predicate "_" betype[$i]); transform = (transform code[$i]); transform_args = (transform_args ", ND_kid(t," i-1 ")"); predicate_args = (predicate_args " " becode[betype[$i]]); if (function_type) function_type = (function_type ", " bespell[betype[$i]]); else function_type = bespell[betype[$i]]; } } constraints = (transform "@"); # Check the syntax of the ops file. if ($i != "=" || NF > i+PREDICATE || NF < i+CONFIGURE) no_equal(i,$0); if (!betype[$(i+RESULT)]) no_type($(i+RESULT)); # Incorporate the result type. if (i == 2) { predicate = "_void"; function_type = "void"; } signature = ($(i+SPECIFIC) signature); predicate = sprintf("is_%s_func%s", betype[$(i+RESULT)], predicate); predicate_args = (becode[betype[$(i+RESULT)]] predicate_args); function_type = sprintf("(%s (*)(%s))", bespell[betype[$(i+RESULT)]], \ function_type); if (substr(code[$(i+RESULT)], 1, 1) == "j") { # Handle a jump asm. The code is expedted to be # j={cc-bit-num}={cc-bit-value}[={r|d}]. The operation must have # one operand if the code d is used and two operands otherwise. # The transform function can implement the r code by reversing the # two operands. In all cases, the first operand is a computed # constant encoding both the bit number and the test. n = split(code[$(i+RESULT)], jmp, "="); if (jmp[n] == "d" && i != 3) error("%d operands", i-2); if (jmp[n] != "d" && i != 4) error("%d operands", i-2); if (jmp[n] == "r") transform_args = ", ND_kid(t,2), ND_kid(t,1)"; transform_args = sprintf("%s(OP_VCMP%s%s", tree[i-2], \ toupper(jmp[3]), transform_args); if (jmp[n] == "r") transform = ("r" transform); insn_code = sprintf("CODE_FOR_j_%d_%s_f%s", jmp[2], jmp[3], \ transform); transform = sprintf("transform_j_%d_%s_f%s", jmp[2], jmp[3], \ transform); } else { transform_args = sprintf("%s(OP_%sASM%s%s", tree[i-2], \ toupper(code[$(i+RESULT)]), \ toupper(transform), transform_args); insn_code = sprintf("CODE_FOR_%sf%s", code[$(i+RESULT)], transform); transform = sprintf("transform_%sf%s", code[$(i+RESULT)], transform); } # Give a unique id to the signature if (count[signature] == 0) count[signature] = ++uid[$(i+SPECIFIC)]; # Compute the default instruction name nf = split($(i+SPECIFIC), part, "_"); instruction = ("MOP_" part[nf]); # Compute the insn_code, but use the instruction override if given. if (NF >= i+INSTRUCTION) instruction = $(i+INSTRUCTION); if (insn_type[instruction]) insn_code = (insn_code "_" insn_type[instruction]); # Allow the user to override the addressibility, instruction, # const_ptr_ok, volatile_ptr_ok, transform, and predicate. if (NF >= i+ADDRESSIBLE) addressible = ""; else addressible = "FALSE"; if (NF >= i+INSTRUCTION) instruction = ""; else if (substr($1, 1, 4) == "vec_") print "@ @3", instruction; if (NF >= i+CONST_PTR_OK) const_ptr_ok = ""; else const_ptr_ok = "FALSE"; if (NF >= i+VOLATILE_PTR_OK) volatile_ptr_ok = ""; else volatile_ptr_ok = "FALSE"; if (NF >= i+TRANSFORM) transform = ""; else print "@ @1", transform, transform_args; if (NF >= i+PREDICATE) predicate = ""; else print "@ @2", i-2, predicate, predicate_args, function_type; if (optimize[$1]) optimize_method = optimize[$1]; else optimize_method = "0"; # Record the line, addressibility, instruction, transform, # predicate, and unique id. line[n_lines++] = ($0 " " addressible " " instruction " " \ const_ptr_ok " " volatile_ptr_ok " " transform " " \ predicate " " insn_code " " constraints " " \ optimize_method " " count[signature]); } END { if (status) exit; # generic op1 op2 ... opn = result specific when configured # addressable instruction const_ptr_ok volatile_ptr_ok # transform predicate insn_code constraints optimize uid SPECIFIC = 12 for (i = 1; i < n_lines; i++) { nf = split(line[i], part); specific = part[nf-SPECIFIC]; # Print the generic form. printf "%s", part[1]; for (j = 2; j <= nf-SPECIFIC; j++) printf " %s", part[j]; if (uid[specific] > 1) printf ":%d", part[nf]; while (j < nf) printf " %s", part[j++]; printf "\n"; # Print the specific form. printf "%s", specific; for (j = 2; j <= nf-SPECIFIC; j++) printf " %s", part[j]; if (uid[specific] > 1) printf ":%d", part[nf]; while (j < nf) printf " %s", part[j++]; printf "\n"; } }' | \# Strip out load and store qualifiers.sed -e 's/_load_op//g' -e 's/_store_op//g' | \# Sort the processed file and eliminate duplicates.sort -u | \# Append the count of each generic function to each line.awk 'function push() { if (num) for (i = 0; i < num; i++) print line[i], num; num = 0; } $1 == "@" { print $0; } $1 != "@" { if (last != $1) push(); last = $1; line[num++] = $0; } END { push(); }' | \# Now compute the gperf input file.# Lines now have a fixed format# generic op1 ... opn = result specific instruction when configured# addressible const_ptr_ok volatile_ptr_ok transform predicate# insn_code constraints optimize countawk 'BEGIN {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -