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