Browse Source

PPC: Add helper function for folding arithmetic ops.

Mike Pall 15 years ago
parent
commit
b2aa08c75c
1 changed files with 27 additions and 1 deletions
  1. 27 1
      src/buildvm_ppc.dasc

+ 27 - 1
src/buildvm_ppc.dasc

@@ -981,7 +981,33 @@ static void build_subroutines(BuildCtx *ctx)
   |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -)
   |// Compute x op y for basic arithmetic operators (+ - * / % ^ and unary -)
   |// and basic math functions. ORDER ARITH
   |// and basic math functions. ORDER ARITH
   |->vm_foldarith:
   |->vm_foldarith:
-  |  NYI
+  |  evmergelo CARG2, CARG1, CARG2
+  |   cmplwi CARG5, 1
+  |  evmergelo CARG4, CARG3, CARG4
+  |   beq >1; bgt >2
+  |  efdadd CRET2, CARG2, CARG4; evmergehi CRET1, CRET2, CRET2; blr
+  |1:
+  |  efdsub CRET2, CARG2, CARG4; evmergehi CRET1, CRET2, CRET2; blr
+  |2:
+  |   cmplwi CARG5, 3; beq >1; bgt >2
+  |  efdmul CRET2, CARG2, CARG4; evmergehi CRET1, CRET2, CRET2; blr
+  |1:
+  |  efddiv CRET2, CARG2, CARG4; evmergehi CRET1, CRET2, CRET2; blr
+  |2:
+  |   cmplwi CARG5, 5; beq >1; bgt >2
+  |  evmr CARG3, CARG2; efddiv CRET2, CARG2, CARG4
+  |  mflr SAVE0; bl ->vm_floor; mtlr SAVE0
+  |  efdmul CRET2, CRET2, CARG4; efdsub CRET2, CARG3, CRET2
+  |  evmergehi CRET1, CRET2, CRET2; blr
+  |1:
+  |  b extern pow
+  |2:
+  |   cmplwi CARG5, 7; beq >1; bgt >2
+  |  xoris CARG1, CARG1, 0x8000; blr
+  |1:
+  |  rlwinm CARG1, CARG1, 0, 1, 31; blr
+  |2:
+  |  NYI  // Other operations only needed by JIT compiler.
   |
   |
   |//-----------------------------------------------------------------------
   |//-----------------------------------------------------------------------
   |//-- Miscellaneous functions --------------------------------------------
   |//-- Miscellaneous functions --------------------------------------------