os/ossrv/genericopenlibs/liboil/tsrc/examples/oil-suggest/src/oil-suggest.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/liboil/tsrc/examples/oil-suggest/src/oil-suggest.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,156 @@
     1.4 +/*
     1.5 + * LIBOIL - Library of Optimized Inner Loops
     1.6 + * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 
    1.18 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    1.19 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    1.20 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.21 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    1.22 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.23 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.24 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.25 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.26 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    1.27 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.28 + * POSSIBILITY OF SUCH DAMAGE.
    1.29 + */
    1.30 +
    1.31 +#ifdef HAVE_CONFIG_H
    1.32 +#include "config.h"
    1.33 +#endif
    1.34 +
    1.35 +#include <liboil/liboil.h>
    1.36 +#include <liboil/liboilfunction.h>
    1.37 +#include <liboil/liboilcpu.h>
    1.38 +#include <liboil/liboiltest.h>
    1.39 +
    1.40 +#include <stdio.h>
    1.41 +#include <stdlib.h>
    1.42 +#include <string.h>
    1.43 +#include <stdarg.h>
    1.44 +#define LOG_FILE "c:\\logs\\examples_oil-suggest_log.txt"
    1.45 +#include "std_log_result.h"
    1.46 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.47 +
    1.48 +void create_xml(int result)
    1.49 +{
    1.50 +    if(result)
    1.51 +        assert_failed = 1;
    1.52 +    
    1.53 +    testResultXml("examples_oil-suggest");
    1.54 +    close_log_file();
    1.55 +}
    1.56 +
    1.57 +static int
    1.58 +is_poorly_strided (OilFunctionClass *klass)
    1.59 +{
    1.60 +  OilPrototype *proto;
    1.61 +  int i;
    1.62 +  int j;
    1.63 +  OilParameter *param;
    1.64 +
    1.65 +  proto = oil_prototype_from_string (klass->prototype);
    1.66 +  for(i=0;i<proto->n_params;i++) {
    1.67 +    if (proto->params[i].is_stride) {
    1.68 +      for(j=0;j<proto->n_params;j++) {
    1.69 +        param = proto->params + j;
    1.70 +        if (param->parameter_type == (proto->params[i].parameter_type - 1)) {
    1.71 +          if (param->prestride_length == 1 && param->poststride_length == 0) {
    1.72 +            oil_prototype_free (proto);
    1.73 +            return 1;
    1.74 +          }
    1.75 +        }
    1.76 +      }
    1.77 +    }
    1.78 +  }
    1.79 +  oil_prototype_free (proto);
    1.80 +  return 0;
    1.81 +}
    1.82 +
    1.83 +static double
    1.84 +get_speed_score (OilFunctionClass *klass)
    1.85 +{
    1.86 +  OilFunctionImpl *impl;
    1.87 +  double max;
    1.88 +  double x;
    1.89 +
    1.90 +  max = 1.0;
    1.91 +  for(impl = klass->first_impl; impl; impl = impl->next) {
    1.92 +    x =  klass->reference_impl->profile_ave / impl->profile_ave;
    1.93 +    if (x > max) max = x;
    1.94 +  }
    1.95 +  return max;
    1.96 +}
    1.97 +
    1.98 +static void
    1.99 +oil_suggest_class (OilFunctionClass *klass, int verbose)
   1.100 +{
   1.101 +  double x;
   1.102 +
   1.103 +  if (is_poorly_strided (klass)) return;
   1.104 +
   1.105 +  x = get_speed_score (klass);
   1.106 +
   1.107 +  if (x < 20.0) {
   1.108 +  std_log(LOG_FILENAME_LINE,"%s %g\n", klass->name, x);
   1.109 +  }
   1.110 +}
   1.111 +
   1.112 +static void
   1.113 +oil_suggest_all (void)
   1.114 +{
   1.115 +  int i;
   1.116 +  int n;
   1.117 +
   1.118 +  n = oil_class_get_n_classes ();
   1.119 +  for (i = 0; i < n; i++){
   1.120 +    OilFunctionClass *klass = oil_class_get_by_index (i);
   1.121 +
   1.122 +    oil_suggest_class (klass, 0);
   1.123 +  }
   1.124 +}
   1.125 +
   1.126 +static void
   1.127 +oil_suggest (const char *s)
   1.128 +{
   1.129 +  OilFunctionClass *klass = oil_class_get (s);
   1.130 +
   1.131 +  if (klass) {
   1.132 +    oil_suggest_class (klass, 0);
   1.133 +  }
   1.134 +}
   1.135 +
   1.136 +int
   1.137 +main (int argc, char *argv[])
   1.138 +{
   1.139 +  int i;
   1.140 +
   1.141 +  oil_init();
   1.142 +
   1.143 +  if (argc == 1) {
   1.144 +    oil_suggest_all ();
   1.145 +	create_xml(0);
   1.146 +    return 0;
   1.147 +  }
   1.148 +
   1.149 +  for(i=1;i<argc;i++){
   1.150 +    oil_suggest (argv[i]);
   1.151 +  }
   1.152 +    if(assert_failed)
   1.153 +          std_log(LOG_FILENAME_LINE,"Test Fail");
   1.154 +    else
   1.155 +          std_log(LOG_FILENAME_LINE,"Test Successful");
   1.156 +    create_xml(0);
   1.157 +    return 0;
   1.158 +}
   1.159 +