607a946d93b4ba18ceb39cccbcf191273f7a25d5
1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
24 #if defined(ENABLE_PPA)
29 #define PPA_REGISTER_CPU_EVENT2GROUP(x, y) # x, # y,
30 #define PPA_REGISTER_CPU_EVENT(x) PPA_REGISTER_CPU_EVENT2GROUP(x, NoGroup)
31 const char *PPACpuAndGroup
[] =
33 #include "ppaCPUEvents.h"
36 #undef PPA_REGISTER_CPU_EVENT
37 #undef PPA_REGISTER_CPU_EVENT2GROUP
40 typedef ppa::Base
*(FUNC_PPALibInit
)(const char **, int);
41 typedef void (FUNC_PPALibRelease
)(ppa::Base
* &);
44 static FUNC_PPALibRelease
*_pfuncPpaRelease
;
47 static void _ppaReleaseAtExit()
49 _pfuncPpaRelease(ppabase
);
55 #if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
57 # define PPA_DLL_NAME L"ppa64.dll"
59 # define PPA_DLL_NAME "ppa64.dll"
63 # define PPA_DLL_NAME L"ppa.dll"
65 # define PPA_DLL_NAME "ppa.dll"
67 #endif // if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
69 void initializePPA(void)
74 HMODULE _ppaLibHandle
= LoadLibrary(PPA_DLL_NAME
);
78 FUNC_PPALibInit
*_pfuncPpaInit
= (FUNC_PPALibInit
*)GetProcAddress(_ppaLibHandle
, "InitPpaUtil");
79 _pfuncPpaRelease
= (FUNC_PPALibRelease
*)GetProcAddress(_ppaLibHandle
, "DeletePpa");
81 if (!_pfuncPpaInit
|| !_pfuncPpaRelease
)
83 FreeLibrary(_ppaLibHandle
);
87 ppabase
= _pfuncPpaInit(PPACpuAndGroup
, PPACpuGroupNums
);
90 FreeLibrary(_ppaLibHandle
);
94 atexit(_ppaReleaseAtExit
);
97 #else /* linux & unix & cygwin */
101 #if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
102 # define PPA_LIB_NAME "libppa64.so"
104 # define PPA_LIB_NAME "libppa.so"
107 void initializePPA(void)
111 printf("PPA: already initialized\n");
115 void *_ppaDllHandle
= dlopen(PPA_LIB_NAME
, RTLD_LAZY
);
118 printf("PPA: Unable to load %s\n", PPA_LIB_NAME
);
122 FUNC_PPALibInit
*_pfuncPpaInit
= (FUNC_PPALibInit
*)dlsym(_ppaDllHandle
, "InitPpaUtil");
123 _pfuncPpaRelease
= (FUNC_PPALibRelease
*)dlsym(_ppaDllHandle
, "DeletePpa");
125 if (!_pfuncPpaInit
|| !_pfuncPpaRelease
)
127 printf("PPA: Function bindings failed\n");
128 dlclose(_ppaDllHandle
);
132 ppabase
= _pfuncPpaInit(PPACpuAndGroup
, PPACpuGroupNums
);
135 printf("PPA: Init failed\n");
136 dlclose(_ppaDllHandle
);
140 atexit(_ppaReleaseAtExit
);
145 #endif /* defined(ENABLE_PPA) */