I'm looking for a way to allocate local variables to registers. I'm aware of a couple of serious methods for doing it (namely, those mentioned on Wikipedia), but I'm stuck on how "spilling" is accomplished. Also, the relevant literature is quite…
This is a strange request but I have a feeling that it could be possible. What I would like is to insert some pragmas or directives into areas of my code (written in C) so that GCC's register allocator will not use them.
I understand that I can do…
Here is some question I wondered about. Given the following code, can we be certain about its output?
void f() {
int i = 0;
z: if(i == 1) goto x; else goto u;
int a;
x: if(a == 10) goto y;
u: a = 10; i = 1; goto z;
y: std::cout <<…
Consider this C code:
void foo(void);
long bar(long x) {
foo();
return x;
}
When I compile it on GCC 9.3 with either -O3 or -Os, I get this:
bar:
push r12
mov r12, rdi
call foo
mov rax, r12
…
In C, we cannot use & to find out the address of a register variable but in C++ we can do the same. Why is it legal in C++ but not in C? Can someone please explain this concept in-depth.
Below is excerpted from the GCC manual's Extended Asm docs, on embedding assembly instructions in C using asm keyword:
The same problem can occur if one output parameter (a) allows a
register constraint and another output parameter (b) allows a…
I'm trying to write some computationally intensive code for Windows x64 target, with SSE or the new AVX instructions, compiling in GCC 4.5.2 and 4.6.1, MinGW64 (TDM GCC build, and some custom build). My compiler options are -O3 -mavx. (-m64 is…
Most assembly programs make use of the 4 general purpose registers eax ebx ecx edx but I find that quite often I need to use more than 4 registers to accomplish my task easily without having to push and pop from the stack to much. Since my program…
The following code compiling with gcc or clang on amd64
// gcc -O2 file.c -c
int f(int a, int b, int c, int d)
{
return a & b & c & d;
}
produces following assembly:
0000000000000000 :
0: 89 d0 mov %edx,%eax
2: …
I know how register based and how stack based virtual machines work independently. I know the advantages and disadvantages of both. What I want to know is that has anyone ever tried to merge the two?
I tried to search the net for the existence of…
I want to write some inline ARM assembly in my C code. For this code, I need to use a register or two more than just the ones declared as inputs and outputs to the function. I know how to use the clobber list to tell GCC that I will be using some…
When talking about register allocation, texts on compilation (for example, Engineering a Compiler by Cooper) often mention that values stored in registers need to be "safe" - otherwise they should be stored in memory.
What makes a value unsafe to be…
I'm trying to implement a code generation/register allocation algorithm for Trees in favor of my old one, where I put everything on stack. Now I'm trying to implement Sethi-Ullman algorithm but from only contents I've found on Wikipedia and some…
For my compiler course I'm building a register allocator based on graph coloring for MIPS architecture. I'm following Muchnick's treatment on the same for my implementation.
Muchnick has been a little fuzzy about how to treat arguments of function…
I've been researching register allocation and was wondering why they all built graphs from the live registers list when there could be a better way to do it. The way I think they could do it is when the live registers crosses the number of registers…