SOA vs AOS ?

Discussion of chess software programming and technical issues.

Moderator: Ras

MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

SOA vs AOS ?

Post by MahmoudUthman »

of the following 2 code snippets which is generally better performance wise for chess engines "I know such performance difference is almost if not irrelevant to Elo but ":

Code: Select all

struct StateStack
{
   Bitboard BitBoards[16];
	Bitboard CastleRights[2];
	Key Positionkey;
	Key PawnKey;
	U32 HalfMoveClock;
	U32 DoublePushSQ;
	Score PSQTScore;
	int iphase;
} SS[MaxPly]/*backup for make unmake*/;
or

Code: Select all

   Bitboard BitBoards[16];
	Bitboard CastleRights[2];
	Key Positionkey;
	Key PawnKey;
	U32 HalfMoveClock;
	U32 DoublePushSQ;
	Score PSQTScore;
	int iphase;

   //Backup for Make/Unmake
   Bitboard BUBitBoards[MaxPly][16];
	Bitboard BUCastleRights[MaxPly][2];
	Key BUPositionkey[MaxPly];
	Key BUPawnKey[MaxPly];
	U32 BUHalfMoveClock[MaxPly];
	U32 BUDoublePushSQ[MaxPly];
	Score BUPSQTScore[MaxPly];
	int BUiphase[MaxPly];

syzygy
Posts: 5868
Joined: Tue Feb 28, 2012 11:56 pm

Re: SOA vs AOS ?

Post by syzygy »

I'm sure you know the answer?

One has good caching behaviour, the other has not.
MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

Re: SOA vs AOS ?

Post by MahmoudUthman »

syzygy wrote:I'm sure you know the answer?

One has good caching behaviour, the other has not.
I'm assuming the first one in this case , but I'm not entirely sure ?
mar
Posts: 2673
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: SOA vs AOS ?

Post by mar »

SOA is powerful if you have a large structure and you know you won't have to access all its elements during traversal (loop).
(In such cases AOS will hurt a lot because you get L1 miss per element)
But I don't think this applies in your case.

Jai programming language by Jonathan Blow (not out yet unfortunately, but I recommend his devel videos on YouTube - absolutely amazing if you understand what he's talking about)
has native language support for SOA (also for SOA pointers => pointer + stride), in all other languages implenting SOA results in ugly, unreadable code.
That's only the tip of the iceberg, it has many neat features; I'd probably dub it "C on steroids", yet that would be a vast understatement,
as it has lambdas, function/operator overloads, simplified templates, compile-time exection, full reflection, really cool 'format strings', per-thread temporary storage (scratch buffer),
fast compile times and way more. Also no GC (yes I consider this a feature)
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: SOA vs AOS ?

Post by cdani »

I use the first in Andscacs for various things. With one pointer you access all the variables. Also all the variables are grouped in the same memory space, so is better for cache.
Also this big array is inside the biggest array that uses each thread.