| | 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 | |
|---|
| | 79 | enum VecExpressionType { SSE1Expression, SSE2Expression, X87Expression, DExpression }; |
|---|
| | 80 | |
|---|
| | 81 | VecExpressionType 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 | |
|---|
| 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 | |
|---|