Tagged Questions
9
votes
2answers
155 views
Why some compilers optimize if(a>0) and not if(*(&a)>0)?
Let's say I have in the global scope:
const int a =0x93191;
and in the main function I have:
if(a>0)
do_something
the compiler will drop the if statement and there is no branch/jmp in the ...
1
vote
3answers
28 views
Is optimization necessary when code generation is targeting a runtime with JIT?
I'm planning on writing a programming language targeting the .NET platform which led me to start thinking about the code generation aspect of targeting such a platform. I'm new at writing compilers ...
0
votes
2answers
103 views
trying to optimize if/else condition slows down program
I am currently trying to optimize a .net application with the help of the VS-Profiling tools.
One function, which gets called quite often, contains the following code:
if ...
13
votes
5answers
5k views
How many GCC optimization levels are there?
How many GCC optimization levels are there?
I tried gcc -O1, gcc -O2, gcc -O3, and gcc -O4
If I use a really large number, it won't work.
However, I have tried
gcc -O100
and it compiled.
How ...
15
votes
6answers
902 views
Are there risks to optimizing code in C#?
In the build settings panel of VS2010 Pro, there is a CheckBox with the label "optimize code"... of course, I want to check it... but being unusually cautious, I asked my brother about it and he said ...
7
votes
4answers
190 views
What can a compiler do with branching information?
On a modern Pentium it is no longer possible to give branching hints to the processor it seems. Assuming that a profiling compiler such as gcc with profile-guided optimization gains information about ...
0
votes
0answers
64 views
Intel Compiler vs GCC code generation differences
I'm learning about x64 programming and the differences between Intel C++ compiler and GCC and how they optimise the instructions
Questions:
What's the best way to tell Intel Compiler to dump the ...
2
votes
2answers
84 views
Does compilers move skip checks to outside the function call?
Functions or methods like:
void DoSomething(...){
if( ... ) return;
...
}
Checks that skip the entire function if a condition is met. Does the compiler move the check code outside the ...
0
votes
1answer
39 views
HLSL compiler optimizes strange?
I am not an expert in HLSL compilers and how they work with branches but I have read different opinions about this issue. So to be concrete: In C/C++ it would make perfect sense to implement something ...
13
votes
1answer
399 views
Why isn't the Prelude's words function written more simply?
Consider the words Prelude function; it is really easy and one could write it in the following manner:
words' :: String -> [String]
words' [] = []
words' str = before : words' (dropWhile isSpace ...
3
votes
2answers
149 views
Is worth using SSE or should I just rely on the compiler?
I am looking into SSE instructions which are great and started to work some simple code to measure the difference between a function using them and the same function using "standard" code (i.e non ...
-1
votes
4answers
89 views
c++ force compiler to opt out some piece of code
I have a piece of code:
// some code, which only do sanity check
expensive checks
// sanity check end
Now how do I tell the compiler to force it to opt out
this piece? Basically it means when I ...
2
votes
1answer
88 views
Will the C# compiler remove unused local if it is assigned a property?
This might be a silly question. I know that compiler will remove unused locals. But if I write my code like this:
class MyClass
{
public int SomeProperty
{
get
{
...
...
2
votes
4answers
164 views
'|' vs '||' compiler optimization in C#
I was recently asked this question in an interview which I totally got wrong but got me curious about the compiler optimizations in C# and .net
Consider the following snippet:
void Main()
{
...
53
votes
22answers
25k views
Advantage of switch over if-else statement
What's the best practice for switch vs if for a 30 unsigned enumerations where about 10 have an expected action (that presently is the same action). Performance and space need to be considered but ...