-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from robertdfrench/select-candidates-from-dylibs
Measure invocation cost for dynamic symbols. Fixes #20
- Loading branch information
Showing
20 changed files
with
233 additions
and
128 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test: main.exe | ||
time -p ./main.exe | ||
|
||
main.exe: main.o libincrement.so | ||
gcc -Wl,-rpath,$(CURDIR) -o $@ $< -L. -lincrement | ||
|
||
libincrement.so: libincrement.o | ||
gcc -shared -o $@ $< | ||
|
||
%.o: %.c | ||
gcc -fPIC -Wall -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.exe *.o *.so |
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,10 @@ | ||
// Use this incrementer algorithm if AVX2 is available. | ||
int fancy_incrementer(int x) { | ||
return x + 1; | ||
} | ||
|
||
// Use this if AVX2 is not available. It's the same as above, because we don't | ||
// actually rely on AVX2. | ||
int normal_incrementer(int x) { | ||
return x + 1; | ||
} |
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,27 @@ | ||
// This program is part of an experiment to compare the performance of GNU IFUNC | ||
// vs plain-old function pointers. Run `make rigorous_speed_demo` to see a full | ||
// comparison of speeds. | ||
// | ||
// This particular program selects an "appropriate" incrementer function lazily, | ||
// via the GNU IFUNC facility. The choice of incrementer is irrelevant, since | ||
// they are the same; our concern is the cost of invoking the chosen incrementer | ||
// based on what strategy we use to select it. | ||
#include <limits.h> | ||
#include <stddef.h> | ||
|
||
int fancy_incrementer(int); | ||
int normal_incrementer(int); | ||
|
||
int main() { | ||
__builtin_cpu_init (); | ||
// Count to ~ 2 Billion by calling a dynamically-resolved incrementer | ||
int counter = 0; | ||
while (counter < INT_MAX) { | ||
if (__builtin_cpu_supports("avx2")) { | ||
counter = fancy_incrementer(counter); | ||
} else { | ||
counter = normal_incrementer(counter); | ||
} | ||
} | ||
return 0; | ||
} |
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,14 @@ | ||
test: main.exe | ||
time -p ./main.exe | ||
|
||
main.exe: main.o libincrement.so | ||
gcc -Wl,-rpath,$(CURDIR) -o $@ $< -L. -lincrement | ||
|
||
libincrement.so: libincrement.o | ||
gcc -shared -o $@ $< | ||
|
||
%.o: %.c | ||
gcc -fPIC -Wall -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.exe *.o *.so |
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,3 @@ | ||
int increment(int x) { | ||
return x + 1; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test: main.exe | ||
time -p ./main.exe | ||
|
||
main.exe: main.o libincrement.so | ||
gcc -Wl,-rpath,$(CURDIR) -o $@ $< -L. -lincrement | ||
|
||
libincrement.so: libincrement.o | ||
gcc -shared -o $@ $< | ||
|
||
%.o: %.c | ||
gcc -fPIC -Wall -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.exe *.o *.so |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This program is part of an experiment to compare the performance of GNU IFUNC | ||
// vs plain-old function pointers. Run `make rigorous_speed_demo` to see a full | ||
// comparison of speeds. | ||
// | ||
// This particular program selects an "appropriate" incrementer function lazily, | ||
// via the GNU IFUNC facility. The choice of incrementer is irrelevant, since | ||
// they are the same; our concern is the cost of invoking the chosen incrementer | ||
// based on what strategy we use to select it. | ||
#include <limits.h> | ||
|
||
int increment(int); | ||
|
||
int main() { | ||
// Count to ~ 2 Billion by calling a dynamically-resolved incrementer | ||
int counter = 0; | ||
while (counter < INT_MAX) { | ||
counter = increment(counter); | ||
} | ||
return 0; | ||
} |
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,14 @@ | ||
test: main.exe | ||
time -p ./main.exe | ||
|
||
main.exe: main.o libincrement.so | ||
gcc -Wl,-rpath,$(CURDIR) -o $@ $< -L. -lincrement | ||
|
||
libincrement.so: libincrement.o | ||
gcc -shared -o $@ $< | ||
|
||
%.o: %.c | ||
gcc -fPIC -Wall -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.exe *.o *.so |
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,10 @@ | ||
// Use this incrementer algorithm if AVX2 is available. | ||
int fancy_incrementer(int x) { | ||
return x + 1; | ||
} | ||
|
||
// Use this if AVX2 is not available. It's the same as above, because we don't | ||
// actually rely on AVX2. | ||
int normal_incrementer(int x) { | ||
return x + 1; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
test: main.exe | ||
time -p ./main.exe | ||
|
||
main.exe: main.o libincrement.so | ||
gcc -Wl,-rpath,$(CURDIR) -o $@ $< -L. -lincrement | ||
|
||
libincrement.so: libincrement.o | ||
gcc -shared -o $@ $< | ||
|
||
%.o: %.c | ||
gcc -fPIC -Wall -c $< -o $@ | ||
|
||
clean: | ||
rm -f *.exe *.o *.so |
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,10 @@ | ||
// Use this incrementer algorithm if AVX2 is available. | ||
int fancy_incrementer(int x) { | ||
return x + 1; | ||
} | ||
|
||
// Use this if AVX2 is not available. It's the same as above, because we don't | ||
// actually rely on AVX2. | ||
int normal_incrementer(int x) { | ||
return x + 1; | ||
} |
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
Oops, something went wrong.