Changeset 120

Show
Ignore:
Timestamp:
10/24/07 02:28:27 (1 year ago)
Author:
Don Clugston
Message:

* First steps to expression categorisation.
* removed non-working dot product support from SSE2.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/blade/Blade.d

    r117 r120  
    7272} 
    7373 
     74// ------------------------------------ 
     75// Categorize the expression type 
     76// SSE2 is possible only if all vectors are doubles. 
     77// SSE1 is possible only if all vectors are floats. 
     78 
     79enum VecExpressionType { SSE1Expression, SSE2Expression, X87Expression, DExpression }; 
     80 
     81VecExpressionType categorizeExpression(AbstractSyntaxTree tree) 
     82{ 
     83    bool SSE2 = true; 
     84    bool SSE1 = true; 
     85    bool X87 = true; 
     86    for (int i=0; i<tree.symbolTable.length;++i) { 
     87        char [] t = tree.symbolTable[i].type; 
     88        int r = tree.symbolTable[i].rank; 
     89        if (r>1) return VecExpressionType.DExpression; // can only do scalars and vectors right now. 
     90        if (r==0) continue; // assume we can always do scalars.         
     91        if ((t.length>7 && t[0..7]=="double[")) { 
     92            SSE1 = false; 
     93        } else if ((t.length>6 && t[0..6]=="float[")) { 
     94            SSE2 = false; 
     95        } else { 
     96            SSE1 = false; 
     97            SSE2 = false; 
     98            if ((t.length>5 && t[0..5]=="real[")) { } 
     99            else X87 = false; 
     100        } 
     101    } 
     102    if (SSE1) return VecExpressionType.SSE1Expression; 
     103    if (SSE2) return VecExpressionType.SSE2Expression;     
     104    return X87 ? VecExpressionType.X87Expression : VecExpressionType.DExpression;  
     105} 
     106 
    74107char [] makeSSE(AbstractSyntaxTree tree) 
    75108{ 
    76     char [] result = "SSEVECGEN!(" ~ wrapInQuotes(tree.expression) ~ ")("; 
    77     int knt=0; 
    78     for (int i=0; i<tree.symbolTable.length;++i) { 
    79         if (knt>0) result ~=","; 
    80         result ~= tree.symbolTable[i].value; 
    81         ++knt; 
    82     } 
    83     return result~ ");"; 
     109    VecExpressionType exprType = categorizeExpression(tree); 
     110    if (exprType == VecExpressionType.SSE2Expression) { 
     111        char [] result = "SSEVECGEN!(" ~ wrapInQuotes(tree.expression) ~ ")("; 
     112        int knt=0; 
     113        for (int i=0; i<tree.symbolTable.length;++i) { 
     114            if (knt>0) result ~=","; 
     115            result ~= tree.symbolTable[i].value; 
     116            ++knt; 
     117        } 
     118        return result~ ");"; 
     119    } else { 
     120        return `static assert(0,` ~ wrapInQuotes("SSE2 is impossible for expression " ~ tree.expression) ~ `);`; 
     121    }     
     122     
    84123} 
    85124 
  • trunk/blade/BladeUtil.d

    r119 r120  
    3939} 
    4040 
     41unittest { 
     42    assert(wrapInQuotes(`"a\"`)==`"\"a\\\""`); 
     43} 
  • trunk/blade/CodegenX86.d

    r117 r120  
    150150    if (first[0]=='(') { 
    151151        first = makePostfixForSSE(first[1..first.length-1], ranklist); 
    152     } else if (first[0]=='d') { // dot product 
    153         return "AA="; 
    154 //        assert(0, "xxx" ~ first ~ " " ~ second); 
    155 //    first="A"; 
    156 //        int comma = paramLength(first[2..$-1]); 
    157    //     char [] right = first[comma+1..$-1]; 
    158    //     first = '#' ~ makePostfixForSSE(first[2..comma], ranklist) ~ makePostfixForSSE(right, ranklist) ~ "*+"; 
    159152    } else assert(first.length<2, "Missing () in expression: " ~ first); 
    160153    if (second[0]=='(') { 
     
    165158    } 
    166159 
    167     // On x87, fp multiplies have a long latency, so we want to delay using the 
     160    // Multiplies have a long latency, so we want to delay using the 
    168161    // result of a multiply. Since + is commutative, we can achieve this 
    169162    // by calculating the value with the multiply, before the other one.