Mercurial > hg > CbC > CbC_examples
changeset 21:0d6edf8a4b67
add test
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 Jan 2016 10:49:15 +0900 |
parents | c181f93d4e30 |
children | 39ae2535ad2c |
files | conv1/conv2.c ljtes/Makefile ljtes/a.out ljtes/benchmark.sh ljtes/lj ljtes/lj_as ljtes/ljtes.c ljtes/ljtes_as.c |
diffstat | 8 files changed, 175 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/conv1/conv2.c Mon Jan 25 09:53:21 2016 +0900 +++ b/conv1/conv2.c Mon Jan 25 10:49:15 2016 +0900 @@ -107,15 +107,15 @@ if (loop-->0) goto f(233,sp); printf("#0103:%d\n",i); - asm volatile( - "movq (%%rdi), %%r10;" - "movq $0, (%%r10);" - "movq 0x8(%%rdi), %%r10;" - "movq 0x8(%%r10), %%rbp;" - "movq 0x10(%%r10), %%rsp;" - "jmpq *0x38(%%r10);" - :"+D"(((struct main_continuation *)sp)->env)::"r10" - ); + asm ( + "movq (%%rdi), %%r10;" + "movq $0, (%%r10);" + "movq 0x8(%%rdi), %%r10;" + "movq 0x8(%%r10), %%rbp;" + "movq 0x10(%%r10), %%rsp;" + "jmpq *0x38(%%r10);" + :"+D"(((struct main_continuation *)sp)->env)::"r10" + ); } /* little optimzation without stack continuation (2) */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ljtes/Makefile Mon Jan 25 10:49:15 2016 +0900 @@ -0,0 +1,28 @@ +CC=/Users/e105711/prog/seminar/CbC/llvmInst/Debug+Asserts/bin/clang +TARGET=conv1 + +CFLAGS= -D"CLANG" +.SUFFIXES: .c .s + +.PHONY: all +all: $(TARGET) + +.c.s: + $(CC) $(CFLAGS) -S $< + +$(TARGET): $(TARGET:%=%.s) + $(CC) -o $@ $(@:%=%.s) + +.PHONY: clean +clean: + rm -f $(TARGET) + rm -f *.o *.s + +time: + for exe in *; do \ + if [ -x $$exe ]; then \ + echo $$exe; \ + time ./$$exe; \ + fi; \ + done +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ljtes/benchmark.sh Mon Jan 25 10:49:15 2016 +0900 @@ -0,0 +1,39 @@ +#!/usr/bin/env zsh + +time=/usr/bin/time +CONV1=./$1 +num=10 + +count=0 +amount=0 +max=0 +min=99999 + +echo "$CONV1" +while [[ $count -lt $num ]]; do + # /usr/bin/time -p ./conv1 1 2>&1 >& - |grep '^user'|tr -s " "|cut -f2 -d" " + usertime=$( $time -p $CONV1 2>&1 >& - |grep '^user'|tr -s " " |cut -f2 -d" ") + echo $usertime + + amount=$(($usertime+$amount)) + if [[ $usertime -lt $min ]]; then + min=$usertime + fi + if [[ $usertime -gt $max ]]; then + max=$usertime + fi + count=$(($count+1)) +done + +echo "amount time = $amount" +echo "maxtime = $max" +echo "mintime = $min" + + +amount=$(($amount - $max - $min)) +echo "amount time - mintime - maxtime = $amount" +count=$(($count-2)) +echo "count = $count" +averagetime=$(($amount/($count))) +echo "average time = $averagetime" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ljtes/ljtes.c Mon Jan 25 10:49:15 2016 +0900 @@ -0,0 +1,45 @@ +#ifdef GCC +#define __environment _CbC_environment +#define __return _CbC_return +#endif + +#define LOOP 50000 + +#include <stdio.h> + +__code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) +{ + if (n<0) { + printf("#0008:err %d!\n",n); + goto (*exit1)(0,exit1env); + } + if (n==0) + goto (*print)(n,result,orig,print,exit1,exit1env); + else { + result += n; + n--; + goto factorial(n,result,orig,print,exit1,exit1env); + } +} + + +int calc(int n){ + goto factorial(n,1,n,print,__return,__environment); +} + +int main( int ac, char *av[]) +{ + int i; + long ans; + for(i=LOOP,ans=0;i>0;i--){ + ans += calc(i); + } + + printf("%ld\n",ans); +} + +__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) +{ + goto (*exit1)(result,exit1env); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ljtes/ljtes_as.c Mon Jan 25 10:49:15 2016 +0900 @@ -0,0 +1,54 @@ +#ifdef GCC +#define __environment _CbC_environment +#define __return _CbC_return +#endif + +#define LOOP 50000 + +#include <stdio.h> + +__code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) +{ + if (n<0) { + printf("#0008:err %d!\n",n); + goto (*exit1)(0,exit1env); + } + if (n==0) + goto (*print)(n,result,orig,print,exit1,exit1env); + else { + result += n; + n--; + goto factorial(n,result,orig,print,exit1,exit1env); + } +} + + +int calc(int n){ + goto factorial(n,1,n,print,__return,__environment); +} + +int main( int ac, char *av[]) +{ + int i; + long ans; + for(i=LOOP,ans=0;i>0;i--){ + int a = calc(i); + ans += a; + } + + printf("%ld\n",ans); +} + +__code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) +{ + asm ( + "movq (%%rdi), %%r10;" + "movq $0, (%%r10);" + "movq 0x8(%%rdi), %%r10;" + "movq 0x8(%%r10), %%rbp;" + "movq 0x10(%%r10), %%rsp;" + "jmpq *0x38(%%r10);" + :"+D"(exit1env)::"r10" + ); +} +