diff options
| -rw-r--r-- | Makefile | 10 | ||||
| -rwxr-xr-x | asm_diff.sh | 11 | ||||
| -rw-r--r-- | codesize.c | 23 | ||||
| -rwxr-xr-x | runtime.sh | 24 |
4 files changed, 68 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..70f3066 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +CFLAGS=-O2 + +codesize: + gcc $(CFLAGS) -D_TM -o tm_codesize codesize.c -fgnu-tm + gcc $(CFLAGS) -D_LOCK -o lock_codesize codesize.c -lpthread + +all: codesize + +clean: + rm -rf *.o tm_* lock_* diff --git a/asm_diff.sh b/asm_diff.sh new file mode 100755 index 0000000..8987b89 --- /dev/null +++ b/asm_diff.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +if [ "$1" == "" ]; then + echo "$0 <test_name>" + exit -1 +fi + +objdump -D tm_$1 > ___tm.asm +objdump -D lock_$1 > ___lock.asm +diff -Nur ___tm.asm ___lock.asm +rm -f ___tm.asm ___lock.asm diff --git a/codesize.c b/codesize.c new file mode 100644 index 0000000..960757c --- /dev/null +++ b/codesize.c @@ -0,0 +1,23 @@ +#ifdef _TM +#define LOCK __transaction_atomic { +#define UNLOCK } +#endif + +#ifdef _LOCK +#include <pthread.h> +static pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER; +#define LOCK pthread_mutex_lock (&l); +#define UNLOCK pthread_mutex_unlock (&l); +#endif + +int main (int argc, char **argv) +{ + int a = 0, b = 1, c = 2; + + LOCK + if (a < b) + c++; + UNLOCK + + return 0; +} diff --git a/runtime.sh b/runtime.sh new file mode 100755 index 0000000..a88345c --- /dev/null +++ b/runtime.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +RUNS=1000 + +if [ "$1" == "" ]; then + echo "$0 <test_name>" + exit -1 +fi + +echo +echo +echo "transactional memory" +time for i in {1..1000} +do + ./tm_$1 +done + +echo +echo +echo "pthread locking" +time for i in {1..1000} +do + ./lock_$1 +done |
