C++ optimization for emulators

Discussion in 'C++' started by Timothy Stark, Oct 7, 2003.

  1. 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
     
    Timothy Stark, Oct 7, 2003
    #1
    1. Advertising

  2. Timothy Stark escribió:

    > 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


    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.
     
    =?iso-8859-1?Q?Juli=E1n?= Albo, Oct 7, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carl Prothman [MVP]

    Re: EMULATORS

    Carl Prothman [MVP], Jul 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,037
    Carl Prothman [MVP]
    Jul 23, 2003
  2. Aisha

    EMULATORS

    Aisha, Jul 21, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    495
    Aisha
    Jul 21, 2003
  3. Chumley Walrus
    Replies:
    1
    Views:
    475
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=
    Dec 31, 2004
  4. BikingBill
    Replies:
    2
    Views:
    3,377
    susith
    Feb 25, 2009
  5. Ravikiran

    Zero Optimization and Sign Optimization???

    Ravikiran, Nov 17, 2008, in forum: C Programming
    Replies:
    22
    Views:
    904
    Thad Smith
    Nov 24, 2008
Loading...

Share This Page