Curious Cross Platform Issue

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Curious Cross Platform Issue

Post by jsgroby »

Can anyone tell me what might cause the following:

My engine is written in ANSI C primarily on a Unix workstation. However, I have compiled it a few times on Windows 7 64-bit. Every perft test I have run on the unix version returns the right values at the right depths so far. However, when I run a specific test on the Windows version it gives a bad result for depth 6 on the following FEN:

r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

The unix version returns 8031647685 for depth 6. The Windows one gave a very large negative number. At depth 5 it returned the right number of 193690690.

Any idea what can cause this difference?

Jeff
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: Curious Cross Platform Issue

Post by matthewlai »

jsgroby wrote:Can anyone tell me what might cause the following:

My engine is written in ANSI C primarily on a Unix workstation. However, I have compiled it a few times on Windows 7 64-bit. Every perft test I have run on the unix version returns the right values at the right depths so far. However, when I run a specific test on the Windows version it gives a bad result for depth 6 on the following FEN:

r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

The unix version returns 8031647685 for depth 6. The Windows one gave a very large negative number. At depth 5 it returned the right number of 193690690.

Any idea what can cause this difference?

Jeff
I would guess that's because you are assuming ints to be 64-bit.

On Windows (even 64-bit Windows) ints are 32-bit for backward compatibility.

I always use uint64_t/int64_t/uint32_t/int32_t for portable code.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Re: Curious Cross Platform Issue

Post by jsgroby »

matthewlai wrote:
jsgroby wrote:Can anyone tell me what might cause the following:

My engine is written in ANSI C primarily on a Unix workstation. However, I have compiled it a few times on Windows 7 64-bit. Every perft test I have run on the unix version returns the right values at the right depths so far. However, when I run a specific test on the Windows version it gives a bad result for depth 6 on the following FEN:

r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

The unix version returns 8031647685 for depth 6. The Windows one gave a very large negative number. At depth 5 it returned the right number of 193690690.

Any idea what can cause this difference?

Jeff
I would guess that's because you are assuming ints to be 64-bit.

On Windows (even 64-bit Windows) ints are 32-bit for backward compatibility.

I always use uint64_t/int64_t/uint32_t/int32_t for portable code.
That is more than likely the issue. I am going to make the change and recompile and test in a bit.

Thanks for the suggestion.

jeff
User avatar
jsgroby
Posts: 83
Joined: Mon Mar 24, 2014 12:26 am
Location: Glen Carbon, IL USA

Re: Curious Cross Platform Issue

Post by jsgroby »

jsgroby wrote:
matthewlai wrote:
jsgroby wrote:Can anyone tell me what might cause the following:

My engine is written in ANSI C primarily on a Unix workstation. However, I have compiled it a few times on Windows 7 64-bit. Every perft test I have run on the unix version returns the right values at the right depths so far. However, when I run a specific test on the Windows version it gives a bad result for depth 6 on the following FEN:

r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

The unix version returns 8031647685 for depth 6. The Windows one gave a very large negative number. At depth 5 it returned the right number of 193690690.

Any idea what can cause this difference?

Jeff
I would guess that's because you are assuming ints to be 64-bit.

On Windows (even 64-bit Windows) ints are 32-bit for backward compatibility.

I always use uint64_t/int64_t/uint32_t/int32_t for portable code.
That is more than likely the issue. I am going to make the change and recompile and test in a bit.

Thanks for the suggestion.

jeff
Indeed that was the issue. Fixed and tested on 64-bit Unix and Windows 7

Thanks again. I learn something new every day while coding on this engine.

I am making a note of that particular FEN as it will be good to test with since it hits so many nodes at depth 6.

Jeff
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: Curious Cross Platform Issue

Post by matthewlai »

jsgroby wrote:
jsgroby wrote:
matthewlai wrote:
jsgroby wrote:Can anyone tell me what might cause the following:

My engine is written in ANSI C primarily on a Unix workstation. However, I have compiled it a few times on Windows 7 64-bit. Every perft test I have run on the unix version returns the right values at the right depths so far. However, when I run a specific test on the Windows version it gives a bad result for depth 6 on the following FEN:

r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1

The unix version returns 8031647685 for depth 6. The Windows one gave a very large negative number. At depth 5 it returned the right number of 193690690.

Any idea what can cause this difference?

Jeff
I would guess that's because you are assuming ints to be 64-bit.

On Windows (even 64-bit Windows) ints are 32-bit for backward compatibility.

I always use uint64_t/int64_t/uint32_t/int32_t for portable code.
That is more than likely the issue. I am going to make the change and recompile and test in a bit.

Thanks for the suggestion.

jeff
Indeed that was the issue. Fixed and tested on 64-bit Unix and Windows 7

Thanks again. I learn something new every day while coding on this engine.

I am making a note of that particular FEN as it will be good to test with since it hits so many nodes at depth 6.

Jeff
Glad to have helped :).

I got bitten by this before, too, going from a platform with 32-bit ints to a platform with 16-bit ints (microcontrollers).

C standard only says ints need to be 16-bits minimum.

So nowadays I only use int for very small values (few hundred), and only when I am lazy. Otherwise everything is fixed size types.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.