Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7944 Discussions

Need Advice for better C++ Writing Code?

bparkoff
Beginner
393 Views
Intel team recommends to use vectorization book for writing better C++ code. I think that vectorization is used for loop only. Should I write Emulator Project using MMX instructions or SSE instructions? Do you think that MMX instructions or SSE instructions can translate or interpret fromemulated CPU instructions to x86 CPU instructions faster than regular instructions?
I have knowledge of most C++'s global variables, global functions, and classes.
I have tested all of them using clock function. It shows that global variables and member variable inside struct are the same speed, but member variables and member functions inside classes are slower than global variables and global functions.
I am not sure if vectorization book is right for me. I try to get the right book for Intel Performance. If my draft code does not work inside global function or member function, Intel Performance book instructs me to modify by writing different C++ code in other way to improve performance.
Some people make their own opinions when they claim that global variables are bad idea while local variables inside structs or classes are good idea. They think that structs and classes reduce bugs than global variables.
I always create over 200 global variables inside namespace so global variables can be prevented if global functions attempt to modify global variables inside namespace so it can reduce bugs too.
What do you think? Please recommend. Can you please tell where I can post to discuss C++ code for better performance to any Intel newsgroups?
Thanks...
Bryan Parkoff
0 Kudos
6 Replies
Intel_C_Intel
Employee
393 Views

Bryan,
I also referred you to other books at Intel Press and the technical optimization center
. Did you look there already?
Aart Bik
http://www.aartbik.com/


0 Kudos
bparkoff
Beginner
393 Views
Aart,
Yes, I have looked at Intel Press website. I can't find which book is right for me how to write C++ in a better way for performance since you recommend vectorization book. I think that vectorization book is used for MMX instructions and SSE instructions only. I don't know if emulator project should use regular instructions or MMX instructions or SSE instructions.
It is what I understand that MMX instructions and SSE instructions are used for graphics only, but it is not for emulator project. I am trying to research and find more information.
Can you please list the name topic what you have at Intel Press?
Bryan Parkoff
0 Kudos
Intel_C_Intel
Employee
393 Views

Dear Bryan,

Vectorization can onlyspeedup repetitive operations (typically detected in loops, but occasionally also detected in straight-line code). Just judging from the description of your application, I agree that this is probably not the right optimization for you.
I can recommend The Software Optimization Cookbook from Intel Press and The Intel Architecture Optimization Reference Manual from the IntelTechnicalDocumentationCenter. These books do not explicitly give many C++ programming guidelines, but together give you very good insights on how to optimize for IA32.

Aart Bik
http://www.aartbik.com/

0 Kudos
rmauldin
Beginner
393 Views

The only reason that local variables in the struct are faster is because of the way the cache system works. When you are executing code and accessing data very close to each other, the cache system doesn't have to reach far away to grab the data you are looking for, increasing the rate at which your code executes. Global Variables are stored next to each other in system memory. Your structs may or may not be next to eachother based on when you allocate memory for them in your program. If the data you are looking for is in your struct and not off 100 MB somewhere else in a global variable then it can all be stored in cache and executed very efficiently. Someone tell meI'm wrong. And in general, global variables are messy when editing your source code and functions. Why reach up 200 lines of code to remember what you called a variable. Your functions shouldn't be depending so much on global variables. Even use a static variable inside your structs just to get away from them!

Ryan

0 Kudos
Intel_C_Intel
Employee
393 Views
And in general, global variables are messy when editing your source code and functions. Why reach up 200 lines of code to remember what you called a variable. Your functions shouldn't be depending so much on global variables. Even use a static variable inside your structs just to get away from them!


Thats really very, very true.

Global variables are not worth all the trouble and won't help that much in performance terms.



lg Clemens
0 Kudos
rmauldin
Beginner
393 Views

>>I have tested all of them using clock function. It shows that global variables and member variable inside struct are the same speed, but member variables and member functions inside classes are slower than global variables and global functions. <<

Another thought... member variables require two memory accesses. One for the object and another for the variable offset.

0 Kudos
Reply