• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
  • entries
    625
  • comments
    1446
  • views
    1006530

Epoch runtime: now with StupidFast

Sign in to follow this  
Followers 0
ApochPiQ

1785 views

Did some more experimentation with LLVM and Epoch's JIT system; and damn I am pleased with the results.

After finally muddling through enough of the llvm-opt source code to figure out how to order all the optimization passes that LLVM offers, I got a lot of basic optimization and dead-code elimination working on the bitcode that the Epoch VM JITs out. The single biggest contributor to the new-found speed, though, is my addition of simple flow control to the native code emitter.

In a nutshell, this means you can write while() loops in Epoch code that is tagged as [native]. The practical upshot of this is that loop unrolling and constant propagation can now apply to Epoch code, thanks to LLVM. In turn, this means that my nice little brute-force benchmark from the last few days is basically now a couple of multiplications and nothing else.


To recap, here's the modified benchmark using native-code-generation of loops:

//
// JIT.EPOCH
//
// Just in time compilation test for Epoch
//


timeGetTime : -> integer ms = 0 [external("WinMM.dll", "timeGetTime")]


entrypoint :
{
integer four = 1 + 3
assert(four == 4)

vmbench(2, 3)
jitbench(2, 3)
}


vmbench : integer a, integer b
{
integer begintime = timeGetTime()
integer result = vmmath(a, b)
integer duration = timeGetTime() - begintime
string durationstr = cast(string, duration)
print("VM benchmark lasted: " ; durationstr)
string resultstr = cast(string, result)
print("Result: " ; resultstr)
}


jitbench : integer a, integer b
{
integer begintime = timeGetTime()
integer result = jitmath(a, b)
integer duration = timeGetTime() - begintime
string durationstr = cast(string, duration)
print("JIT benchmark lasted: " ; durationstr)
string resultstr = cast(string, result)
print("Result: " ; resultstr)
}


vmmath : integer a, integer b -> integer ret = 0
{
integer counter = 0
integer result = 0

while(counter < 1000000)
{
result = a * b
ret = ret + result
counter = counter + 1
}
}


jitmath : integer a, integer b -> integer ret = 0 [native]
{
integer counter = 0
integer result = 0

while(counter < 1000000)
{
result = a * b
ret = ret + result
counter = counter + 1
}
}



Since the two seed values come from outside LLVM's scope of knowledge, it can't quite turn the benchmark into a no-op, but it can get it down to this:

; ModuleID = 'EpochJIT_4181'

define void @dostuff(i32, i32) nounwind {
entry:
%2 = inttoptr i32 %0 to i32**
%3 = load i32** %2, align 4
%4 = load i32* %3, align 4
%5 = getelementptr i32* %3, i32 1
%6 = load i32* %5, align 4
%7 = mul i32 %6, %4
%8 = mul i32 %7, 1000000
store i32 %8, i32* %5, align 4
store i32* %5, i32** %2, align 4
ret void
}


In the quite-likely scenario that you haven't memorized LLVM's assembly syntax, here's what's going on:

  • We have a comment indicating that this is an Epoch-JIT module
  • There's a function definition indicating that the JITted function takes two parameters and returns void
  • There's an entry-point label for the function
  • We take the 0th parameter to the function and cast it from a 32-bit integer to an int** (in C parlance)
  • We then dereference this to get an int*, which is the stack pointer from the VM
  • Next we load the value off the stack into a local register
  • Then we increment the stack pointer by one int
  • ...and grab another value off the VM stack into a local register
  • Then multiply the two values
  • Then multiply by 1 million to account for the loop that used to be there
  • Then we store the result back onto the VM's stack, as it expects
  • Lastly, we update the VM's stack pointer
  • And return!



    Here's a dump of running the new JIT test:

    Epoch Language Project
    Command line tools interface

    Executing: D:/Epoch/Programs/JIT Tests/jit.epoch

    Parsing... finished in 7ms
    Validating semantics... finished in 2ms with 0 error(s)
    Generating code... finished in 0ms

    DEBUG: VM benchmark lasted: 3780
    DEBUG: Result: 6000000
    DEBUG: JIT benchmark lasted: 0
    DEBUG: Result: 6000000


    That's right... counting to 6 million takes the VM 3.78 seconds, and the JITted native code is so fast it can't even be measured by the benchmark. Which stands to reason, considering it's just a couple of imul instructions.


    I now stand by my tentative decision to complete deprecate the VM as an execution model. I might keep it as a convenient IR for code and as a jumping-off-point for the JITter, but... going from over 3 seconds to unmeasurably fast is just too cool to pass up. There's really no major wins to be had in hacking on the VM anymore if I can get such excellent performance from JITted code and invest my time in making the JITter more powerful instead.


    Next up, I need to do some major refactoring of the JITter and make it not... suck. Then I'll see about finishing up the remaining work items for R12, and kick that puppy out the door.


    Woot!

1
Sign in to follow this  
Followers 0


1 Comment


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now