473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C++ optimization for emulators

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
Jul 19 '05 #1
1 1652
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.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
0
by: Aisha | last post by:
Hi all, this is my first message here.. I use visual studio .NET 2002 with MMIT , and i developed some webpages for mobile devices. i tested them on my cell phone, and they are working fine....
1
by: Chumley Walrus | last post by:
I want to use an emulator to test some mobilewebform stuff (via visual studio.net IDE) , but I can't find anything for the Blackberry 6210, or compatible . I would also need some resources on how...
5
by: wkaras | last post by:
I've compiled this code: const int x0 = 10; const int x1 = 20; const int x2 = 30; int x = { x2, x0, x1 }; struct Y {
5
by: John | last post by:
Was curious if anyone codes C on a mainframe in TSO/ISPF and, if so, what they've done to get brackets ( ) recognized by both their terminal emulator and ISPF itself. I'm using Attachmate Extra...
1
by: nitinpatel1117 | last post by:
i have a website, which as flash elements on the screen. I've tested it on all the major broswers, IE 6 & 7, firefox v1 & 2, opera, safari. Works perfect on all these broswers, However, i...
1
by: saurabhamiable | last post by:
Can anyone please tell me that how emulators are used in C?
2
by: refugeedeveloper | last post by:
Hello, Does anyone know how to debug applications using emulators?
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.