diff options
| author | Drahflow <drahflow@gmx.de> | 2013-10-22 22:54:11 +0200 |
|---|---|---|
| committer | Drahflow <drahflow@gmx.de> | 2013-10-22 22:54:11 +0200 |
| commit | 1ed4d0703d433fb44fc9a38dc8a0a190a1aac54b (patch) | |
| tree | 2d0c20d2b99d999739f3c0a49f241c21fc3e63bb | |
| parent | 36db2558acb7fee6f4e575963b340bdd76143045 (diff) | |
Optimizations
| -rw-r--r-- | compiler/elymasGlobal.ey | 48 | ||||
| -rw-r--r-- | elymas/lib/sys/opt.ey | 68 |
2 files changed, 112 insertions, 4 deletions
diff --git a/compiler/elymasGlobal.ey b/compiler/elymasGlobal.ey index 9ba92c9..cca3ad6 100644 --- a/compiler/elymasGlobal.ey +++ b/compiler/elymasGlobal.ey @@ -1869,6 +1869,19 @@ # /r15 -> first part # 8 /r15 -> second part + # check loop parts for being functions + /r15 /rsi :movqMemReg + 7 /rsi /cl :movbMemDisp8Reg + %F0 /cl :andbImmReg + %50 /cl :cmpbImmReg + /loop :jnzLbl8 + 8 /r15 /rdi :movqMemDisp8Reg + 7 /rdi /cl :movbMemDisp8Reg + %F0 /cl :andbImmReg + %50 /cl :cmpbImmReg + /loop :jnzLbl8 + /functionLoop :jmpLbl8 + @loop /r15 :pushqMem |ey* /rax :movqImmReg @@ -1891,6 +1904,41 @@ /r15 :pushqMem 8 /r15 :addqImm8Reg :retn + + @functionLoop + # check loop parts for being non-typed + 16 /rsi /rax :movqMemDisp8Reg + 16 /rdi /rax :orqMemDisp8Reg + /nonTypedLoop :jzLbl8 + /loop :jmpLbl8 # TODO: maybe put a faster version here one day + + @nonTypedLoop + # check loop parts for being non-capturing + 8 /rsi /rax :movqMemDisp8Reg + 8 /rdi /rax :orqMemDisp8Reg + /nonCapturingLoopEntry :jzLbl8 + /loop :jmpLbl8 # TODO: here should follow a significantly faster version already + + @nonCapturingLoopEntry + 24 /rsi /rsi :movqMemDisp8Reg + 24 /rdi /rdi :movqMemDisp8Reg + 16 /rsi :addqImm8Reg + 16 /rdi :addqImm8Reg + /rsi /r15 :movqRegMem + /rdi 8 /r15 :movqRegMemDisp8 + + @nonCapturingLoop + /r15 /rax :movqMemReg + /rax :callqReg + + /rax :popqReg + /rax ::unboxInteger + /rax /rax :testqRegReg + /end :jzLbl8 + + 8 /r15 /rax :movqMemDisp8Reg + /rax :callqReg + /nonCapturingLoop :jmpLbl8 ]] /eyloop defv # a foreach loop diff --git a/elymas/lib/sys/opt.ey b/elymas/lib/sys/opt.ey index d07a5e7..72f1897 100644 --- a/elymas/lib/sys/opt.ey +++ b/elymas/lib/sys/opt.ey @@ -133,6 +133,7 @@ /ARRAYSTAR ==:ARRAYSTAR /UNTYPEDSCOPEDSTAR ==:UNTYPEDSCOPEDSTAR /UNTYPEDUNSCOPEDSTAR ==:UNTYPEDUNSCOPEDSTAR + /STRINGSTAR ==:STRINGSTAR { =*f ==t t { f } { 0 } ? * @@ -368,7 +369,9 @@ type [ { "failed to optimize 'execution' of integer typed object" die } - { } # TODO string case + { + [ STRINGSTAR ] i logic =[] + } { "failed to optimize 'execution' of scope typed object" die } { "failed to optimize 'execution' of name table" die } { "failed to optimize 'execution' of extension area" die } @@ -402,10 +405,50 @@ } each } /rewriteConstantStar deffst + { _ ==logic + 3 logic len range { ==i i logic * ==entry 0 entry * ==action i 1 sub logic * ==last i 2 sub logic * ==secondLast i 3 sub logic * ==thirdLast + [ + { action CALL streq + { 1 entry * "*" | ::rawCodeAddress eq }' andif + { 0 last * CALL streq }' andif + { 1 last * "?" | ::rawCodeAddress eq }' andif + { 0 secondLast * PUSH streq }' andif + { 0 thirdLast * PUSH streq }' andif + { 1 secondLast * ::rawObject sys .typed .type 5 eq }' andif + { 1 thirdLast * ::rawObject sys .typed .type 5 eq }' andif + { 1 secondLast * ::rawObject sys .typed .inputs len not }' andif # TODO: think about typed functions + { 1 thirdLast * ::rawObject sys .typed .inputs len not }' andif # TODO: think about typed functions + }' { + 1 secondLast * ::rawObject sys .capturedScope _ { -01 -- } { } ? * ==hasScope + 1 thirdLast * ::rawObject sys .capturedScope _ { -01 -- } { } ? * hasScope or =hasScope + + hasScope { + [ UNTYPEDSCOPEDSTAR ] i logic =[] + } { + [ UNTYPEDUNSCOPEDSTAR ] i logic =[] + } ? * + } + ] conds + } each + } /rewriteConstantQuestionStar deffst + { ==logic [ NOP ] ==last [ logic { ==entry 0 entry * ==action [ + { action CALL streq { 1 entry * "?" | ::rawCodeAddress eq }' andif }' { + [ NATIVE [ + /rcx :popqReg + /rdx :popqReg + /rax :popqReg + 63 /rax :btrqImm8Reg + [ 8 /rax /rax :movqMemDisp8Reg ] len :jcRel8 + 8 /rax /rax :movqMemDisp8Reg + /rax /rax :testqRegReg + /rcx /rdx :cmovzqRegReg + /rdx :pushqReg + ] ] =entry + } { action CALL streq { 1 entry * "_" | ::rawCodeAddress eq }' andif }' { [ NATIVE [ 0 /rsp :pushqMemDisp8 @@ -454,7 +497,7 @@ last entry =last } each last ] - } /rewriteStackOps deffst + } /rewriteSimpleFunctions deffst sys .asm "::" via sys .asm .|peek ==:peek @@ -636,9 +679,10 @@ rewriteConstantEquals } rep rewriteConstantDot - rewriteArithmetics rewriteConstantStar - rewriteStackOps + rewriteConstantQuestionStar + rewriteArithmetics + rewriteSimpleFunctions { =*entry 0 entry ==action [ { action PUSH streq }' { @@ -785,6 +829,22 @@ ] emitOpcodes } + { action STRINGSTAR streq }' { + [ + /rsi :popqReg + /rax :popqReg + 63 /rax :btrqImm8Reg + [ 8 /rax /rax :movqMemDisp8Reg ] len :jcRel8 + 8 /rax /rax :movqMemDisp8Reg + 16 /rsi /rcx :movqMemDisp8Reg + /rdx /rdx :xorqRegReg + /rcx :divqReg + 24 1 /rdx /rsi /rbx :movzxMem8IndexScaleDisp8Reg64 + 63 /rbx :btsqImm8Reg + /rbx :pushqReg + ] emitOpcodes + } + { action NATIVE streq }' { 1 entry emitOpcodes } |
