| re: C++ optimization for emulators
Timothy Stark escribió:
[color=blue]
> inline Word10& operator += (register const Word10 &val)
> {
> if ((rh += val.rh) & ~H10_MASK)
> ( rh &= H10_MASK, lh++ );
> lh = (lh + val.lh) & H10_MASK;
> return *this;
> }
>
> inline Word10& operator + (register const Word10& x, register const Word10&
> y)
> {
> return Word10 (x) += y;
> }
>
> vs.
>
> #define op_add3(z, x, y) \
> if ((z.rh = x.rh + y.rh) & ~H10_MASK) \
> ( z.rh &= H10_MASK, z.lh++ ); \
> z.lh = (x.lh + y.lh) & H10_MASK;
>
> I compared two generated assembly lines and noticed that operator + function
> has a few more instructions than op_add3 macro function because it usesan
> extra temp pair for returning results. Their results are 23 instructions[/color]
You can write something like:
inline void add_assign (Word10 & z, const Word10 & x, const Word10 & y)
{
if ((z.rh = x.rh + y.rh) & ~H10_MASK)
( z.rh &= H10_MASK, z.lh++ );
z.lh = (x.lh + y.lh) & H10_MASK;
}
By the way, is this code correct? You are incrementing the destination
lh and then assigning it a value in both versions.
Regards. |