From: Bernhard Urban Date: Tue, 2 Mar 2010 21:21:19 +0000 (+0100) Subject: asmb: pernors modifizierter asmb test aus infforum X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=uebersetzerbau-ss10.git;a=commitdiff_plain;h=8c745a62aa810240f4a5db3bababcdb381ae99ca asmb: pernors modifizierter asmb test aus infforum --- diff --git a/asmb/README b/asmb/README new file mode 100644 index 0000000..90a5448 --- /dev/null +++ b/asmb/README @@ -0,0 +1,7 @@ +the mysterious mr. ubvl presents + +the asmb benchmark: +unpack somewhere, +./test.sh +compare your instruction count to that of your colleagues. the smaller, the +better. you can see what instructions were executed by looking at the trace. diff --git a/asmb/dumpinstr.sh b/asmb/dumpinstr.sh new file mode 100755 index 0000000..abff42d --- /dev/null +++ b/asmb/dumpinstr.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +if [ $# -lt 2 ]; then + echo "usage: $0 " + echo "will produce .trace" +fi + +EXECFILE=$1 +EXECMETHOD=$2 + +shift 2 + +cat < $EXECFILE.tmp + +set step-mode on + +file $EXECFILE +break $EXECMETHOD + +run $* + +while 1==1 + +if \$pc != \$pc +printf "==== ?\\n" +end + +printf "\\n====BEGIN $EXECMETHOD\\n" + +printf "==== " +x/i \$pc + +up +set \$nfp = \$fp +down + +while \$fp != \$nfp +stepi +printf "==== " +x/i \$pc +end + +printf "\\n====END $EXECMETHOD\\n" + +continue + +end + +quit + +END + +gdb < $EXECFILE.tmp > $EXECFILE.trace + +mv $EXECFILE.trace $EXECFILE.output + +awk -- '\ +/^====BEGIN/ {ll = ("begin " $2);} \ +/^==== / {print ll; ll = (" " substr($0, 5));} \ +/^====END/ {print "end", $2;} +' $EXECFILE.output > $EXECFILE.trace + +echo instructions: `grep "^ " $EXECFILE.trace | wc -l` +echo trace output: $EXECFILE.trace + +#rm $EXECFILE.tmp $EXECFILE.output diff --git a/asmb/main.c b/asmb/main.c old mode 100644 new mode 100755 index b63e8df..89e585b --- a/asmb/main.c +++ b/asmb/main.c @@ -2,65 +2,79 @@ #include #include -extern unsigned char *asmb(unsigned char *s); +extern unsigned char *asmb(unsigned char *a); unsigned char *asmb_ref(unsigned char *s) { unsigned long i; for (i=0; s[i]; i++) { - unsigned char c = s[i]; - c += (c >= 'A' && c <= 'Z') ? 'a'-'A' : 0; + unsigned char c=s[i]; + c += (c>='A' && c<='Z') ? 'a'-'A' : 0; s[i] = c; } return s; } -int main(int argc, char **argv) { - char *input1[]={"asdfA\0BCDEFGHKL5", "foofuuMUHkk\0AAAA", - "AbC\0AAAAAAAAAAAA", "BLA|MUHMKUH|KAA\0", - "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC", - "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf" - /* 8 16 20 24 28 32 36 40 48 */ - }; - int len[] = {16,16, - 16,16, - 32, - 48}; - char *output1; - char *output2; - char *input2; - char *input3; - int i, j; +#define NUM_TESTCASES 12 +int main() { + char *input[NUM_TESTCASES]={"asdfABCDEFGHKL54", + "foofuuMUHkk", + "AbC", + "BLA|MUHMKUH|KA", + "ASDFNERABHDFKHDFKLGJAHGLKAHGLKASHGEARNAKLVNLVAANLSADJVHASDLGH", + "asdfABCDEFGHKL544", + "asdfA\0BCDEFGHKL5", + "foofuuMUHkk\0AAAA", + "AbC\0AAAAAAAAAAAA", + "BLA|MUHMKUH|KAA\0", + "ASDFASDFasdfasdfaBC\0AAAABBBBCCCC", + "ASDFASDFasdfasdfaBC0AAAABBBBCCCCmuhKA\0asASDFasdf" + }; + int len[NUM_TESTCASES] = {16, + 11, + 3, + 14, + 60, + 17, + 16, + 16, + 16, + 16, + 32, + 48 + }; + char *output_our, *output_ref; + char *input_our, *input_ref; - for(i = 0; i < 6; i++) { - input2 = strdup(input1[i]); - input3 = strdup(input1[i]); - output1 = (char *)asmb_ref((unsigned char *)(input2)); - output2 = (char *)asmb((unsigned char *)(input3)); + int i,j; + for(i = 0; i < NUM_TESTCASES; i++) { + input_our = strndup(input[i], len[i]); + input_ref = strndup(input[i], len[i]); - printf("\n"); -#if 0 - if(memcmp(output1,output2, len[i])) { -#else - if(strncmp(output1,output2, len[i])) { -#endif - j = 0; - printf("Testfall falsch; Input war: \"%s\"\n", input1[i]); - printf("erwartet:\n\t\"%s\"\ntatsaechliches Ergebnis:\n\t\"%s\"\n", output1, output2); -#if 0 - printf("0x"); - for(j = 0; j < 16; j++) - printf("%02X", output2[j]); + output_our = asmb(input_our); + output_ref = asmb_ref(input_ref); + if(memcmp(output_our,output_ref, len[i]) != 0) { + printf("Testfall falsch! \n Input: \n"); + for(j = 0; j <= len[i]; j++) { + printf("%02X ",input[j]); + } + printf("\nerwartet: \n"); + for(j = 0; j <= len[i]; j++) { + printf("%02X ",output_ref[j]); + } + printf("\ntatsaechliches Ergebnis: \n"); + for(j = 0; j <= len[i]; j++) { + printf("%02X ",output_our[j]); + } printf("\n"); -#endif - } else { - printf("Testfall \"%s\" passt.\n", output1); } - - free(input2); - free(input3); + else { + printf("Testfall korrekt\n"); + } + free(input_our); + free(input_ref); } - return 0; } + diff --git a/asmb/test.sh b/asmb/test.sh new file mode 100755 index 0000000..9140956 --- /dev/null +++ b/asmb/test.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +gcc -O -g -o asmbtest asmbtest.c asmb.o +./dumpinstr.sh asmbtest asmb +rm -f asmbtest