44,790
questions
2319
votes
12
answers
236k
views
Why doesn't GCC optimize a*a*a*a*a*a to (a*a*a)*(a*a*a)?
I am doing some numerical optimization on a scientific application. One thing I noticed is that GCC will optimize the call pow(a,2) by compiling it into a*a, but the call pow(a,6) is not optimized and ...
1776
votes
15
answers
152k
views
Is < faster than <=?
Is if (a < 901) faster than if (a <= 900)?
Not exactly as in this simple example, but there are slight performance changes on loop complex code. I suppose this has to do something with generated ...
1644
votes
11
answers
198k
views
Replacing a 32-bit loop counter with 64-bit introduces crazy performance deviations with _mm_popcnt_u64 on Intel CPUs
I was looking for the fastest way to popcount large arrays of data. I encountered a very weird effect: Changing the loop variable from unsigned to uint64_t made the performance drop by 50% on my PC.
...
947
votes
11
answers
184k
views
Why does C++ code for testing the Collatz conjecture run faster than hand-written assembly?
I wrote these two solutions for Project Euler Q14, in assembly and in C++. They implement identical brute force approach for testing the Collatz conjecture. The assembly solution was assembled with:
...
889
votes
17
answers
938k
views
What's the purpose of the LEA instruction?
For me, it just seems like a funky MOV. What's its purpose and when should I use it?
700
votes
4
answers
91k
views
How do I achieve the theoretical maximum of 4 FLOPs per cycle?
How can the theoretical peak performance of 4 floating point operations (double precision) per cycle be achieved on a modern x86-64 Intel CPU?
As far as I understand it takes three cycles for an SSE ...
540
votes
17
answers
543k
views
How do you get assembler output from C/C++ source in GCC?
How does one do this?
If I want to analyze how something is getting compiled, how would I get the emitted assembly code?
502
votes
40
answers
152k
views
When is assembly faster than C? [closed]
One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in particular. ...
325
votes
16
answers
980k
views
Is it possible to "decompile" a Windows .exe? Or at least view the Assembly?
A friend of mine downloaded some malware from Facebook, and I'm curious to see what it does without infecting myself. I know that you can't really decompile an .exe, but can I at least view it in ...
319
votes
7
answers
87k
views
Why does this code execute more slowly after strength-reducing multiplications to loop-carried additions?
I was reading Agner Fog's optimization manuals, and I came across this example:
double data[LEN];
void compute()
{
const double A = 1.1, B = 2.2, C = 3.3;
int i;
for(i=0; i<LEN; i++) {...
316
votes
11
answers
223k
views
Using GCC to produce readable assembly?
I was wondering how to use GCC on my C source file to dump a mnemonic version of the machine code so I could see what my code was being compiled into. You can do this with Java but I haven't been able ...
315
votes
4
answers
133k
views
How to run a program without an operating system?
How do you run a program all by itself without an operating system running?
Can you create assembly programs that the computer can load and run at startup, e.g. boot the computer from a flash drive ...
313
votes
11
answers
74k
views
What does multicore assembly language look like?
Once upon a time, to write x86 assembler, for example, you would have instructions stating "load the EDX register with the value 5", "increment the EDX" register, etc.
With modern CPUs that have 4 ...
289
votes
6
answers
270k
views
What exactly is the base pointer and stack pointer? To what do they point?
Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine():
(Note that this diagram has high addresses at the bottom and low addresses at the top.)
Could anyone explain to me ...
287
votes
5
answers
16k
views
Why does Java switch on contiguous ints appear to run faster with added cases?
I am working on some Java code which needs to be highly optimized as it will run in hot functions that are invoked at many points in my main program logic. Part of this code involves multiplying ...