Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: C++ class design question

Author: Patrick N

Date: 15:08:41 10/09/03

Go up one level in this thread


I'd say it depends on what exactly you are trying to do.  Are you trying to have
a common class with different implementations depending on what hardware is
available or different implementations which you use at the same time?
If you want a common class, you could have one header but different
implementations (using different source files and/or preprocessor).  One example
I use like this is a thread class.  This way I can have a common interface for
both posix threads and windows threads.  I use the same header file, but
different implementations depending on the platform.
If you are trying to use two different approaches to storing data in the same
algorithm, I recommend two different classes, but have operators that can
convert easily between them.
Hopefully this is helpful.
-Patrick

On October 09, 2003 at 17:05:41, Gerd Isenberg wrote:

>Hi all,
>especially low level C++ experts,
>
>I introduced this SSE2-intrinsic wrapper class with sizeof(2*8):
>
>http://www.talkchess.com/forums/1/message.html?320110
>
>It encapsulates the intrinsic data type __m128i.
>
>Now i like to write a compatible class with standard C++ 64-bit types,
>two bitboards.
>
>Both classes have the same public interface, the same size,
>the same memory image, but disjoint register representation.
>
>Due to all constructors and operators are forced to be inlined,
>a abstract, pure virtual base class makes no sense. And late binding
>at runtime is no issue here.
>
>The issue is portability and the possibility to mix SSE2 (or other 128-bit
>register files on other processors) and gp-algorithms with independent
>instruction chains. Performance tuning by changing some datatype of connected
>(register) variables (but probably not the type of incarnations in memory,
>e.g. members of some source and target structs).
>
>What is the best way to implement that,
>with respect to the different register files?
>
>1. Two none related classes with coincidentally have
>   the same operators, size and memory image.
>
>2. One "protected" base class with a union of both types, but no operators,
>   and two derived classes with inlined operators and constructors?
>
>  union
>  {
>    __m128i dbl;
>    BitBoard sgl[2];
>  }
>
>3. A portable full implemented base class and a derived class with
>   overloaded operators and constructors implemented with
>   intrinsic functions and data type.
>
>One problem is assignment from one type to the other and casting.
>Memory-memory/register or vice versa is fine, but register-register
>is rather inperformant and should be avoided.
>
>Thanks in advance,
>Gerd



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.