Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
28 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
30 #ifndef _LIBOIL_FUNCTION_H_
31 #define _LIBOIL_FUNCTION_H_
33 #include "liboil/liboilutils.h"
34 #include "liboil/liboiltypes.h"
37 * OIL_CHECK_PROTOTYPE:
40 * Macro used internally to implement the --enable-prototype-checking
43 #ifdef LIBOIL_STRICT_PROTOTYPES
44 #include <liboil/liboilfuncs.h>
45 #define OIL_CHECK_PROTOTYPE(a) a
47 #define OIL_CHECK_PROTOTYPE(a)
55 * Implementation flags.
57 * @OIL_IMPL_FLAG_REF: is the reference implementation for the class.
59 * @OIL_IMPL_FLAG_OPT: was compiled with alternate CFLAGS as specified
60 * by --enable-alternate-optimization.
62 * @OIL_IMPL_FLAG_ASM: is written in assembly code.
64 * @OIL_IMPL_FLAG_DISABLED: is disabled. This can be set either in the
65 * source code or during library initialization.
67 * @OIL_IMPL_FLAG_CMOV: uses the i386 instruction cmov or its variants.
69 * @OIL_IMPL_FLAG_MMX: uses MMX instructions.
71 * @OIL_IMPL_FLAG_SSE: uses SSE instructions.
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.
78 * @OIL_IMPL_FLAG_SSE2: uses SSE2 instructions. This flag implies
79 * @OIL_IMPL_FLAG_SSE and @OIL_IMPL_FLAG_MMXEXT.
81 * @OIL_IMPL_FLAG_3DNOW: uses 3DNow! instructions.
83 * @OIL_IMPL_FLAG_3DNOWEXT: uses extended 3DNow! instructions.
85 * @OIL_IMPL_FLAG_SSE3: uses SSE3 instructions. This flag implies
86 * @OIL_IMPL_FLAG_SSE2.
88 * @OIL_IMPL_FLAG_SSSE3: uses SSSE3 instructions. This flag implies
89 * @OIL_IMPL_FLAG_SSE3.
91 * @OIL_IMPL_FLAG_ALTIVEC: uses Altivec instructions.
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)
114 #ifdef OIL_ENABLE_UNSTABLE_API
119 * Used internally to implement the --enable-alternate-optimizations
123 * OIL_OPT_FLAG_MANGLE:
125 * Used internally to implement the --enable-alternate-optimizations
131 * Used internally to implement the --enable-alternate-optimizations
137 * Used internally to implement the --enable-alternate-optimizations
140 #ifndef OIL_OPT_MANGLE
141 #define OIL_OPT_MANGLE(a) a
142 #define OIL_OPT_FLAG_MANGLE(a) a
144 #define OIL_NO_CLASSES
145 #define OIL_OPT_FLAG_MANGLE(a) (((a)&(~OIL_IMPL_FLAG_REF)) | OIL_IMPL_FLAG_OPT)
147 #ifndef OIL_OPT_SUFFIX
148 #define OIL_OPT_SUFFIX
154 * An opaque structure representing a function class.
157 struct _OilFunctionClass {
162 OilTestFunction test_func;
164 OilFunctionImpl *first_impl;
165 OilFunctionImpl *reference_impl;
167 OilFunctionImpl *chosen_impl;
169 const char *prototype;
175 * An opaque structure representing a function implementation.
178 struct _OilFunctionImpl {
181 OilFunctionClass *klass;
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.
199 #define OIL_GET(ptr, offset, type) (*(type *)((uint8_t *)(ptr) + (offset)) )
205 * Add @offset bytes to the pointer @ptr.
207 #define OIL_OFFSET(ptr, offset) ((void *)((uint8_t *)(ptr) + (offset)) )
213 * Increments the pointer @ptr by @offset number of bytes.
215 #define OIL_INCREMENT(ptr, offset) (ptr = (void *)((uint8_t *)ptr + (offset)) )
220 * Mask describing which bits in #OilImplFlag depend on the current
223 #define OIL_CPU_FLAG_MASK 0xffff0000
227 * @klass: the name of a function class (without the oil_ prefix)
229 * Declares the Liboil function class @klass.
231 #define OIL_DECLARE_CLASS(klass) \
232 extern OilFunctionClass _oil_function_class_ ## klass
235 * SECTION:liboilmacros
237 * @short_description: Macros
240 #ifndef OIL_NO_CLASSES
242 * OIL_DEFINE_CLASS_FULL:
243 * @klass: name of class to declare (without oil_ prefix)
244 * @string: prototype of class
245 * @test: test function
247 * Defines a #OilFunctionClass structure for @klass. Classes
248 * defined this way will be automatically at Liboil initialization
251 #define OIL_DEFINE_CLASS_FULL(klass, string, test) \
252 OilFunctionClass _oil_function_class_ ## klass = { \
262 OilFunctionClass *oil_function_class_ptr_ ## klass = \
263 &_oil_function_class_ ## klass
265 #define OIL_DEFINE_CLASS_FULL(klass, string, test) \
266 OIL_DECLARE_CLASS(klass)
271 * @klass: name of class to declare (without oil_ prefix)
272 * @string: prototype of class
274 * Defines a #OilFunctionClass structure for @klass. Classes
275 * defined this way will be automatically at Liboil initialization
278 #define OIL_DEFINE_CLASS(klass, string) \
279 OIL_DEFINE_CLASS_FULL (klass, string, NULL)
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
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.
292 #define OIL_DEFINE_IMPL_FULL(function,klass,flags) \
293 OilFunctionImpl OIL_OPT_MANGLE(_oil_function_impl_ ## function) = { \
295 &_oil_function_class_ ## klass , \
297 OIL_OPT_FLAG_MANGLE(flags), \
298 #function OIL_OPT_SUFFIX \
304 OIL_CHECK_PROTOTYPE(;_oil_type_ ## klass _ignore_me_ ## function = function)
308 * @function: name of function
309 * @klass: name of class to declare (without oil_ prefix)
311 * Shorthand for defining a C implementation. See OIL_DEFINE_IMPL_FULL().
313 #define OIL_DEFINE_IMPL(function,klass) \
314 OIL_DEFINE_IMPL_FULL(function,klass,0)
316 * OIL_DEFINE_IMPL_REF:
317 * @function: name of function
318 * @klass: name of class to declare (without oil_ prefix)
320 * Shorthand for defining a reference implementation. See OIL_DEFINE_IMPL_FULL().
322 #define OIL_DEFINE_IMPL_REF(function,klass) \
323 OIL_DEFINE_IMPL_FULL(function,klass,OIL_IMPL_FLAG_REF)
325 * OIL_DEFINE_IMPL_ASM:
326 * @function: name of function
327 * @klass: name of class to declare (without oil_ prefix)
329 * Shorthand for defining an implementation written in inline
330 * assembly code. See OIL_DEFINE_IMPL_FULL().
332 #define OIL_DEFINE_IMPL_ASM(function,klass) \
333 OIL_DEFINE_IMPL_FULL(function,klass,OIL_IMPL_FLAG_ASM)
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
340 * Shorthand for defining an implementation that uses another Liboil
341 * function class. This is not currently used. See
342 * OIL_DEFINE_IMPL_FULL().
344 #ifndef __SYMBIAN32__
345 #define OIL_DEFINE_IMPL_DEPENDS(function,klass,...) \
346 OIL_DEFINE_IMPL_FULL(function,klass,0)
348 #define OIL_DEFINE_IMPL_DEPENDS(function,klass,args...) \
349 OIL_DEFINE_IMPL_FULL(function,klass,0)
357 void oil_optimize_all (void);
362 void oil_optimize (const char *class_name);
367 OilFunctionClass * oil_class_get_by_index (int i);
372 OilFunctionClass *oil_class_get (const char *class_name);
377 void oil_class_optimize (OilFunctionClass *klass);
382 int oil_class_get_n_classes (void);
387 OilFunctionImpl * oil_impl_get_by_index (int i);
392 int oil_impl_is_runnable (OilFunctionImpl *impl);
397 int oil_impl_is_usable (OilFunctionImpl *impl);
402 void oil_class_choose_by_name (OilFunctionClass * klass, const char *name);
407 void oil_class_register_impl_full (OilFunctionClass * klass,
408 void (*func)(void), const char *name, unsigned int flags);
414 void oil_class_register_impl (OilFunctionClass * klass, OilFunctionImpl *impl);
419 void oil_class_register_impl_by_name (const char *klass_name,
420 OilFunctionImpl *impl);
425 void oil_init_no_optimize(void);