T
Timothy Stark
Hello folks,
Does anyone have any information about good books about C/C++ optiimization?
I am developing my emulator by using C++ language. I compared generated
assembly sources between two
operator functions. To add a pair of 18-bit values by two different
operators below.
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 uses an extra temp pair
for returning
results. Their results are 23 instructions (operator +) vs. 18 instructions
(op_add3) However, I noticed that one instruction is wasted in middle of
operator + function in assembly line.
Does anyone have any segguestions about C/C++ optimization for writing
emulators?
Thank you!
Tim Stark
Does anyone have any information about good books about C/C++ optiimization?
I am developing my emulator by using C++ language. I compared generated
assembly sources between two
operator functions. To add a pair of 18-bit values by two different
operators below.
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 uses an extra temp pair
for returning
results. Their results are 23 instructions (operator +) vs. 18 instructions
(op_add3) However, I noticed that one instruction is wasted in middle of
operator + function in assembly line.
Does anyone have any segguestions about C/C++ optimization for writing
emulators?
Thank you!
Tim Stark