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
* &);
46 static FUNC_PPALibRelease
*_pfuncPpaRelease
;
47 ppa::Base
*ppa::ppabase
;
49 static void _ppaReleaseAtExit()
51 _pfuncPpaRelease(ppabase
);
57 #if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
59 # define PPA_DLL_NAME L"ppa64.dll"
61 # define PPA_DLL_NAME "ppa64.dll"
65 # define PPA_DLL_NAME L"ppa.dll"
67 # define PPA_DLL_NAME "ppa.dll"
69 #endif // if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
71 void initializePPA(void)
76 HMODULE _ppaLibHandle
= LoadLibrary(PPA_DLL_NAME
);
80 FUNC_PPALibInit
*_pfuncPpaInit
= (FUNC_PPALibInit
*)GetProcAddress(_ppaLibHandle
, "InitPpaUtil");
81 _pfuncPpaRelease
= (FUNC_PPALibRelease
*)GetProcAddress(_ppaLibHandle
, "DeletePpa");
83 if (!_pfuncPpaInit
|| !_pfuncPpaRelease
)
85 FreeLibrary(_ppaLibHandle
);
89 ppabase
= _pfuncPpaInit(PPACpuAndGroup
, PPACpuGroupNums
);
92 FreeLibrary(_ppaLibHandle
);
96 atexit(_ppaReleaseAtExit
);
99 #else /* linux & unix & cygwin */
103 #if defined(_M_X64) || defined(__x86_64__) || defined(__amd64__)
104 # define PPA_LIB_NAME "libppa64.so"
106 # define PPA_LIB_NAME "libppa.so"
109 void initializePPA(void)
113 printf("PPA: already initialized\n");
117 void *_ppaDllHandle
= dlopen(PPA_LIB_NAME
, RTLD_LAZY
);
120 printf("PPA: Unable to load %s\n", PPA_LIB_NAME
);
124 FUNC_PPALibInit
*_pfuncPpaInit
= (FUNC_PPALibInit
*)dlsym(_ppaDllHandle
, "InitPpaUtil");
125 _pfuncPpaRelease
= (FUNC_PPALibRelease
*)dlsym(_ppaDllHandle
, "DeletePpa");
127 if (!_pfuncPpaInit
|| !_pfuncPpaRelease
)
129 printf("PPA: Function bindings failed\n");
130 dlclose(_ppaDllHandle
);
134 ppabase
= _pfuncPpaInit(PPACpuAndGroup
, PPACpuGroupNums
);
137 printf("PPA: Init failed\n");
138 dlclose(_ppaDllHandle
);
142 atexit(_ppaReleaseAtExit
);
147 #endif /* defined(ENABLE_PPA) */