Tag: c

65 votes
3 answers
3K views
How do you use gcc to generate assembly code in Intel syntax?

The gcc -S option will generate assembly code in AT&T syntax, is there a way to generate files in Intel sy

avatar
Brianne
0 1 0 9
asked 07 September, 2021
66 votes
13 answers
1.7K views
Can num++ be atomic for 'int num'?

In general, for int num, num++ (or ++num), as a read-modify-write operation, is not atomic. But I often see co

avatar
Forrest
0 1 0 9
asked 07 September, 2021
54 votes
4 answers
2K views
What are the calling conventions for UNIX & Linux system calls (and user-space functions) on i386 and x86-64

Following links explain x86-32 system call conventions for both UNIX (BSD flavor) & Linux: http://www.int

avatar
Rufus
0 1 0 9
asked 07 September, 2021
50 votes
3 answers
1.8K views
Why does GCC generate such radically different assembly for nearly the same C code?

While writing an optimized ftol function I found some very odd behaviour in GCC 4.6.1. Let me show you the cod

avatar
Eddie
0 1 0 9
asked 07 September, 2021
64 votes
21 answers
380 views
Is inline assembly language slower than native C++ code?

I tried to compare the performance of inline assembly language and C++ code, so I wrote a function that add tw

avatar
Rudolf
0 1 0 9
asked 07 September, 2021
66 votes
24 answers
1.4K views
Protecting executable from reverse engineering?

I've been contemplating how to protect my C/C++ code from disassembly and reverse engineering. Normally

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
56 votes
4 answers
3K views
Why would introducing useless MOV instructions speed up a tight loop in x86_64 assembly?

Background: While optimizing some Pascal code with embedded assembly language, I noticed an unnecessary MOV i

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
62 votes
5 answers
2.5K views
Why does GCC use multiplication by a strange number in implementing integer division?

I've been reading about div and mul assembly operations, and I decided to see them in action by writing a

avatar
Xavier
0 1 0 9
asked 07 September, 2021
62 votes
10 answers
2.4K views
Assembly code vs Machine code vs Object code?

What is the difference between object code, machine code and assembly code? Can you give a visual example of

avatar
Xavier
0 1 0 9
asked 07 September, 2021
53 votes
7 answers
1.5K views
What is exactly 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 h

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
49 votes
12 answers
1.4K views
Is 'switch' faster than 'if'?

Is a switch statement actually faster than an if statement? I ran the code below on Visual Studio 2010's

avatar
Renaldo
0 1 0 9
asked 07 September, 2021
50 votes
3 answers
1.7K views
What is a retpoline and how does it work?

In order to mitigate against kernel or cross-process memory disclosure (the Spectre attack), the Linux kernel1

avatar
Gigi
0 1 0 9
asked 07 September, 2021
54 votes
10 answers
1.6K 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 regis

avatar
Trudy
0 1 0 9
asked 07 September, 2021
58 votes
16 answers
655 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 infec

avatar
Rudy
0 1 0 9
asked 07 September, 2021
63 votes
5 answers
1.7K 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 inv

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
48 votes
10 answers
1.6K 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 s

avatar
Jesenia
0 1 0 9
asked 07 September, 2021
55 votes
17 answers
1.5K 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 ass

avatar
Winford
0 1 0 9
asked 07 September, 2021
52 votes
4 answers
663 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 achiev

avatar
Dorian
0 1 0 9
asked 07 September, 2021
58 votes
11 answers
1.9K 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 forc

avatar
Deedee
0 1 0 9
asked 07 September, 2021
64 votes
11 answers
1.9K 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: Changin

avatar
Daniel
0 1 0 9
asked 07 September, 2021