chiark / gitweb /
@@@ remote works?
[mLib] / test / tvec-bench.c
index b56fcbe4a904e22a1cdb9103655d4278a2eb32a2..8c8cfdf627f5b1be4e22a5e7c67a53d6bf6f5154 100644 (file)
@@ -90,12 +90,12 @@ static void normalize(double *x_inout, const char **unit_out, double scale)
  *             @void *pctx@ = parent context (ignored)
  *             @void *ctx@ = context pointer to initialize
  *
- * Returns:    Zero on success, @-1@ on failure.
+ * Returns:    ---
  *
  * Use:                Initialize a benchmarking environment context.
  *
  *             The environment description must really be a @struct
- *             tvec_bench@.  If the @bst@ slot is null, then a temporary
+ *             tvec_benchenv@.  If the @bst@ slot is null, then a temporary
  *             benchmark state is allocated for the current test group and
  *             released at the end.  Otherwise, it must be the address of a
  *             pointer to a benchmark state: if the pointer is null, then a
@@ -104,38 +104,37 @@ static void normalize(double *x_inout, const char **unit_out, double scale)
  *             existing valid benchmark state.
  */
 
-int tvec_benchsetup(struct tvec_state *tv, const struct tvec_env *env,
-                   void *pctx, void *ctx)
+void tvec_benchsetup(struct tvec_state *tv, const struct tvec_env *env,
+                    void *pctx, void *ctx)
 {
   struct tvec_benchctx *bc = ctx;
-  const struct tvec_bench *b = (const struct tvec_bench *)env;
-  const struct tvec_env *subenv = b->env;
+  const struct tvec_benchenv *be = (const struct tvec_benchenv *)env;
+  const struct tvec_env *subenv = be->env;
   struct bench_timer *bt;
 
   /* Basic initialization. */
-  bc->b = b; bc->bst = 0; bc->subctx = 0;
+  bc->be = be; bc->bst = 0; bc->subctx = 0;
 
   /* Set up the benchmarking state if it hasn't been done before. */
-  if (!b->bst || !*b->bst) {
+  if (!be->bst || !*be->bst) {
     bt = bench_createtimer(); if (!bt) goto fail_timer;
     bc->bst = xmalloc(sizeof(*bc->bst)); bench_init(bc->bst, bt);
-    if (b->bst) *b->bst = bc->bst;
-  } else if (!(*b->bst)->tm)
+    if (be->bst) *be->bst = bc->bst;
+  } else if (!(*be->bst)->tm)
     goto fail_timer;
   else
-    bc->bst = *b->bst;
+    bc->bst = *be->bst;
 
   /* Set the default target time. */
   bc->dflt_target = bc->bst->target_s;
 
   /* Initialize the subordinate environment. */
   if (subenv && subenv->ctxsz) bc->subctx = xmalloc(subenv->ctxsz);
-  if (subenv && subenv->setup && subenv->setup(tv, subenv, bc, bc->subctx))
-    { xfree(bc->subctx); bc->subctx = 0; return (-1); }
+  if (subenv && subenv->setup) subenv->setup(tv, subenv, bc, bc->subctx);
 
   /* All done. */
 end:
-  return (0);
+  return;
 fail_timer:
   tvec_skipgroup(tv, "failed to create timer"); goto end;
 }
@@ -163,8 +162,8 @@ int tvec_benchset(struct tvec_state *tv, const char *var,
                  const struct tvec_env *env, void *ctx)
 {
   struct tvec_benchctx *bc = ctx;
-  const struct tvec_bench *b = (const struct tvec_bench *)env;
-  const struct tvec_env *subenv = b->env;
+  const struct tvec_benchenv *be = (const struct tvec_benchenv *)env;
+  const struct tvec_env *subenv = be->env;
   union tvec_regval rv;
   static const struct tvec_floatinfo fi = { TVFF_NOMAX, 0.0, 0.0, 0.0 };
   static const struct tvec_regdef rd =
@@ -185,21 +184,20 @@ int tvec_benchset(struct tvec_state *tv, const char *var,
  * Arguments:  @struct tvec_state *tv@ = test vector state
  *             @void *ctx@ = context pointer
  *
- * Returns:    Zero on success, @-1@ on failure.
+ * Returns:    ---
  *
  * Use:                Invoke the subordinate environment's @before@ function to
  *             prepare for the benchmark.
  */
 
-int tvec_benchbefore(struct tvec_state *tv, void *ctx)
+void tvec_benchbefore(struct tvec_state *tv, void *ctx)
 {
   struct tvec_benchctx *bc = ctx;
-  const struct tvec_bench *b = bc->b;
-  const struct tvec_env *subenv = b->env;
+  const struct tvec_benchenv *be = bc->be;
+  const struct tvec_env *subenv = be->env;
 
   /* Just call the subsidiary environment. */
-  if (subenv && subenv->before) return (subenv->before(tv, bc->subctx));
-  else return (0);
+  if (subenv && subenv->before) subenv->before(tv, bc->subctx);
 }
 
 /* --- @tvec_benchafter@ --- *
@@ -216,8 +214,8 @@ int tvec_benchbefore(struct tvec_state *tv, void *ctx)
 void tvec_benchafter(struct tvec_state *tv, void *ctx)
 {
   struct tvec_benchctx *bc = ctx;
-  const struct tvec_bench *b = bc->b;
-  const struct tvec_env *subenv = b->env;
+  const struct tvec_benchenv *be = bc->be;
+  const struct tvec_env *subenv = be->env;
 
   /* Restore the benchmark state's old target. */
   bc->bst->target_s = bc->dflt_target;
@@ -239,11 +237,11 @@ void tvec_benchafter(struct tvec_state *tv, void *ctx)
 void tvec_benchteardown(struct tvec_state *tv, void *ctx)
 {
   struct tvec_benchctx *bc = ctx;
-  const struct tvec_bench *b;
+  const struct tvec_benchenv *be;
   const struct tvec_env *subenv;
 
   if (!bc) return;
-  b = bc->b; subenv = b->env;
+  be = bc->be; subenv = be->env;
 
   /* Tear down any subsidiary environment. */
   if (subenv && subenv->teardown && bc->subctx)
@@ -251,7 +249,7 @@ void tvec_benchteardown(struct tvec_state *tv, void *ctx)
 
   /* If the benchmark state was temporary, then dispose of it. */
   if (bc->bst) {
-    if (b->bst) bc->bst->target_s = bc->dflt_target;
+    if (be->bst) bc->bst->target_s = bc->dflt_target;
     else { bench_destroy(bc->bst); xfree(bc->bst); }
   }
 }
@@ -314,15 +312,13 @@ static void benchloop_inner_indirect(unsigned long n, void *ctx)
  * Returns:    ---
  *
  * Use:                Measures and reports the performance of a test function.
- *
- *
  */
 
 void tvec_benchrun(struct tvec_state *tv, tvec_testfn *fn, void *ctx)
 {
   struct tvec_benchctx *bc = ctx;
-  const struct tvec_bench *b = bc->b;
-  const struct tvec_env *subenv = b->env;
+  const struct tvec_benchenv *be = bc->be;
+  const struct tvec_env *subenv = be->env;
   const struct tvec_regdef *rd;
   struct tvec_output *o = tv->output;
   struct bench_timing tm;
@@ -339,8 +335,8 @@ void tvec_benchrun(struct tvec_state *tv, tvec_testfn *fn, void *ctx)
   r.in = tv->in; r.out = tv->out; r.fn = fn;
 
   /* Decide on the run function to select. */
-  if (b->riter >= 0) {
-    r.n = &TVEC_REG(tv, in, b->riter)->v.u;
+  if (be->riter >= 0) {
+    r.n = &TVEC_REG(tv, in, be->riter)->v.u;
     loopfn = subenv && subenv->run ?
       benchloop_inner_indirect : benchloop_inner_direct;
   } else {
@@ -350,9 +346,9 @@ void tvec_benchrun(struct tvec_state *tv, tvec_testfn *fn, void *ctx)
   }
 
   /* Decide on the kind of unit and the base count. */
-  base = b->niter;
-  if (b->rbuf < 0) unit = TVBU_OP;
-  else { unit = TVBU_BYTE; base *= TVEC_REG(tv, in, b->rbuf)->v.bytes.sz; }
+  base = be->niter;
+  if (be->rbuf < 0) unit = TVBU_OP;
+  else { unit = TVBU_BYTE; base *= TVEC_REG(tv, in, be->rbuf)->v.bytes.sz; }
 
   /* Construct a description of the test using the identifier registers. */
   for (rd = tv->test->regs; rd->name; rd++)