(12-18-2008, 10:22 PM)heftig Wrote: VM means Virtual Memory.
TLB apparently means Translation Lookaside Buffer, which is a (nowadays hardware) feature to speed up virtual address translation. So, TLB is a feature to speed up VM.
Now, the labeling of the two versions confuses me. Just what is the TLB version doing differently from the VM version?
The TLB version is named such pretty much because it's just a straight up emulation of the PS2's TLB; so the "TLB" is referring to the PS2's TLB. The VM version is named such because it uses your operating system's virtual memory to simplify the code needed to emulate the PS2's TLB; so the "VM" is referring to your computer's own virtual memory system.
The VM version is faster for Pcsx2 for the same reasons it's faster to use VM on the PS2. It simplifies the code by allowing the programmer to make assumptions regarding memory addresses. So, for example, references to an allocated memory block can simply be accessed with a
constant value instead of a dynamically assigned variable.
Normally, an allocation works like this:
char* buffer = malloc( datasize );
*(buffer+32) = value;
... where-by the buffer is located "somewhere" in memory -- a location picked by malloc and which could be picked differently every time the app runs. That location must be loaded into a cpu register and offset by 32 to access the element. Under VM, you can specify the exact location of the buffer as a hard-coded value:
char* buffer = VM_MapMemory( 0x05000, datasize );
*(0x05032) = value;
This code uses a single constant expression instead, 0x5032, which bypasses both loading the "buffer" address into a cpu register, and offsetting it by 32. So it generates smaller and faster code.
This is how the VM system in Pcsx2 works, more or less. But it has drawbacks also, one of which is the fact that it doesn't always initialize on everyone's computers (depending on operating system and drivers), and it also limits our ability to provide full-on proper emulation of the PS2's TLB implementation. Perhaps though, most importantly, is that it's really not that big of a speedup as far as our x86/x64 CPUs are concerned. The current VM build is faster then the current TLB build partly for the benefits of VM, but more so because the VM build is coded better and utilizes a full suite of recompiler optimizations. If the TLB build were implemented properly, the real difference in speed between the two would likely be around 5% on most games.
.. but emulation quality would be better, the recompiler would be easier to maintain and debug, and Pcsx2 would be a sure bet to start and run on everyone's PC without tossing VM alloc errors or making you log off or restart.
So it's probably not a bad idea.