-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/chapter_20/int_only/no_coalescing/funcall_generates_args.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Make sure we recognize that a function uses some parameter-passing registers, | ||
* determined by its declaration. Don't inspect assembly, just validate behavior. | ||
* NOTE: only works as intended after we've implemented register coalescing. | ||
* */ | ||
|
||
#include "util.h" | ||
|
||
// defined in funcall_generates_args_lib, | ||
// exits early with return code -1 if a and b don't have | ||
// the correc values | ||
int f(int a, int b); | ||
|
||
int glob = 10; | ||
int x = 0; | ||
int y = 0; | ||
int target(void) { | ||
int a = glob + 1; | ||
int b = glob + 2; | ||
// We'll coalesce a and b with EDI/ESI because they're copied into those | ||
// registers. If we don't recognize that EDI/ESI are live when we call f, | ||
// we'll coalesce the temporaries that hold a * glob and b * glob | ||
// with EDI/ESI too, since we'll generate the following assembly: | ||
// movl %a, %tmp | ||
// imull %glob, %tmp | ||
// movl %tmp, %x | ||
// and similar for y/b | ||
x = a * glob; | ||
y = b * glob; | ||
// validate a and b | ||
f(a, b); | ||
// validate x and y | ||
check_one_int(x, 110); | ||
check_one_int(y, 120); | ||
return 0; | ||
} | ||
|
||
int main(void) { | ||
return target(); | ||
} |
24 changes: 0 additions & 24 deletions
24
tests/chapter_20/int_only/with_coalescing/funcall_generates_args.c
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
// helper function for funcall_generates_args | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
// a and b should be 11 and 12 | ||
int f(int a, int b) { | ||
return a == 11 && b == 12; | ||
if (a != 11) { | ||
printf("Expected a to be 11 but found %d\n", a); | ||
exit(-1); | ||
} | ||
|
||
if (b != 12) { | ||
printf("Expected b to be 12 but found %d\n", b); | ||
exit(-1); | ||
} | ||
|
||
return 0; | ||
} |