compiler-optimization

VB.NET Select Case Compiler Optimizations?

Does the VB.NET 2008 compiler selectively optimize Select Case Statements? For example, a Select Case Statement with a sufficient quantity of integer cases could be organized as a binary search. I ask this because I am curious whether or not I should opt for a Select Case in place of If Statements with multiple Else If's where integer...

Effect on performance when using objects in c++

Hey, I have a dynamic programming algorithm for Knapsack in C++. When it was implemented as a function and accessing variables passed into it, it was taking 22 seconds to run on a particular instance. When I made it the member function of my class KnapsackInstance and had it use variables that were data members of that class, it started...

C++ Copy constructor, temporaries and copy semantics

For this program #include <iostream> using std::cout; struct C { C() { cout << "Default C called!\n"; } C(const C &rhs) { cout << "CC called!\n"; } }; const C f() { cout << "Entered f()!\n"; return C(); } int main() { C a = f(); C b = a; return 0; } the output I get is: Entered f()! Default C called! ...

How to turn off gcc compiler optimization to enable buffer overflow

Hello - I'm working on a hw problem that requires disabling compiler optimization protection for it to work. I'm using gcc 4.4.1 on ubuntu linux, but can't figure out which flags are are the right ones. I realize it's architecture dependant - my machine runs w/ 32-bit Intel processor. Thanks. ...

Visual C++.NET , speed optimizations

Hello, I want my VC++ code to be executed as fast as possible. Does anybody know what I should change or set in project properties and settings? ...

Benefits of 'Optimize code' option in Visual Studio build

Much of our C# release code is built with the 'Optimize code' option turned off. I believe this is to allow code built in Release mode to be debugged more easily. Given that we are creating fairly simple desktop software which connects to backend Web Services, (ie. not a particularly processor-intensive application) then what if any sor...

C++ defines for a 'better' Release mode build in VS

I currently use the following preprocessor defines, and various optimization settings: WIN32_LEAN_AND_MEAN VC_EXTRALEAN NOMINMAX _CRT_SECURE_NO_WARNINGS _SCL_SECURE_NO_WARNINGS _SECURE_SCL=0 _HAS_ITERATOR_DEBUGGING=0 My question is what other things do fellow SOers use, add, define, in order to get a Release Mode build from VS C++ ...

some pointer to understanding GCC source code

hi, I'm student working on optimizing GCC for multi-core processor. I tried going through the source code, it is difficult to follow through it since I need to add some code to the back end. Can anyone suggest some good resource which explains the code flow through the different phases. Also suggest some development environment for debug...

Languages and VMs: Features that are hard to optimize and why

I'm doing a survey of features in preparation for a research project. Name a mainstream language or language feature that is hard to optimize, and why the feature is or isn't worth the price paid, or instead, just debunk my theories below with anecdotal evidence. Before anyone flags this as subjective, I am asking for specific examples ...

How do JVM's implicit memory barriers behave when chaining constructors?

Referring to my earlier question on incompletely constructed objects, I have a second question. As Jon Skeet pointed out, there's an implicit memory barrier in the end of a constructor that makes sure that final fields are visible to all threads. But what if a constructor calls another constructor; is there such a memory barrier in the ...

Is there any way to get MSVC to pass structs arguments in registers on x64?

For a function with signature: struct Pair { void *v1, *v2 }; void f(Pair p); compiled on x64, I would like Pair's fields to be passed via register, as if the function was: void f(void *v1, void *v2); Compiling a test with gcc 4.2.1 for x86_64 on OSX 10.6, I can see this is exactly what happens by examining the disassembly. Howeve...

"volatile" qualifier and compiler reorderings

A compiler cannot eliminate or reorder reads/writes to a volatile-qualified variables. But what about the cases where other variables are present, which may or may not be volatile-qualified? Scenario 1 volatile int a; volatile int b; a = 1; b = 2; a = 3; b = 4; Can the compiler reorder first and the second, or third and the fourth ...

Copy method optimization in compilers

Hi All! I have the following code: void Stack::operator =(Stack &rhs) { //do the actual copying } Stack::Stack(Stack &rhs) //copy-constructor { top=NULL; //initialize this as an empty stack (which it is) *this=rhs; //invoke assignment operator } Stack& Stack::CopyStack() { return *this; //this statement will invoke co...

io operations in compilers

How are constructs of io operations handled by a compiler? Like the RTL mapping for memory related operations which is done in a compiler at the time of target code generation, where and how exactly is the same done for io operations? How are the appeoaches different for processors supporting MMIO and I/O mapped I/O? Are there any optimi...

Which free C compiler gives options for greater optimizations?

Can you please give me some comparison between C compilers especially with respect to optimization? ...

Compiler reordering around mutex boundaries?

Suppose I have my own non-inline functions LockMutex and UnlockMutex, which are using some proper mutex - such as boost - inside. How will the compiler know not to reorder other operations with regard to calls to the LockMutex and UnlockMutex? It can not possibly know how will I implement these functions in some other compilation unit. ...

Can compiler optimization introduce bugs ?

Hi, Today I had a discussion with a friend of mine and we debated for a couple of hours about "compiler optimization". I defended the point that sometimes, a compiler optimization might introduce bugs or at least, undesired behavior. My friend totally disagreed, saying that "compilers are built by smart people and do smart things" and...

Compiler optimization causing the performance to slow down

I have one strange problem. I have following piece of code: template<clss index, class policy> inline int CBase<index,policy>::func(const A& test_in, int* srcPtr ,int* dstPtr) { int width = test_in.width(); int height = test_in.height(); double d = 0.0; //here is the problem for(int y = 0; y < height; y++) { ...

Can a conforming C# compiler optimize away a local (but unused) variable if it is the only strong reference to an object?

or, in other words: Can an object referenced by a local variable be reclaimed before the variable goes out of scope (eg. because the variable is assigned, but then not used again), or is that object guaranteed to be ineligible for garbage collection until the variable goes out of scope? Let me explain: void Case_1(...

C++ performance, optimizing compiler, empty function in .cpp

I've a very basic class, name it Basic, used in nearly all other files in a bigger project. In some cases, there needs to be debug output, but in release mode, this should not be enabled and be a NOOP. Currently there is a define in the header, which switches a makro on or off, depending on the setting. So this is definetely a NOOP, whe...