$ ./opcost opcodes.txt srl $t0, $t0, 8: 0 45 lb $t0, 8($sp): 0 25 lw $t1, 0($sp): 0 25 lw $t1, 16($sp): 0 31 sll $t0, $t1, 16: 0 18 move $v0, $v1: 0 18 li $v0, 33: 0 18 add $v0, $v0, $v0: 0 45 mult $v0, $v0: 0 45 nop: 0 18
$ cat opcost.c /** * Opcode cost payload calculation * * pancake <pancake/A/youterm/D/com> */ #include <stdio.h> #include <string.h> #define TIMES "20560" #define LAUNCHER "" char *prg = "echo '#include <sys/time.h>\n#include <time.h>\n#include <stdio.h>\n" "int main() { int i, a=0,b=0; struct timeval tv,tv2;" " for(i=0;i<100;i++) { gettimeofday(&tv, NULL);" " asm(\"\\n.rept "TIMES"\\n%s\\n.endr\\n\"); gettimeofday(&tv2, NULL);" " if (i==0) continue; /* skip first iteration */" " /* printf(\"%%d %%d\\n\", tv2.tv_sec-tv.tv_sec, tv2.tv_usec - tv.tv_usec); */" " if (a == 0) a = tv2.tv_sec-tv.tv_sec; if (b == 0) b = tv2.tv_usec-tv.tv_usec;" " else { a=(a+tv2.tv_sec-tv.tv_sec)>>1; b=(b+tv2.tv_usec-tv.tv_usec)>>1; }" " } printf(\"%20s:\t %%d %%d\\n\", a, b); return 0;}' > .tst.c && gcc %s .tst.c -o .a.out" "&& "LAUNCHER" ./.a.out && rm -f .a.out .tst.c"; int main(int argc, char **argv) { FILE *fd; char buf[1024]; char line[1024]; const char *cflags; if (argc<2) { printf("Usage: opcost [file]\n"); return 1; } fd = fopen(argv[1], "r"); if (fd == NULL) { printf("Cannot open '%s'\n", argv[1]); return 1; } cflags = (const char *)getenv("CFLAGS"); if (!cflags) cflags=""; while(1) { line[0] = '\0'; fgets(line, 1024, fd); if (!*line||line[1]=='\0') break; line[strlen(line)-1] = '\0'; sprintf(buf, prg, line, line, cflags); if (system(buf)) break; } fclose(fd); }
There are 31,321 total registered users.
[+] expand