Skip to content

Commit

Permalink
missed refactoring plus doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Jul 5, 2015
1 parent 40c3f03 commit d75af6a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
44 changes: 23 additions & 21 deletions readthedocs/ravi-benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ Ravi's reason for existence is to achieve greater performance than standard Lua

The programs used in the performance testing can be found at `Ravi Tests <https://github.com/dibyendumajumdar/ravi/tree/master/ravi-tests>`_ folder.

+---------------+---------+------------+-----------------------+------------+
| Program | Lua5.3 | Ravi(LLVM) | Ravi (gccjit;guest VM)| Luajit 2.1 |
+===============+=========+============+=======================+============+
|fornum_test1 | 9.187 | 0.305 | 0.000001 (VM) | 0.309 |
+---------------+---------+------------+-----------------------+------------+
|fornum_test2 | 9.57 | 0.922 | 0.939 (VM) | 0.906 |
+---------------+---------+------------+-----------------------+------------+
|fornum_test3 | 53.932 | 4.593 | | 7.778 |
+---------------+---------+------------+-----------------------+------------+
|mandel(4000) | 21.247 | 2.94 | 3.09 (VM) | 1.633 |
+---------------+---------+------------+-----------------------+------------+
|fannkuchen(11) | 63.446 | 8.875 | 10.678 (VM) | 4.751 |
+---------------+---------+------------+-----------------------+------------+
|matmul(1000) | 34.604 | 4.2 | | 0.968 |
+---------------+---------+------------+-----------------------+------------+
+---------------+---------+------------+------------+
| Program | Lua5.3 | Ravi(LLVM) | Luajit 2.1 |
+===============+=========+============+============+
|fornum_test1 | 9.187 | 0.31 | 0.309 |
+---------------+---------+------------+------------+
|fornum_test2 | 9.57 | 0.917 | 0.906 |
+---------------+---------+------------+------------+
|fornum_test3 | 53.932 | 4.598 | 7.778 |
+---------------+---------+------------+------------+
|mandel(4000) | 21.247 | 2.936 | 1.633 |
+---------------+---------+------------+------------+
|fannkuchen(11) | 63.446 | 8.317 | 4.751 |
+---------------+---------+------------+------------+
|matmul(1000) | 34.604 | 2.942 | 0.968 |
+---------------+---------+------------+------------+

Following points are worth bearing in mind when looking at above benchmarks.

Expand All @@ -28,9 +28,7 @@ Following points are worth bearing in mind when looking at above benchmarks.
/ two stores. Luajit has a performance advantage when it comes to floating
point operations due to this.

2. More work is needed to optimize fornum loops in Ravi. I have some
ideas on what can be improved but have parked this for now as I want
to get more coverage of Lua bytecodes first.
2. More work is needed to optimize numeric operations in Ravi.

3. Luajit compilation approach ensures that it can use information about
the actual execution path taken by the code at runtime whereas Ravi
Expand All @@ -40,14 +38,18 @@ Following points are worth bearing in mind when looking at above benchmarks.
But LuaJIT timings include the JIT compilation times, so they show
incredible performance.

5. The benchmarks were run on Windows 8.1 64-bit except for the libgccjit 5.1
benchmarks which were run on a Ubuntu 64-bit VM running on Windows 8.1.
LLVM version 3.7 was used.
5. The benchmarks were run on Windows 8.1 64-bit. LLVM version 3.7 was used.

6. The Ravi benchmarks are based on code that uses optional static types.

Ideas
-----
There are a number of improvements possible. Below are some of my thoughts.

Allocating variables on C stack
-------------------------------
Certain local and temporary variables that hold numeric values could be allocated on the C stack avoiding the overhead of accessing the Lua stack. This requires implementing escape analysis to determine which variables are safe to be allocated on the C stack.

Optimizing Fornum loops
-----------------------
The Lua fornum loops create an `extra "external" variable <http://www.lua.org/manual/5.3/manual.html#3.3.5>`_ that has the name given by the user.
Expand Down
9 changes: 3 additions & 6 deletions src/ravi_llvmforprep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, int A, int pc) {
def->builder->SetInsertPoint(else1_pstep);
llvm::Instruction *nlimit_load = emit_load_local_n(def, nlimit);

emit_store_reg_n(def, nlimit_load, plimit);
emit_store_type(def, plimit, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, nlimit_load, plimit);

// *********** PSTEP - convert pstep to float
// Test if already a float
Expand Down Expand Up @@ -639,8 +638,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, int A, int pc) {

llvm::Instruction *nstep_load = emit_load_local_n(def, nstep);

emit_store_reg_n(def, nstep_load, pstep);
emit_store_type(def, pstep, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, nstep_load, pstep);

// *********** PINIT finally handle initial value

Expand Down Expand Up @@ -692,8 +690,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, int A, int pc) {
llvm::Value *init_n =
def->builder->CreateFSub(ninit_load, nstep_load, "ninit-nstep");

emit_store_reg_n(def, init_n, init);
emit_store_type(def, init, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, init_n, init);

// Done so jump to forloop
def->builder->CreateBr(def->jmp_targets[pc].jmp1);
Expand Down

0 comments on commit d75af6a

Please sign in to comment.