genericopenlibs/liboil/src/liboilfunction.h
branchRCL_3
changeset 56 acd3cd4aaceb
equal deleted inserted replaced
54:4332f0f7be53 56:acd3cd4aaceb
       
     1 /*
       
     2  * LIBOIL - Library of Optimized Inner Loops
       
     3  * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
       
     4  * All rights reserved.
       
     5  *
       
     6  * Redistribution and use in source and binary forms, with or without
       
     7  * modification, are permitted provided that the following conditions
       
     8  * are met:
       
     9  * 1. Redistributions of source code must retain the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer.
       
    11  * 2. Redistributions in binary form must reproduce the above copyright
       
    12  *    notice, this list of conditions and the following disclaimer in the
       
    13  *    documentation and/or other materials provided with the distribution.
       
    14  * 
       
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
       
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       
    18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
       
    19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
       
    21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
       
    22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
       
    23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
       
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       
    25  * POSSIBILITY OF SUCH DAMAGE.
       
    26  */
       
    27 
       
    28 //Portions Copyright (c)  2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. 
       
    29 
       
    30 #ifndef _LIBOIL_FUNCTION_H_
       
    31 #define _LIBOIL_FUNCTION_H_
       
    32 
       
    33 #include "liboil/liboilutils.h"
       
    34 #include "liboil/liboiltypes.h"
       
    35 
       
    36 /**
       
    37  * OIL_CHECK_PROTOTYPE:
       
    38  * @a:
       
    39  *
       
    40  * Macro used internally to implement the --enable-prototype-checking
       
    41  * configure option.
       
    42  */
       
    43 #ifdef LIBOIL_STRICT_PROTOTYPES
       
    44 #include <liboil/liboilfuncs.h>
       
    45 #define OIL_CHECK_PROTOTYPE(a) a
       
    46 #else
       
    47 #define OIL_CHECK_PROTOTYPE(a)
       
    48 #endif
       
    49 
       
    50 OIL_BEGIN_DECLS
       
    51 
       
    52 /**
       
    53  * OilImplFlag:
       
    54  *
       
    55  * Implementation flags.
       
    56  *
       
    57  * @OIL_IMPL_FLAG_REF: is the reference implementation for the class.
       
    58  *
       
    59  * @OIL_IMPL_FLAG_OPT: was compiled with alternate CFLAGS as specified
       
    60  * by --enable-alternate-optimization.
       
    61  *
       
    62  * @OIL_IMPL_FLAG_ASM: is written in assembly code.
       
    63  *
       
    64  * @OIL_IMPL_FLAG_DISABLED: is disabled.  This can be set either in the
       
    65  * source code or during library initialization.
       
    66  *
       
    67  * @OIL_IMPL_FLAG_CMOV: uses the i386 instruction cmov or its variants.
       
    68  *
       
    69  * @OIL_IMPL_FLAG_MMX: uses MMX instructions.
       
    70  *
       
    71  * @OIL_IMPL_FLAG_SSE: uses SSE instructions.
       
    72  *
       
    73  * @OIL_IMPL_FLAG_MMXEXT: uses AMD's extended MMX instructions.  These
       
    74  * are a subset of what Intel calls SSE2.  If an implementation uses
       
    75  * only AMD's extended MMX instructions, it should set this flag, and
       
    76  * not @OIL_IMPL_FLAG_SSE2.
       
    77  *
       
    78  * @OIL_IMPL_FLAG_SSE2: uses SSE2 instructions.  This flag implies
       
    79  * @OIL_IMPL_FLAG_SSE and @OIL_IMPL_FLAG_MMXEXT.
       
    80  *
       
    81  * @OIL_IMPL_FLAG_3DNOW: uses 3DNow! instructions.
       
    82  *
       
    83  * @OIL_IMPL_FLAG_3DNOWEXT: uses extended 3DNow! instructions.
       
    84  *
       
    85  * @OIL_IMPL_FLAG_SSE3: uses SSE3 instructions.  This flag implies
       
    86  * @OIL_IMPL_FLAG_SSE2.
       
    87  *
       
    88  * @OIL_IMPL_FLAG_SSSE3: uses SSSE3 instructions.  This flag implies
       
    89  * @OIL_IMPL_FLAG_SSE3.
       
    90  *
       
    91  * @OIL_IMPL_FLAG_ALTIVEC: uses Altivec instructions.
       
    92  *
       
    93  */
       
    94 typedef enum {
       
    95   OIL_IMPL_FLAG_REF = (1<<0),
       
    96   OIL_IMPL_FLAG_OPT = (1<<1),
       
    97   OIL_IMPL_FLAG_ASM = (1<<2),
       
    98   OIL_IMPL_FLAG_DISABLED = (1<<3),
       
    99   OIL_IMPL_FLAG_CMOV = (1<<16),
       
   100   OIL_IMPL_FLAG_MMX = (1<<17),
       
   101   OIL_IMPL_FLAG_SSE = (1<<18),
       
   102   OIL_IMPL_FLAG_MMXEXT = (1<<19),
       
   103   OIL_IMPL_FLAG_SSE2 = (1<<20),
       
   104   OIL_IMPL_FLAG_3DNOW = (1<<21),
       
   105   OIL_IMPL_FLAG_3DNOWEXT = (1<<22),
       
   106   OIL_IMPL_FLAG_SSE3 = (1<<23),
       
   107   OIL_IMPL_FLAG_ALTIVEC = (1<<24),
       
   108   OIL_IMPL_FLAG_EDSP = (1<<25),
       
   109   OIL_IMPL_FLAG_ARM6 = (1<<26),
       
   110   OIL_IMPL_FLAG_VFP = (1<<27),
       
   111   OIL_IMPL_FLAG_SSSE3 = (1<<28)
       
   112 } OilImplFlag;
       
   113 
       
   114 #ifdef OIL_ENABLE_UNSTABLE_API
       
   115 
       
   116 /**
       
   117  * OIL_OPT_MANGLE:
       
   118  *
       
   119  * Used internally to implement the --enable-alternate-optimizations
       
   120  * configure option.
       
   121  */
       
   122 /**
       
   123  * OIL_OPT_FLAG_MANGLE:
       
   124  *
       
   125  * Used internally to implement the --enable-alternate-optimizations
       
   126  * configure option.
       
   127  */
       
   128 /**
       
   129  * OIL_NO_CLASSES:
       
   130  *
       
   131  * Used internally to implement the --enable-alternate-optimizations
       
   132  * configure option.
       
   133  */
       
   134 /**
       
   135  * OIL_OPT_SUFFIX:
       
   136  *
       
   137  * Used internally to implement the --enable-alternate-optimizations
       
   138  * configure option.
       
   139  */
       
   140 #ifndef OIL_OPT_MANGLE
       
   141 #define OIL_OPT_MANGLE(a) a
       
   142 #define OIL_OPT_FLAG_MANGLE(a) a
       
   143 #else
       
   144 #define OIL_NO_CLASSES
       
   145 #define OIL_OPT_FLAG_MANGLE(a) (((a)&(~OIL_IMPL_FLAG_REF)) | OIL_IMPL_FLAG_OPT)
       
   146 #endif
       
   147 #ifndef OIL_OPT_SUFFIX
       
   148 #define OIL_OPT_SUFFIX
       
   149 #endif
       
   150 
       
   151 /**
       
   152  * OilFunctionClass:
       
   153  *
       
   154  * An opaque structure representing a function class.
       
   155  *
       
   156  */
       
   157 struct _OilFunctionClass {
       
   158   /*< private >*/
       
   159     void *func;
       
   160     const char *name;
       
   161     const char *desc;
       
   162     OilTestFunction test_func;
       
   163 
       
   164     OilFunctionImpl *first_impl;
       
   165     OilFunctionImpl *reference_impl;
       
   166 
       
   167     OilFunctionImpl *chosen_impl;
       
   168 
       
   169     const char *prototype;
       
   170 };
       
   171 
       
   172 /**
       
   173  * OilFunctionImpl:
       
   174  *
       
   175  * An opaque structure representing a function implementation.
       
   176  *
       
   177  */
       
   178 struct _OilFunctionImpl {
       
   179   /*< private >*/
       
   180     void *next;
       
   181     OilFunctionClass *klass;
       
   182     void *func;
       
   183     unsigned int flags;
       
   184     const char *name;
       
   185         double profile_ave;
       
   186         double profile_std;
       
   187 };
       
   188 
       
   189 /**
       
   190  * OIL_GET:
       
   191  * @ptr:
       
   192  * @offset:
       
   193  * @type:
       
   194  *
       
   195  * Offsets @ptr by @offset number of bytes, and dereferences it
       
   196  * as type @type.  Note that the offset is in bytes, and not in
       
   197  * the size of the pointer type.
       
   198  */
       
   199 #define OIL_GET(ptr, offset, type) (*(type *)((uint8_t *)(ptr) + (offset)) )
       
   200 /**
       
   201  * OIL_OFFSET:
       
   202  * @ptr:
       
   203  * @offset:
       
   204  *
       
   205  * Add @offset bytes to the pointer @ptr.
       
   206  */
       
   207 #define OIL_OFFSET(ptr, offset) ((void *)((uint8_t *)(ptr) + (offset)) )
       
   208 /**
       
   209  * OIL_INCREMENT:
       
   210  * @ptr:
       
   211  * @offset:
       
   212  *
       
   213  * Increments the pointer @ptr by @offset number of bytes.
       
   214  */
       
   215 #define OIL_INCREMENT(ptr, offset) (ptr = (void *)((uint8_t *)ptr + (offset)) )
       
   216 
       
   217 /**
       
   218  * OIL_CPU_FLAG_MASK:
       
   219  *
       
   220  * Mask describing which bits in #OilImplFlag depend on the current
       
   221  * CPU.
       
   222  */
       
   223 #define OIL_CPU_FLAG_MASK 0xffff0000
       
   224 
       
   225 /**
       
   226  * OIL_DECLARE_CLASS:
       
   227  * @klass: the name of a function class (without the oil_ prefix)
       
   228  *
       
   229  * Declares the Liboil function class @klass.
       
   230  */
       
   231 #define OIL_DECLARE_CLASS(klass) \
       
   232     extern OilFunctionClass _oil_function_class_ ## klass
       
   233 
       
   234 /**
       
   235  * SECTION:liboilmacros
       
   236  * @title: Macros
       
   237  * @short_description: Macros
       
   238  */
       
   239 
       
   240 #ifndef OIL_NO_CLASSES
       
   241 /**
       
   242  * OIL_DEFINE_CLASS_FULL:
       
   243  * @klass: name of class to declare (without oil_ prefix)
       
   244  * @string: prototype of class
       
   245  * @test: test function
       
   246  *
       
   247  * Defines a #OilFunctionClass structure for @klass.  Classes
       
   248  * defined this way will be automatically at Liboil initialization
       
   249  * time.
       
   250  */
       
   251 #define OIL_DEFINE_CLASS_FULL(klass, string, test) \
       
   252 OilFunctionClass _oil_function_class_ ## klass = { \
       
   253     NULL, \
       
   254     #klass , \
       
   255     NULL, \
       
   256         test, \
       
   257         NULL, \
       
   258         NULL, \
       
   259         NULL, \
       
   260         string \
       
   261 }; \
       
   262 OilFunctionClass *oil_function_class_ptr_ ## klass = \
       
   263   &_oil_function_class_ ## klass
       
   264 #else
       
   265 #define OIL_DEFINE_CLASS_FULL(klass, string, test) \
       
   266   OIL_DECLARE_CLASS(klass)
       
   267 #endif
       
   268 
       
   269 /**
       
   270  * OIL_DEFINE_CLASS:
       
   271  * @klass: name of class to declare (without oil_ prefix)
       
   272  * @string: prototype of class
       
   273  *
       
   274  * Defines a #OilFunctionClass structure for @klass.  Classes
       
   275  * defined this way will be automatically at Liboil initialization
       
   276  * time.
       
   277  */
       
   278 #define OIL_DEFINE_CLASS(klass, string) \
       
   279   OIL_DEFINE_CLASS_FULL (klass, string, NULL)
       
   280 
       
   281 /**
       
   282  * OIL_DEFINE_IMPL_FULL:
       
   283  * @function: name of function
       
   284  * @klass: name of class to declare (without oil_ prefix)
       
   285  * @flags: implementation flags and CPU requirements
       
   286  *
       
   287  * Defines a #OilFunctionImpl structure for the function @function
       
   288  * and class @klass.  CPU-dependent flags in @flags will indicate
       
   289  * that this implementation requires the given CPU flags.
       
   290  */
       
   291 
       
   292 #define OIL_DEFINE_IMPL_FULL(function,klass,flags) \
       
   293 OilFunctionImpl OIL_OPT_MANGLE(_oil_function_impl_ ## function) = { \
       
   294     NULL, \
       
   295     &_oil_function_class_ ## klass , \
       
   296     (void *)function, \
       
   297     OIL_OPT_FLAG_MANGLE(flags), \
       
   298         #function OIL_OPT_SUFFIX \
       
   299 } \
       
   300 
       
   301 
       
   302 
       
   303 
       
   304 OIL_CHECK_PROTOTYPE(;_oil_type_ ## klass _ignore_me_ ## function = function)
       
   305 
       
   306 /**
       
   307  * OIL_DEFINE_IMPL:
       
   308  * @function: name of function
       
   309  * @klass: name of class to declare (without oil_ prefix)
       
   310  *
       
   311  * Shorthand for defining a C implementation.  See OIL_DEFINE_IMPL_FULL().
       
   312  */
       
   313 #define OIL_DEFINE_IMPL(function,klass) \
       
   314     OIL_DEFINE_IMPL_FULL(function,klass,0)
       
   315 /**
       
   316  * OIL_DEFINE_IMPL_REF:
       
   317  * @function: name of function
       
   318  * @klass: name of class to declare (without oil_ prefix)
       
   319  *
       
   320  * Shorthand for defining a reference implementation.  See OIL_DEFINE_IMPL_FULL().
       
   321  */
       
   322 #define OIL_DEFINE_IMPL_REF(function,klass) \
       
   323     OIL_DEFINE_IMPL_FULL(function,klass,OIL_IMPL_FLAG_REF)
       
   324 /**
       
   325  * OIL_DEFINE_IMPL_ASM:
       
   326  * @function: name of function
       
   327  * @klass: name of class to declare (without oil_ prefix)
       
   328  *
       
   329  * Shorthand for defining an implementation written in inline
       
   330  * assembly code.  See OIL_DEFINE_IMPL_FULL().
       
   331  */
       
   332 #define OIL_DEFINE_IMPL_ASM(function,klass) \
       
   333     OIL_DEFINE_IMPL_FULL(function,klass,OIL_IMPL_FLAG_ASM)
       
   334 /**
       
   335  * OIL_DEFINE_IMPL_DEPENDS
       
   336  * @function: name of function
       
   337  * @klass: name of class to declare (without oil_ prefix)
       
   338  * @...: other classes this implementation uses
       
   339  *
       
   340  * Shorthand for defining an implementation that uses another Liboil
       
   341  * function class.  This is not currently used.  See
       
   342  * OIL_DEFINE_IMPL_FULL().
       
   343  */
       
   344 #ifndef __SYMBIAN32__
       
   345 #define OIL_DEFINE_IMPL_DEPENDS(function,klass,...) \
       
   346     OIL_DEFINE_IMPL_FULL(function,klass,0)
       
   347 #else
       
   348 #define OIL_DEFINE_IMPL_DEPENDS(function,klass,args...) \
       
   349     OIL_DEFINE_IMPL_FULL(function,klass,0)
       
   350 #endif
       
   351 
       
   352 
       
   353 
       
   354 #ifdef __SYMBIAN32__
       
   355 IMPORT_C
       
   356 #endif
       
   357 void oil_optimize_all (void);
       
   358 
       
   359 #ifdef __SYMBIAN32__
       
   360 IMPORT_C
       
   361 #endif
       
   362 void oil_optimize (const char *class_name);
       
   363 
       
   364 #ifdef __SYMBIAN32__
       
   365 IMPORT_C
       
   366 #endif
       
   367 OilFunctionClass * oil_class_get_by_index (int i);
       
   368 
       
   369 #ifdef __SYMBIAN32__
       
   370 IMPORT_C
       
   371 #endif
       
   372 OilFunctionClass *oil_class_get (const char *class_name);
       
   373 
       
   374 #ifdef __SYMBIAN32__
       
   375 IMPORT_C
       
   376 #endif
       
   377 void oil_class_optimize (OilFunctionClass *klass);
       
   378 
       
   379 #ifdef __SYMBIAN32__
       
   380 IMPORT_C
       
   381 #endif
       
   382 int oil_class_get_n_classes (void);
       
   383 
       
   384 #ifdef __SYMBIAN32__
       
   385 IMPORT_C
       
   386 #endif
       
   387 OilFunctionImpl * oil_impl_get_by_index (int i);
       
   388 
       
   389 #ifdef __SYMBIAN32__
       
   390 IMPORT_C
       
   391 #endif
       
   392 int oil_impl_is_runnable (OilFunctionImpl *impl);
       
   393 
       
   394 #ifdef __SYMBIAN32__
       
   395 IMPORT_C
       
   396 #endif
       
   397 int oil_impl_is_usable (OilFunctionImpl *impl);
       
   398 
       
   399 #ifdef __SYMBIAN32__
       
   400 IMPORT_C
       
   401 #endif
       
   402 void oil_class_choose_by_name (OilFunctionClass * klass, const char *name);
       
   403 
       
   404 #ifdef __SYMBIAN32__
       
   405 IMPORT_C
       
   406 #endif
       
   407 void oil_class_register_impl_full (OilFunctionClass * klass,
       
   408 void (*func)(void), const char *name, unsigned int flags);
       
   409 
       
   410 
       
   411 #ifdef __SYMBIAN32__
       
   412 IMPORT_C
       
   413 #endif
       
   414 void oil_class_register_impl (OilFunctionClass * klass, OilFunctionImpl *impl);
       
   415 
       
   416 #ifdef __SYMBIAN32__
       
   417 IMPORT_C
       
   418 #endif
       
   419 void oil_class_register_impl_by_name (const char *klass_name,
       
   420     OilFunctionImpl *impl);
       
   421 
       
   422 #ifdef __SYMBIAN32__
       
   423 IMPORT_C
       
   424 #endif
       
   425 void oil_init_no_optimize(void);
       
   426 
       
   427 #endif
       
   428 
       
   429 OIL_END_DECLS
       
   430 
       
   431 #endif
       
   432