private static void RotateUnmatchedRegisters(ref string s, UnwrappedElement el) { int a = 0; char reg = '\0'; for (int i = 0; i < s.Length; i++) { if (s[i] == '(' && s[i + 1] != '(') { reg = s[i + 1]; break; } } for (int i = 0; i < s.Length - 2; i++) { if (s[i] == '(') { while (el.stuff[a++] != '(') { } } if (s[i] != '(' && s[i] != ')' && s[i] != reg && (s[i + 1] == '*' || s[i + 1] == '+') && s[i + 2] == reg) { string s2 = s; s2 = s2.Remove(i, 1); s2 = s2.Insert(i, "" + s[i + 2]); s2 = s2.Remove(i + 2, 1); s2 = s2.Insert(i + 2, "" + s[i]); s = s2; s2 = ""; string s3 = ""; string s4 = ""; int b; int c; b = a; while (el.stuff[a] != ']') { s2 += el.stuff[a++]; } c = a; s2 += ']'; s4 += el.stuff[a++]; s4 += el.stuff[a++]; while (el.stuff[a] != ']') { s3 += el.stuff[a++]; } a++; el.stuff = el.stuff.Remove(b, a - b); el.stuff = el.stuff.Insert(b, s3 + s4 + s2); } } }
private static void VectorMatchSplit(VectorMatch vm) { int tempofset = vm.Offset; string[] calcs = new string[vm.Count]; string[] rcalcs = new string[vm.Count]; //Generate calcs and rcalcs for (int i = 0; i < vm.Count; i++) { calcs[i] = ParseScalarCalc(((UnwrappedElement)elements[vm.Start + i]).stuff); rcalcs[i] = ParseScalarCalcWithReg(((UnwrappedElement)elements[vm.Start + i]).stuff); } //Rotate the registers to try and match up rcalcs RotateUnmatchedRegisters(ref rcalcs[0], (UnwrappedElement)elements[vm.Start]); for (int i = 1; i < vm.Count; i++) { if (calcs[i] == calcs[i - 1]) { if (rcalcs[i] != rcalcs[i - 1]) { if (!RotateDeepRegisters(ref rcalcs[i], rcalcs[i - 1], (UnwrappedElement)elements[vm.Start + i])) { RotateUnmatchedRegisters(ref rcalcs[i], (UnwrappedElement)elements[vm.Start + i]); } } } } //Split vectors wherever rcalcs dont match up int start = 0; for (int i = 1; i < vm.Count; i++) { if (rcalcs[i] != rcalcs[i - 1]) { if (i > start + 1) { UnwrappedElement[] o = new UnwrappedElement[i - start + 1]; elements.CopyTo(start + vm.Start, o, 0, i - start + 1); FoundVectors.Add(new VectorMatch(start + vm.Start, i - start + 1, vm.Upward, o, vm.Offset, vm.Reg)); } start = i; Offset = ((UnwrappedElement)elements[i + vm.Start]).Offset; } } if (start < vm.Count - 1) { UnwrappedElement[] o = new UnwrappedElement[vm.Count - start]; elements.CopyTo(start + vm.Start, o, 0, vm.Count - start); FoundVectors.Add(new VectorMatch(start + vm.Start, vm.Count - start, vm.Upward, o, Offset, vm.Reg)); } }
private static bool RotateDeepRegisters(ref string s, string t, UnwrappedElement el) { int a = 0; for (int i = 0; i < s.Length - 2; i++) { if (s[i] == '(') { while (el.stuff[a++] != '(') { } } if (s[i] != '(' && s[i] != ')' && (s[i + 1] == '*' || s[i + 1] == '+') && s[i + 2] != '(' && s[i + 2] != ')') { string s2 = s; s2 = s2.Remove(i, 1); s2 = s2.Insert(i, "" + s[i + 2]); s2 = s2.Remove(i + 2, 1); s2 = s2.Insert(i + 2, "" + s[i]); if (s2[i] == t[i] && s2[i + 2] == t[i + 2]) { s = s2; s2 = ""; string s3 = ""; string s4 = ""; int b; int c; b = a; while (el.stuff[a] != ']') { s2 += el.stuff[a++]; } c = a; s2 += ']'; s4 += el.stuff[a++]; s4 += el.stuff[a++]; while (el.stuff[a] != ']') { s3 += el.stuff[a++]; } a++; el.stuff = el.stuff.Remove(b, a - b); el.stuff = el.stuff.Insert(b, s3 + s4 + s2); } } } return(s == t); }
public VectorMatch(int start,int count,bool upward,UnwrappedElement[] elements,int offset,string reg) { fpulines=null; Offset=offset; Reg=reg; Start=start; Count=count; Upward=upward; calc=vectorizer.ParseMarkedScalarCalc(elements[0].stuff); arguments=new Element[elements.Length][]; for(int i=0;i<elements.Length;i++) { arguments[i]=GetArgs(elements[i].stuff); } pArguments=null; }
private static void VectorMatchSplit(VectorMatch vm) { int tempofset=vm.Offset; string[] calcs=new string[vm.Count]; string[] rcalcs=new string[vm.Count]; //Generate calcs and rcalcs for(int i=0;i<vm.Count;i++) { calcs[i]=ParseScalarCalc(((UnwrappedElement)elements[vm.Start+i]).stuff); rcalcs[i]=ParseScalarCalcWithReg(((UnwrappedElement)elements[vm.Start+i]).stuff); } //Rotate the registers to try and match up rcalcs RotateUnmatchedRegisters(ref rcalcs[0],(UnwrappedElement)elements[vm.Start]); for(int i=1;i<vm.Count;i++) { if(calcs[i]==calcs[i-1]) { if(rcalcs[i]!=rcalcs[i-1]) { if(!RotateDeepRegisters(ref rcalcs[i],rcalcs[i-1],(UnwrappedElement)elements[vm.Start+i])) { RotateUnmatchedRegisters(ref rcalcs[i],(UnwrappedElement)elements[vm.Start+i]); } } } } //Split vectors wherever rcalcs dont match up int start=0; for(int i=1;i<vm.Count;i++) { if(rcalcs[i]!=rcalcs[i-1]) { if(i>start+1) { UnwrappedElement[] o=new UnwrappedElement[i-start+1]; elements.CopyTo(start+vm.Start,o,0,i-start+1); FoundVectors.Add(new VectorMatch(start+vm.Start,i-start+1,vm.Upward,o,vm.Offset,vm.Reg)); } start=i; Offset=((UnwrappedElement)elements[i+vm.Start]).Offset; } } if(start<vm.Count-1) { UnwrappedElement[] o=new UnwrappedElement[vm.Count-start]; elements.CopyTo(start+vm.Start,o,0,vm.Count-start); FoundVectors.Add(new VectorMatch(start+vm.Start,vm.Count-start,vm.Upward,o,Offset,vm.Reg)); } }
private static void RotateUnmatchedRegisters(ref string s,UnwrappedElement el) { int a=0; char reg='\0'; for(int i=0;i<s.Length;i++) { if(s[i]=='('&&s[i+1]!='(') { reg=s[i+1]; break; } } for(int i=0;i<s.Length-2;i++) { if(s[i]=='(') { while(el.stuff[a++]!='(') { } } if(s[i]!='('&&s[i]!=')'&&s[i]!=reg&&(s[i+1]=='*'||s[i+1]=='+')&&s[i+2]==reg) { string s2=s; s2=s2.Remove(i,1); s2=s2.Insert(i,""+s[i+2]); s2=s2.Remove(i+2,1); s2=s2.Insert(i+2,""+s[i]); s=s2; s2=""; string s3=""; string s4=""; int b; int c; b=a; while(el.stuff[a]!=']') { s2+=el.stuff[a++]; } c=a; s2+=']'; s4+=el.stuff[a++]; s4+=el.stuff[a++]; while(el.stuff[a]!=']') { s3+=el.stuff[a++]; } a++; el.stuff=el.stuff.Remove(b,a-b); el.stuff=el.stuff.Insert(b,s3+s4+s2); } } }
private static bool RotateDeepRegisters(ref string s,string t,UnwrappedElement el) { int a=0; for(int i=0;i<s.Length-2;i++) { if(s[i]=='(') { while(el.stuff[a++]!='(') { } } if(s[i]!='('&&s[i]!=')'&&(s[i+1]=='*'||s[i+1]=='+')&&s[i+2]!='('&&s[i+2]!=')') { string s2=s; s2=s2.Remove(i,1); s2=s2.Insert(i,""+s[i+2]); s2=s2.Remove(i+2,1); s2=s2.Insert(i+2,""+s[i]); if(s2[i]==t[i]&&s2[i+2]==t[i+2]) { s=s2; s2=""; string s3=""; string s4=""; int b; int c; b=a; while(el.stuff[a]!=']') { s2+=el.stuff[a++]; } c=a; s2+=']'; s4+=el.stuff[a++]; s4+=el.stuff[a++]; while(el.stuff[a]!=']') { s3+=el.stuff[a++]; } a++; el.stuff=el.stuff.Remove(b,a-b); el.stuff=el.stuff.Insert(b,s3+s4+s2); } } } return s==t; }