Avoid optimizing primitive #33 in vm.c (for VC++)

Lendvai Attila Attila.Lendvai at netvisor.hu
Mon Aug 9 06:00:00 PDT 2004


I've successfully generated a fully optimized exe with VC++ 2005 beta.
This new compiler is a lot much different then the old one, namely that
it generates IL code (just like C#) and that is JIT'ted when the exe is
started. Unfortunately because of that a .NET framework 2.0 beta is
required to run the exe for now. (Or use Mingw, or Cygwin for a windows
exe)

So I think we can just forget this problem...

- 101

PS: thanks for all the info!

:: Hi
:: 
:: Looking at the disassembly below it certainly looks like a 
:: global optimization bug in VC++. I did some experimentation 
:: and found that the following implementation of 
:: _primitive33() works without having to disable any optimizations:
:: 
:: void _primitive33(struct Interpreter * interpreter, 
:: ObjectPointer * arguments, unsigned long int argumentsSize, 
:: struct OopArray * optionals) {
::   signed long int y;
::   signed long int x;
::   x = ObjectPointer_asSmallInt( arguments[0] );
::   y = ObjectPointer_asSmallInt( arguments[1] );
::   PSInterpreter_stackPush_(interpreter, x < y ? 
:: CurrentMemory->TrueObject :
:: CurrentMemory->FalseObject);
:: }
:: 
:: Comparing this to the orignal version below
:: 
:: void _primitive33(struct Interpreter * interpreter, 
:: ObjectPointer * arguments, unsigned long int argumentsSize, 
:: struct OopArray * optionals) {
::   ObjectPointer y;
::   ObjectPointer x;
::   x = arguments[0];
::   y = arguments[1];
::   PSInterpreter_stackPush_(interpreter, 
:: ObjectPointer_asSmallInt(x) < 
:: ObjectPointer_asSmallInt(y)?CurrentMemory->TrueObject:Current
:: Memory->FalseOb
:: ject);
:: }
:: 
:: it seems that the bug is caused by the interaction between 
:: the comparison operator (<) with the inlining of the 
:: ObjectPointer_asSmallInt() function calls. Taking out the 
:: latter into local variables somehow removes this interaction 
:: and makes the optimization bug disappear.
:: 
:: I'm not familiar with the pidgin Slate for generating this 
:: primitive, so maybe somebody familiar with this can update 
:: the pidgin code to generate the function in the above form.
:: 
:: Reading the history of the Microsoft bug reports on global 
:: optimisation bugs, it seems that they have been having 
:: problems with the interaction between the shift operators 
:: and the comparison operators. By the way, these bug reports 
:: are all for older versions of teh VC++ compilers, i.e., 
:: versions 5 and 6. One would expect that these bugs should 
:: have been fixed in the 7.0 and 7.1 versions, but maybe there 
:: are still some uhandled corner cases lurking in their code somewhere.
:: 
:: Just to be on the safe side I would modify the form of ALL 
:: the pidgin code that generates similar forms, i.e. inlined 
:: function calls (containing shift
:: operators) called around comparison operators, to first 
:: store the results of the function calls in local variables 
:: and then use the comparison operator after that on the local 
:: variables.
:: 
:: Regards
:: Jaco
:: 




More information about the Slate mailing list