Changeset 155
- Timestamp:
- 12/05/07 03:02:24 (9 months ago)
- Files:
-
- trunk/blade/Blade.d (modified) (12 diffs)
- trunk/blade/BladeDemo.d (modified) (3 diffs)
- trunk/blade/BladeRank.d (modified) (1 diff)
- trunk/blade/BladeSimplify.d (modified) (2 diffs)
- trunk/blade/CodegenX86.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/blade/Blade.d
r154 r155 49 49 private import blade.BladeRank : isStrided; 50 50 private import blade.BladeSimplify : simplifySyntaxTree, RevisedExpression; 51 public import blade.CodegenX86 : generateCodeForAsmX87, MAX_X87_VECTORS, 51 private import blade.CodegenX86 : generateCodeForAsmX87, MAX_X87_VECTORS, 52 MAX_87_REALSCALARSPLUSTEMPORARIES, 52 53 generateCodeForSSE, MAX_SSE_VECTORS; 53 54 … … 118 119 // SSE1 is possible only if all vectors are floats. 119 120 // X87 is possible for any mix of real, double, and float vectors. 120 // BUG: should also check if it will overflow the FPU stack 121 121 // BUG: for X87, should also check number of temporaries (don't overflow the FPU stack 122 122 enum VecExpressionType { SSE1Expression, SSE2Expression, X87Expression, DExpression }; 123 123 … … 136 136 int numvectors = 0; 137 137 int numscalars = 0; 138 int numRealScalars = 0; // scalars other than float or double. 138 139 for (int i=0; i<revised.mapping.length;++i) { 139 140 char r = revised.rank[i]; 141 int x = revised.mapping[i]-'A'; 140 142 if (r=='0') { 141 143 ++numscalars; 144 if (x<tree.symbolTable.length) { 145 char [] t = tree.symbolTable[x].element; 146 if (t!="double" && t!="float" && t!="idouble" && t!="ifloat") { 147 ++numRealScalars; 148 } 149 } 142 150 // TODO: disallow asm if any non-int/not FP types are used. 143 151 continue; // BUG: assume asm can always do scalars … … 145 153 if (r>'1') return VecExpressionType.DExpression; // can only do scalars and vectors right now. 146 154 // At this point, all compounds are an original symbol + indexing/slicing. 147 int x = revised.mapping[i]-'A';148 155 int y = x; // for compounds, get the original type 149 156 if (x>=tree.symbolTable.length) { … … 151 158 // Check for a stride.. 152 159 if (revised.compounds[x-tree.symbolTable.length][$-1]==']') { 153 // assert(0,revised.compounds[x-tree.symbolTable.length]);154 160 strided |= isStrided(revised.compounds[x-tree.symbolTable.length]); 155 161 } … … 171 177 } 172 178 if (strided) return VecExpressionType.DExpression; 179 if (numRealScalars > MAX_87_REALSCALARSPLUSTEMPORARIES) X87 = false; 173 180 if (numvectors > MAX_X87_VECTORS) X87 = false; 174 181 if (numvectors > MAX_SSE_VECTORS) { SSE1=false; SSE2=false; } … … 193 200 194 201 char [] vals; 195 196 202 for (int i=0; i<revised.mapping.length;++i) { 197 vals ~= "," ~ getValueForSymbol(revised.mapping[i], tree, revised);198 203 char rnk = revised.rank[i]; 204 vals ~= ","; 205 if (rnk=='1') vals ~= "&"; 206 vals ~= getValueForSymbol(revised.mapping[i], tree, revised); 199 207 int x = revised.mapping[i]-'A'; 200 208 char [] t; … … 207 215 // it's a compound 208 216 if (rnk=='0') { 209 t = "real"; // convert all compounds to real 217 t = "real"; // convert all compounds to real. 218 // TODO: if the number is exactly representable as a double 219 // or float, it could use less FPU stack space. 210 220 } else { // for arrays, the type is the type of the original array 211 t = tree.symbolTable[revised.compounds[x-tree.symbolTable.length][0] ].element;221 t = tree.symbolTable[revised.compounds[x-tree.symbolTable.length][0]-'A'].element; 212 222 } 213 223 } … … 225 235 result ~= t ~ "*"; 226 236 // for vectors, we only need the pointer, not the length 227 vals ~= " .ptr";237 vals ~= "[0]"; 228 238 } 229 239 } … … 339 349 } 340 350 351 bool hasDollar(char [] s) 352 { 353 foreach(c; s) { if (c=='$') return true; } 354 return false; 355 } 356 341 357 char [] getDimensionLengthForSymbol(char c, AbstractSyntaxTree tree, RevisedExpression revised, int dimension) 342 358 { … … 366 382 int numbracks = 0; 367 383 bool isSlice = false; 368 char [] newSlice; 384 char [] nextIndex; 385 char [] sliceTo; 369 386 370 387 for (int k = comp.length-1;k>=1; --k) { 371 388 char d = comp[k]; 372 389 if (d == ']') { ++numbracks; } 373 if (d == '[') { --numbracks; } 374 if (d==']' && numbracks == 1) { newSlice = ""; } 375 else if (d=='.' && numbracks == 1) { isSlice = true; 376 newSlice = "." ~ newSlice; 377 } 378 else if (d=='[' && numbracks==0) { 390 if (d == '[') { --numbracks; } 391 392 if (d == ']' && numbracks == 1) { nextIndex = ""; } 393 else if (numbracks == 1 && comp[k-1..k+1]=="..") { 394 isSlice = true; 395 sliceTo = nextIndex; 396 nextIndex = ""; 397 --k; 398 } else if ((d == '[' && numbracks==0) || (d==',' && numbracks==1)) { 379 399 if (isSlice && numSlicesRemaining>0) { 380 v = "[" ~ newSlice 400 if (numSlicesRemaining==1) { 401 if (!hasDollar(nextIndex) && !hasDollar(sliceTo)) { 402 return "(" ~ sliceTo ~ "-" ~ nextIndex ~ ")"; 403 } 404 } 405 v = "[" ~ nextIndex ~ ".." ~ sliceTo 381 406 ~ "].length"; 382 407 --numSlicesRemaining; 383 408 } else { 384 v = "[" ~ newSlice ~ "]" ~ v; 409 if (isSlice) 410 v = "[" ~ nextIndex ~ ".." ~ sliceTo ~ "]" ~ v; 411 else v = "[" ~ nextIndex ~ "]" ~ v; 385 412 } 386 newSlice = ""; 387 isSlice = false; 388 } else if (d==',' && numbracks==1) { 389 if (isSlice && numSlicesRemaining>0) { 390 v = "[" ~ newSlice 391 ~ "].length"; 392 --numSlicesRemaining; 393 } else { 394 v = "[" ~ newSlice ~ "]" ~ v; 395 } 396 newSlice = ""; 413 nextIndex = ""; 397 414 isSlice = false; 398 415 } else { 399 if (d>='A' && d<='Z') ne wSlice = tree.symbolTable[d-'A'].value ~ newSlice;400 else ne wSlice = d ~newSlice;416 if (d>='A' && d<='Z') nextIndex = tree.symbolTable[d-'A'].value ~ nextIndex; 417 else nextIndex = d ~ nextIndex; 401 418 } 402 419 } … … 482 499 483 500 // Convert the compound expression str back into its values. 484 char [] getValueForCompoundExpression(char [] str, Symbol[] table)501 char [] reconstituteCompoundExpression(char [] str, Symbol[] table) 485 502 { 486 503 char [] v = ""; trunk/blade/BladeDemo.d
r154 r155 15 15 // cdouble[] always remains aligned, even when sliced. 16 16 17 18 17 19 18 void main() 20 19 { … … 33 32 double [4][] another = [[33.1, 4543, 43, 878.7], [5.14, 455, 554, 2.43]]; 34 33 real k=3.4; 35 34 36 35 mixin(vectorize(` a += (d[2..$-1]*2.01*a[2]-another[][1])["abc".length-3..$]`)); 37 /+36 38 37 mixin(vectorize(" a-= 2.01*( 3.04+k)*r")); 39 38 mixin(vectorize("q+= q*2.01")); … … 43 42 mixin(vectorize("a+=6*another[1]")); 44 43 mixin(vectorize("a+=6*another[1][]")); 45 +/ 46 mixin(vectorize("another[0..$,1]+=6*a[0..$-2]")); 44 45 mixin(vectorize("another[0..$,1]+=6*a[0..2]")); 46 mixin(vectorize("r-=another[0]")); 47 47 48 48 // Parses OK, but I don't think I'll support this. 49 49 // mixin(vectorize("a+=6*another[1,[1,$]]")); 50 50 51 //mixin(vectorize("dot(q,q*dot(q,q))")); // should simplify to: dot(q.q) * dot(q,q) 51 52 // Parses, and rank checks OK. Doesn't simplify yet, no codegen. 53 // mixin(vectorize("dot(q,q*dot(q,q))")); // BUG: should simplify to: dot(q.q) * dot(q,q) 52 54 53 55 writefln("a=", a); trunk/blade/BladeRank.d
r153 r155 221 221 right = end; 222 222 } 223 224 223 if (z==right.length-1) return totrank; 225 224 right = right[z+2..$]; trunk/blade/BladeSimplify.d
r153 r155 226 226 } 227 227 228 // Allows [a,[b,c],d ] syntax for indices, where [b,c] is a range.228 // Allows [a,[b,c],d..e,f] syntax for indices, where [b,c] is a range. 229 229 int indexRank(char [] s) 230 230 { … … 320 320 assert(exprSimplify("A=(((B*E)+(C*E))*D)", "11100","","")=="(A=(( {(D*E)} *B)+( {(D*E)} *C)))"); 321 321 assert(exprSimplify("A=(D*((B*E)+(C*E)))", "11100","","")=="(A=(( {(D*E)} *B)+( {(D*E)} *C)))"); 322 // assert(exprSimplify("d(A,A*d(A,A))", "1", "","") == "d(A,A)*d(A,A)"); 322 323 323 324 RevisedExpression e = simplifyVectorExpression("A+=(((D[B])*C)[B])", "2004"); trunk/blade/CodegenX86.d
r145 r155 266 266 const int MAX_X87_VECTORS = vectorRegister.length; 267 267 const int MAX_SSE_VECTORS = vectorRegister.length; 268 // Maximum number of real scalars allowable in an expression ( 269 // (max # temporaries + max # real scalars) must be <=8, otherwise FPU stack 270 // will overflow). 271 const int MAX_87_REALSCALARSPLUSTEMPORARIES = 8; 268 272 269 273 private:
