Live data from Hacker News

GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

rodrigodd.github.io

11–20 of 21 posts

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#11

I feel like I've seen the trick of estimating upcoming interrupts before somewhere...was it mednafen or higan? Anyways cool post! How come you don't consider conditional branches to be terminating instructions of your basic blocks?

QEMU does something like this in TCG code when running in icount mode.

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#12
post #9

One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ , which uses a much cheaper/faster, but also not cryptographically secure, hashing algorithm. For these purposes, I doubt the hashing algorithm weakness would be an issue.

Why the hell would a HashMap use a cryptographically secure hash?

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#13
Very nice! I've been working on a Dreamcast emulator for a long time and a lot of the issues you mentioned around deterministic behavior echoed. Schedulers are fantastic, and we landed on the same concept.

You mentioned that you do a hash map look for each (bank,addr) key. Suggestion which helped us: have this point to an Netey which contains the JIT code but also an index/pointer into the next block which executed last time you executed this block. You can do a simple check to see if this is still valid and fall back to the hashmap lookup. If you're careful about code invalidation (not an issue with ROM) then this can help skip the next lookup.

Congrats!

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#14
post #9

One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ , which uses a much cheaper/faster, but also not cryptographically secure, hashing algorithm. For these purposes, I doubt the hashing algorithm weakness would be an issue.

Why the hell would a HashMap use a cryptographically secure hash?

I believe rust’s hashmap does have an implementation that is immune to timing-based attacks and that does have a performance cost. Maybe that’s what parent mixed it up with.

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#15
post #9

One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ , which uses a much cheaper/faster, but also not cryptographically secure, hashing algorithm. For these purposes, I doubt the hashing algorithm weakness would be an issue.

Why the hell would a HashMap use a cryptographically secure hash?

HashMap uses SipHash. To call it cryptographically secure is not a clear way of summarizing what it provides. See Wikipedia for more info. Blurb:

> It was designed to be efficient even for short inputs, with performance comparable to non-cryptographic hash functions, such as CityHash, this can be used to prevent denial-of-service attacks against hash tables ("hash flooding") [...]

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#16
post #15

Earlier quoted context omitted.

Why the hell would a HashMap use a cryptographically secure hash?

HashMap uses SipHash. To call it cryptographically secure is not a clear way of summarizing what it provides. See Wikipedia for more info. Blurb: > It was designed to be efficient even for short inputs, with performance comparable to non-cryptographic hash functions, such as CityHash, this can be used to prevent denial-of-service attacks against hash tables ("hash flooding") [...]

> "hash flooding"

I did not know this was a thing. What a massive amount of engineering effort is being wasted on protecting against outlandish attacks!

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#17
Fascinating read. In the past few months I started work on a Game Boy emulator in Swift, and although it’s still very early days (got the boot ROM logo displaying but not much else) it’s been a very fun and rewarding project.

A JIT is something I’d been wondering about for a bit, and this post was eye-opening about the complexities involved (I have no real compiler background).

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#18
post #9

One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ , which uses a much cheaper/faster, but also not cryptographically secure, hashing algorithm. For these purposes, I doubt the hashing algorithm weakness would be an issue.

I am already using a non-cryptographic hasher. In fact, I am not doing any hashing at all, I am just assuming that the input is already random enough, and use a Hasher that just copies the input to output. But I still didn't measure the performance of that, so that may be something silly to do.

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#19

I feel like I've seen the trick of estimating upcoming interrupts before somewhere...was it mednafen or higan? Anyways cool post! How come you don't consider conditional branches to be terminating instructions of your basic blocks?

> How come you don't consider conditional branches to be terminating instructions of your basic blocks?

Initially I was doing that, but it was making tight loops too slow. And what I am referring to as a "block" was not a basic block, but a entire compilation unit.

Re: GameRoy: JIT Compilation in High-Accuracy Game Boy Emulation

#20
post #9

One "cheap" performance boost you could probably get is replacing your HashMaps with FxHashMap, https://docs.rs/fxhash/latest/fxhash/ , which uses a much cheaper/faster, but also not cryptographically secure, hashing algorithm. For these purposes, I doubt the hashing algorithm weakness would be an issue.

I am already using a non-cryptographic hasher. In fact, I am not doing any hashing at all, I am just assuming that the input is already random enough, and use a Hasher that just copies the input to output. But I still didn't measure the performance of that, so that may be something silly to do.

Sorry, in the blog post you were talking about the HashMap being expensive, and I didn't spot one of the usual "cheap" hashing libraries being in use. That's where I got wondering if you'd missed an easy boost.
Post reply on HN