1 /* /////////////////////////////////////////////////////////////////////////////
3 // INTEL CORPORATION PROPRIETARY INFORMATION
4 // This software is supplied under the terms of a license agreement or
5 // nondisclosure agreement with Intel Corporation and may not be copied
6 // or disclosed except in accordance with the terms of that agreement.
7 // Copyright(c) 1999-2004 Intel Corporation. All Rights Reserved.
11 static const char* SET_LIB_ERR = "Set ipp library error";
15 #define WIN32_LEAN_AND_MEAN
17 #elif defined( linux )
20 /* Describe Intel CPUs and libraries */
21 typedef enum{CPU_PX=0, CPU_A6, CPU_W7, CPU_T7, CPU_NOMORE} cpu_enum;
22 typedef enum{LIB_PX=0, LIB_A6, LIB_W7, LIB_T7, LIB_NOMORE} lib_enum;
24 typedef unsigned char uchar;
25 typedef unsigned short ushort;
26 typedef __int64 int64;
31 #define ippGetCpuType ippCoreGetCpuType
34 static cpu_enum GetProcessorId()
36 switch ( ippGetCpuType() ) {
40 case ippCpuPII: return CPU_PX;
41 case ippCpuITP: return CPU_A6;
42 case ippCpuITP2: return CPU_A6;
43 case ippCpuPIII: return CPU_A6;
46 case ippCpuP4HT: return CPU_W7;
47 case ippCpuEM64T: return CPU_T7;
48 case ippCpuP4HT2: return CPU_T7;
49 default: return CPU_PX;
55 #define IPPAPI(type,name,arg)
59 /* New cpu can use some libraries for old cpu */
60 static const lib_enum libUsage[][LIB_NOMORE+1] = {
61 /* LIB_T7, LIB_W7, LIB_A6, LIB_PX, LIB_NOMORE */
62 /*PX*/ { LIB_PX, LIB_NOMORE },
63 /*A6*/ { LIB_A6, LIB_PX, LIB_NOMORE },
64 /*W7*/ { LIB_W7, LIB_A6, LIB_PX, LIB_NOMORE },
65 /*T7*/ { LIB_T7, LIB_W7, LIB_A6, LIB_PX, LIB_NOMORE }
68 #if !defined (PX) && !defined (A6) && !defined (W7) && !defined (T7)
69 #error Are not defined the CPUs, following are allowed: PX, A6, W7, T7
77 #define IPPAPI(type,name,arg) extern type __stdcall px_##name arg;
78 #define PX_NAME(name) (FARPROC)px_##name
79 #include "opencvipp_funclist.h"
81 #define PX_NAME(name) NULL
86 #define IPPAPI(type,name,arg) extern type __stdcall a6_##name arg;
87 #define A6_NAME(name) (FARPROC)a6_##name
88 #include "opencvipp_funclist.h"
90 #define A6_NAME(name) NULL
95 #define IPPAPI(type,name,arg) extern type __stdcall w7_##name arg;
96 #define W7_NAME(name) (FARPROC)w7_##name
97 #include "opencvipp_funclist.h"
99 #define W7_NAME(name) NULL
104 #define IPPAPI(type,name,arg) extern type __stdcall t7_##name arg;
105 #define T7_NAME(name) (FARPROC)t7_##name
106 #include "opencvipp_funclist.h"
108 #define T7_NAME(name) NULL
115 #define IPP_EXTERN_C extern "C"
121 #define IPPAPI(type,name,arg) \
122 static FARPROC d##name; \
123 IPP_EXTERN_C __declspec(naked dllexport) void __stdcall name arg { __asm {jmp d##name } }
124 #include "opencvipp_funclist.h"
127 typedef struct _USER_Desc_t {
129 FARPROC FuncAddr[CPU_NOMORE];
132 static USER_Desc_t AddressBook[] = {
134 #define IPPAPI(type,name,arg) &d##name, \
135 PX_NAME(name), A6_NAME(name), W7_NAME(name), T7_NAME(name),
136 #include "opencvipp_funclist.h"
139 /* how large is the table of the functions */
140 static int sFuncCount = sizeof( AddressBook ) / sizeof( AddressBook[0] );
142 /* fill ipp function address book in correspondence to the target cpu */
143 static BOOL SetLib( lib_enum lib )
146 for ( i=0; i<sFuncCount; i++ )
147 if( NULL == AddressBook[i].FuncAddr[lib] )
150 *(AddressBook[i].WorkAddr) = AddressBook[i].FuncAddr[lib];
154 static BOOL setCpuSpecificLib()
157 cpu_enum cpu = GetProcessorId();
158 if( sFuncCount > 0 && cpu >= CPU_PX && cpu < CPU_NOMORE ) {
160 const lib_enum* libs = libUsage[ cpu ];
161 while( *libs < LIB_NOMORE )
162 if( SetLib( *libs++ ) ) return TRUE; /* SUCCESS EXIT */
164 /* if not found, then failed with error message */
165 lstrcpy( buf, " No ipp matching to CPU was found during the Waterfall" );
166 MessageBeep( MB_ICONSTOP );
167 MessageBox( 0, buf, SET_LIB_ERR, MB_ICONSTOP | MB_OK );
172 BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason,
175 switch( fdwReason ) {
176 case DLL_PROCESS_ATTACH: if( !setCpuSpecificLib() )return FALSE;
186 /* //////////////////////// End of file "dllmain.c" ///////////////////////// */