Computer Chess Club Archives


Search

Terms

Messages

Subject: VC6, _fastcall and MMX instructions

Author: Marcus Heidkamp

Date: 01:00:05 02/04/03


Has anyone tried to use MMX instructions inside a function (with arguments)
using the _fastcall calling convention? I have the strange impression, the the
compiler does some weird things. Just an example:

_declspec(naked) void _fastcall Test(int n)
{
  n; // just to suppress a level 4 warning
  _asm
  {
    ret
  }
}

works ok, but

_declspec(naked) void _fastcall Test(int n)
{
  n;
  _asm
  {
    emms
    ret
  }
}

produces some code on function ENTRY similar to some prolog, which make
absolutely no sense. The disassembler output looks something like this (the
naked declaration is just to simplify the asm output, but it makes no difference
to generate prolog and epilog):

mov  [n], ecx
emms
ret

The problem comes in here, because the [n] memory location is somewhere on the
stack [esp - 4], which has not been allocated properly before function call. By
the way: This is exactly what _fastcall should do - whenever possible use
registers (mainly ecx, edx) to pass arguments to the function, and if not
possible, use normal stack operations (push ...).

I searched for two weeks the help files, knowledge base, Microsoft home page,
etc., but did not find anything that prohibits the use of _fastcall when also
using MMX instructions (either inline asm or intrinsics behaves the same way). I
am using MSVC6 (Professional) SP5, processor pack (for SP5).

Any comments, hints, suggestions?

Thank you in advance.

Marcus Heidkamp



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.