Wednesday, December 24, 2008

Need for Speed Carbon

As a Christmas treat, I bought myself Need for Speed Carbon (Mac OS X version). It turns out they used TransGaming Cider, a derivative of the WINE project, to port the game. I don't have a Windows version of the game to compare, but it looks like they stored a fully-installed Windows version of the game under "Need for Speed Carbon.app/Contents/Resources/Need For Speed Carbon.app/Contents/Resources/transgaming/c_drive". The second "Need For Speed Carbon.app" is the actual game executable. The top-level one is just an annoying game serial number checking wrapper.

Here is a list of open source programs it contains, possibly as a dependency of WINE.
  • FreeType 2.3.4
  • SDL (Simple DirectMedia Layer) 1.2.10
  • libjpeg 6b
  • libpng 1.2.13
  • libsquish (2006).
  • TransGaming Cider build 472, based on wine.
The game uses DirectX 9, and this appears also what Cider supports up to.

According to TransGaming Cider product page, a large number of high profile games are ported to Mac this way, especially Spore. A consequence of that approach is these games will never be universal binaries. WINE essentially takes unmodified Windows x86 .exe and substitutes only the essential Windows functionalities to allow the game to run. However, x86 binaries require an Intel processor. They won't run on PowerPC.

I'm not sure what to make out of this. Game companies don't write games to be portable, and Cider really is just a band-aid solution. I could have bought the Windows version of the game instead.

Tuesday, December 16, 2008

GNOME vfs mime-type problem

Every once in a while, I seem to suffer a problem where GNOME does not properly recognize mime-type of my files anymore. For example, the PDF file on my desktop is treated as a text file by default, to be opened by "Text Editor" while it's supposed to be opened by "Document Viewer" (left figure depicts the problematic one, while the right figure depicts how it's supposed to look like).

Even if I tried to open the PDF directly with Evince, it tells me that it is unable to open a document of the text/plain type, as seen in the figure below.
Application launchers on my desktop (here shown for ies4linux) are also not recognized. The files are shown as *.desktop files, and when I double click on it, Text Editor comes up and shows me the metadata for the application launcher as opposed to starting the application.
It turns out the problem is that file permissions under /usr/share/mime is messed up. Only root can read and write the files, and nobody else can read them. These files are part of the shared mime-info database generated by /usr/bin/update-mime-database (typically run by package manager as root), and this is how GNOME vfs (or any freedesktop.org compliant desktop environment such as KDE) determines the mime-type of a file.
The reason these files are generated with root-only access is that I set my umask to a pretty strict 0077 (own user full access, group and others no access), and sometimes the update-mime-database program runs under that umask. Not sure whose fault it is because I've never seen package manager suffer that problem. But here is how to fix it.
umask 0022
sudo /usr/bin/update-mime-database /usr/share/mime
And that fixes the problem.

Saturday, December 6, 2008

Reversible Computer

Sounds like an interesting idea to me, so I spent a few minutes reading Carlin James Vieri's master's thesis, Pendulum: A Reversible Computer Architecture, approved by Thomas F. Knight Jr. the thesis supervisor.

I skimmed quickly through page 23, and I decided this thesis is bullocks.

The idea of reversible computing is that a computer should never have to flip a bit, which causes energy loss. Instead, bits should be exchanged so the total number of 0 and 1 bits are conserved. Chapter 3 of the thesis suggests that load-store instructions should be replaced with exchange. I have a simpler approach.

If you implement a 32-bit machine, use 64-bit words with exactly 32 zero bits and 32 one bits. The 64-bit word is divided into two 32-bit parts, the useful part and the useless part. The idea is that a 32-bit word cannot have more than 32 zeros or 32 ones, so we can freely allocate these zero and ones to the "useful" part of the 64-bit word, and the rest temporarily deposited in the "useless" part of the 64-bit word. Computation is carried out by permuting bits between the useful and useless parts.

My model guarantees that storage requirement compared to a traditional computing machine is bounded by a factor of 2. And existing programs can run unmodified on the new reversible computer.

The thesis goes on to explain reversible and irreversible operations in section 3.2.2. It says that:
Certain datapath functions of two operands, such as XOR, have well defined inverses which allow one operand to be reconstructed unambiguously from the result and the second operand. We call these functions reversible because they may be undone: the inputs may be reconstructed from the outputs. Other functions exhibit data-dependent reversibility.
So far so good. Let's continue.
For example, summing two numbers is reversible unless the sum produces an overflow. Multiplication is also reversible unless an overflow or underflow is produced; multiplying a number by zero is reversible if the result and the non-zero operand are saved.
Now this guy is speaking non-sense. Computers perform finite-domain computation with modulo integer arithmetic. It is well-known (at least to students who studied modern algebra) that addition modulo n has an inverse. Overflow (or underflow) merely means the result "wraps around" because of the modulo. Also, multiplication has inverse only under very specific conditions: (1) the set does not contain zero, and (2) any sequence of multiplication on elements in the set cannot give you multiples of n, which becomes zero after modulo. The unit group U(n) trivially satisfies these two conditions, and it has been shown that any other integer multiplicative groups must be isomorphic to an external product of two or more unit groups U(n1) × U(n2) × ... × U(nk).

The point is, the author does not understand when multiplication is inversible. It then contradicts itself by saying:
And a few operations of interest in traditional programming languages and architectures, such as logical AND, are irreversible in the sense that the result and one operand are never sufficient to determine the second operand.
The thing is, any computer science student knows that logical AND is like multiplying two {0, 1} numbers; logical XOR is like adding {0, 1} modulo 2. Why does the author say that multiplication is reversible and goes on to say that logical AND is not? He fails even basic computer science.

You think MIT kids are smart? This guy writes gibberish on his master's thesis and graduated from MIT. He's smart. Anyway, the rest of the thesis seems to be designing an ALU based on these restricted operations (using exchange as opposed to load-store), something that sophomore year college students are asked to do.

I surely hope Pendulum is not state of the art for reversible computer. The idea surely sounds interesting, but I'd be very worried if these designers of computer architecture can't even grasp basic mathematical facts.