Computer Chess Club Archives


Search

Terms

Messages

Subject: Help with msvc port?

Author: Scott Gasch

Date: 14:22:10 07/04/04


I am having two issues porting my engine to MSVC.  I wonder if anyone here has
had similar problems and has any advice.

The first is more serious: when I interface with Eugene's egtb.cpp code I have
to set my project's default calling convention to fastcall in order to make it
work.  If I do not do this then I hit access violations in egtb code that
appears to believe its arguments were passed in ecx and edx when in fact the
calling code seems to have placed them (all) on the stack:

01089C78  mov    ecx,dword ptr [uColor]
01089C7E  push   ecx
01089C7F  mov    edx,dword ptr [iTB]
01089C85  push   edx
01089C86  call   PfnIndCalcFun (102A5F0h)
01089C8B  add    esp,8  <-- this puts invert, ep, bp, and wp on the _stack_
01089C8E  call   eax    <-- this code expects ecx/edx to have params

This is how the code about to be called in eax here is declared:

template <int piw1, int piw2, int pib1> class T32
{
public:
	static INDEX TB_FASTCALL IndCalcW
		(
		square	*psqW,
		square	*psqB,
		square	sqEnP,
		int		fInvert
		)

TB_FASTCALL is defined as __fastcall under MSVC.  Because this same code works
fine when: A. I build the project with default calling convention FASTCALL and
B. when I compile under gcc 3.4.0 I am suspicious of a MSVC code generation bug.
 Has anyone seen this before?  I'm using MSVC 7.1.3088.

Next issue which is less serious but still annoying... I have a struct that I
would like to be 4 bytes large.  It's a bitfield, here's the definition:

#pragma pack(1)
typedef union _ATTACK_BITV
{
    ULONG uWholeThing;
    struct
    {
        union
        {
            UCHAR uSmall;
            struct
            {
                UCHAR uNumAttacks : 3;
                UCHAR uKing : 1;
                UCHAR uQueen : 1;
                UCHAR uRook : 1;
                UCHAR uMinor : 1;
                UCHAR uPawn : 1;
            } small;
        };

        // --------------------
        union
        {
            USHORT uBig;
            struct
            {
                UCHAR uKing : 1;
                UCHAR uQueens : 4;
                UCHAR uRooks : 4;
                UCHAR uMinors : 4;
                UCHAR uPawns : 2;
                UCHAR uUnusedFlag1 : 1;
            } big;
        };

        // -------------------
        union
        {
            UCHAR uXray;
            struct
            {
                UCHAR uNumXrays : 3;
                UCHAR uUnusedFlag2 : 1;
                UCHAR uQueen : 1;
                UCHAR uRook : 1;
                UCHAR uBishop : 1;
                UCHAR uUnusedFlag3 : 1;
            } xray;
        };
    };
}
ATTACK_BITV;
#pragma pack()

As you can see I've tried #pragma pack here... but this turns out to be 5 bytes
in size instead of 4 with some random unused bits in the middle of it.  Again,
on gcc this is 4 bytes.  Is there some way to tell MSVC to pack this thing in
the way I say to?  This is not serious because the code still runs fine.  But
it's annoying.

Thanks much for any help,
Scott




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.