Add performance comparison tests
authorDavid Schleef <ds@schleef.org>
Mon, 2 Aug 2010 01:33:27 +0000 (18:33 -0700)
committerDavid Schleef <ds@schleef.org>
Mon, 2 Aug 2010 01:33:27 +0000 (18:33 -0700)
orc-test/orctest.c
orc-test/orctest.h
orc/orcopcodes.c
testsuite/Makefile.am
testsuite/perf_opcodes_sys.c
testsuite/perf_opcodes_sys_compare.c [new file with mode: 0644]
testsuite/perf_parse.c
testsuite/perf_parse_compare.c [new file with mode: 0644]

index 8ce24c9..07bb334 100644 (file)
@@ -801,10 +801,16 @@ orc_test_get_program_for_opcode_param (OrcStaticOpcode *opcode)
   return p;
 }
 
-
 void
 orc_test_performance (OrcProgram *program, int flags)
 {
+  orc_test_performance_full (program, flags, NULL);
+}
+
+double
+orc_test_performance_full (OrcProgram *program, int flags,
+    const char *target_name)
+{
   OrcExecutor *ex;
   int n;
   int m;
@@ -815,20 +821,21 @@ orc_test_performance (OrcProgram *program, int flags)
   OrcCompileResult result;
   OrcProfile prof;
   double ave, std;
+  OrcTarget *target;
 
   ORC_DEBUG ("got here");
 
+  target = orc_target_get_by_name (target_name);
+
   if (!(flags & ORC_TEST_FLAGS_BACKUP)) {
-    OrcTarget *target;
     unsigned int flags;
 
-    target = orc_target_get_default ();
     flags = orc_target_get_default_flags (target);
 
     result = orc_program_compile_full (program, target, flags);
     if (!ORC_COMPILE_RESULT_IS_SUCCESSFUL(result)) {
-      printf("compile failed\n");
-      return;
+      //printf("compile failed\n");
+      return 0;
     }
   }
 
@@ -891,7 +898,7 @@ orc_test_performance (OrcProgram *program, int flags)
   ORC_DEBUG ("done running");
 
   orc_profile_get_ave_std (&prof, &ave, &std);
-  printf("%g %g\n", ave/(n*m), std/(n*m));
+  //printf("%g %g\n", ave/(n*m), std/(n*m));
 
   for(i=0;i<4;i++){
     if (dest_exec[i]) orc_array_free (dest_exec[i]);
@@ -903,6 +910,6 @@ orc_test_performance (OrcProgram *program, int flags)
 
   orc_executor_free (ex);
 
-  return;
+  return ave/(n*m);
 }
 
index 325d573..55188de 100644 (file)
@@ -30,6 +30,8 @@ OrcProgram *orc_test_get_program_for_opcode_const (OrcStaticOpcode *opcode);
 OrcProgram *orc_test_get_program_for_opcode_param (OrcStaticOpcode *opcode);
 
 void orc_test_performance (OrcProgram *program, int flags);
+double orc_test_performance_full (OrcProgram *program, int flags,
+    const char *target);
 
 ORC_END_DECLS
 
index a777989..2e7d30e 100644 (file)
@@ -61,6 +61,8 @@ orc_target_get_by_name (const char *name)
 {
   int i;
 
+  if (name == NULL) return default_target;
+
   for(i=0;i<n_targets;i++){
     if (strcmp (name, targets[i]->name) == 0) {
       return targets[i];
index 3a6f3d8..f68200a 100644 (file)
@@ -9,6 +9,7 @@ TESTS = \
        exec_opcodes_sys \
        exec_parse \
        perf_opcodes_sys perf_parse \
+       perf_opcodes_sys_compare perf_parse_compare \
        memcpy_speed \
        abi
 
index b49be47..074740e 100644 (file)
@@ -70,7 +70,7 @@ test_opcode_src (OrcStaticOpcode *opcode)
     orc_program_append_str (p, opcode->name, "d1", "s1", "s2");
   }
 
-  orc_test_performance (p, flags);
+  printf("%g\n", orc_test_performance_full (p, flags, NULL));
 
   orc_program_free (p);
 }
diff --git a/testsuite/perf_opcodes_sys_compare.c b/testsuite/perf_opcodes_sys_compare.c
new file mode 100644 (file)
index 0000000..1fdf76f
--- /dev/null
@@ -0,0 +1,81 @@
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include <orc/orc.h>
+#include <orc-test/orctest.h>
+
+
+int error = FALSE;
+
+void test_opcode_src (OrcStaticOpcode *opcode);
+
+int
+main (int argc, char *argv[])
+{
+  int i;
+  OrcOpcodeSet *opcode_set;
+
+  orc_test_init();
+  orc_init();
+
+  opcode_set = orc_opcode_set_get ("sys");
+
+  for(i=0;i<opcode_set->n_opcodes;i++){
+    //printf("opcode_%-20s ", opcode_set->opcodes[i].name);
+    test_opcode_src (opcode_set->opcodes + i);
+  }
+
+  if (error) return 1;
+  return 0;
+}
+
+void
+test_opcode_src (OrcStaticOpcode *opcode)
+{
+  OrcProgram *p;
+  char s[40];
+  int flags = 0;
+  double perf_mmx, perf_sse;
+
+  p = orc_program_new ();
+  if (opcode->flags & ORC_STATIC_OPCODE_ACCUMULATOR) {
+    orc_program_add_accumulator (p, opcode->dest_size[0], "d1");
+  } else {
+    orc_program_add_destination (p, opcode->dest_size[0], "d1");
+  }
+  if (opcode->dest_size[1] != 0) {
+    orc_program_add_destination (p, opcode->dest_size[1], "d2");
+  }
+  orc_program_add_source (p, opcode->src_size[0], "s1");
+  if (opcode->src_size[1] != 0) {
+    if (opcode->flags & ORC_STATIC_OPCODE_SCALAR) {
+      orc_program_add_constant (p, opcode->src_size[1], 1, "s2");
+    } else {
+      orc_program_add_source (p, opcode->src_size[1], "s2");
+    }
+  }
+
+  if ((opcode->flags & ORC_STATIC_OPCODE_FLOAT_SRC) ||
+      (opcode->flags & ORC_STATIC_OPCODE_FLOAT_DEST)) {
+    flags = ORC_TEST_FLAGS_FLOAT;
+  }
+
+  sprintf(s, "test_s_%s ", opcode->name);
+  orc_program_set_name (p, s);
+
+  if (opcode->dest_size[1] != 0) {
+    orc_program_append_dds_str (p, opcode->name, "d1", "d2", "s1");
+  } else {
+    orc_program_append_str (p, opcode->name, "d1", "s1", "s2");
+  }
+
+  perf_mmx = orc_test_performance_full (p, flags, "mmx");
+  perf_sse = orc_test_performance_full (p, flags, "sse");
+
+  printf("%g %g\n", perf_mmx, perf_sse);
+
+  orc_program_free (p);
+}
+
index 7eccafe..731c142 100644 (file)
@@ -43,8 +43,8 @@ main (int argc, char *argv[])
   n = orc_parse (code, &programs);
 
   for(i=0;i<n;i++){
-    printf("%-30s ", programs[i]->name);
-    orc_test_performance (programs[i], 0);
+    printf("%-30s %g\n", programs[i]->name,
+        orc_test_performance_full (programs[i], 0, NULL));
   }
 
   if (error) return 1;
diff --git a/testsuite/perf_parse_compare.c b/testsuite/perf_parse_compare.c
new file mode 100644 (file)
index 0000000..c0d4d76
--- /dev/null
@@ -0,0 +1,94 @@
+
+#include <orc/orc.h>
+#include <orc-test/orctest.h>
+#include <orc/orcparse.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+static char * read_file (const char *filename);
+void output_code (OrcProgram *p, FILE *output);
+void output_code_header (OrcProgram *p, FILE *output);
+void output_code_test (OrcProgram *p, FILE *output);
+
+int error = FALSE;
+
+int
+main (int argc, char *argv[])
+{
+  char *code;
+  int n;
+  int i;
+  OrcProgram **programs;
+  const char *filename = NULL;
+
+  orc_init ();
+  orc_test_init ();
+
+  if (argc >= 2) {
+    filename = argv[1];
+  }
+  if (filename == NULL) {
+    filename = getenv ("testfile");
+  }
+  if (filename == NULL) {
+    filename = "test.orc";
+  }
+  code = read_file (filename);
+  if (!code) {
+    printf("perf_parse <file.orc>\n");
+    exit(1);
+  }
+
+  n = orc_parse (code, &programs);
+
+  for(i=0;i<n;i++){
+    double perf_mmx;
+    double perf_sse;
+    perf_mmx = orc_test_performance_full (programs[i], 0, "mmx");
+    perf_sse = orc_test_performance_full (programs[i], 0, "sse");
+    printf("%g %g\n", perf_mmx, perf_sse);
+  }
+
+  if (error) return 1;
+  return 0;
+}
+
+
+static char *
+read_file (const char *filename)
+{
+  FILE *file = NULL;
+  char *contents = NULL;
+  long size;
+  int ret;
+
+  file = fopen (filename, "r");
+  if (file == NULL) return NULL;
+
+  ret = fseek (file, 0, SEEK_END);
+  if (ret < 0) goto bail;
+
+  size = ftell (file);
+  if (size < 0) goto bail;
+
+  ret = fseek (file, 0, SEEK_SET);
+  if (ret < 0) goto bail;
+
+  contents = malloc (size + 1);
+  if (contents == NULL) goto bail;
+
+  ret = fread (contents, size, 1, file);
+  if (ret < 0) goto bail;
+
+  contents[size] = 0;
+
+  return contents;
+bail:
+  /* something failed */
+  if (file) fclose (file);
+  if (contents) free (contents);
+
+  return NULL;
+}
+