14afb647cSTimo Kreuzer
24afb647cSTimo Kreuzer /*******************************************************************************
34afb647cSTimo Kreuzer MIT License
44afb647cSTimo Kreuzer -----------
54afb647cSTimo Kreuzer
64afb647cSTimo Kreuzer Copyright (c) 2002-2019 Advanced Micro Devices, Inc.
74afb647cSTimo Kreuzer
84afb647cSTimo Kreuzer Permission is hereby granted, free of charge, to any person obtaining a copy
94afb647cSTimo Kreuzer of this Software and associated documentaon files (the "Software"), to deal
104afb647cSTimo Kreuzer in the Software without restriction, including without limitation the rights
114afb647cSTimo Kreuzer to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
124afb647cSTimo Kreuzer copies of the Software, and to permit persons to whom the Software is
134afb647cSTimo Kreuzer furnished to do so, subject to the following conditions:
144afb647cSTimo Kreuzer
154afb647cSTimo Kreuzer The above copyright notice and this permission notice shall be included in
164afb647cSTimo Kreuzer all copies or substantial portions of the Software.
174afb647cSTimo Kreuzer
184afb647cSTimo Kreuzer THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
194afb647cSTimo Kreuzer IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
204afb647cSTimo Kreuzer FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
214afb647cSTimo Kreuzer AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
224afb647cSTimo Kreuzer LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
234afb647cSTimo Kreuzer OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
244afb647cSTimo Kreuzer THE SOFTWARE.
254afb647cSTimo Kreuzer *******************************************************************************/
264afb647cSTimo Kreuzer
274afb647cSTimo Kreuzer #ifdef TEST_STANDALONE
284afb647cSTimo Kreuzer #include <stdio.h>
29*9e8ed3f8STimo Kreuzer #ifdef _MSC_VER
304afb647cSTimo Kreuzer #pragma section (".CRT$XIC",long,read)
31*9e8ed3f8STimo Kreuzer #define _CRTALLOC(x) __declspec(allocate(x))
32*9e8ed3f8STimo Kreuzer #endif /* _MSC_VER */
334afb647cSTimo Kreuzer #else
34*9e8ed3f8STimo Kreuzer #include <intrin.h>
354afb647cSTimo Kreuzer #include <sect_attribs.h>
36*9e8ed3f8STimo Kreuzer #undef _CRTALLOC
37*9e8ed3f8STimo Kreuzer #define _CRTALLOC(x)
384afb647cSTimo Kreuzer #endif
394afb647cSTimo Kreuzer
40*9e8ed3f8STimo Kreuzer typedef int (__cdecl *_PIFV)(void); // FIXME: include process.h?
414afb647cSTimo Kreuzer
424afb647cSTimo Kreuzer int __fma3_is_available = 0;
434afb647cSTimo Kreuzer int __use_fma3_lib = 0;
444afb647cSTimo Kreuzer
454afb647cSTimo Kreuzer
_set_FMA3_enable(int flag)464afb647cSTimo Kreuzer int __cdecl _set_FMA3_enable(int flag)
474afb647cSTimo Kreuzer {
484afb647cSTimo Kreuzer if (__fma3_is_available) __use_fma3_lib = flag;
494afb647cSTimo Kreuzer return __use_fma3_lib;
504afb647cSTimo Kreuzer }
514afb647cSTimo Kreuzer
524afb647cSTimo Kreuzer int __fma3_lib_init(void);
534afb647cSTimo Kreuzer
544afb647cSTimo Kreuzer _CRTALLOC(".CRT$XIC") static _PIFV init_fma3 = __fma3_lib_init;
554afb647cSTimo Kreuzer
__fma3_lib_init(void)564afb647cSTimo Kreuzer int __fma3_lib_init(void)
574afb647cSTimo Kreuzer {
584afb647cSTimo Kreuzer int CPUID[4]; // CPUID[2] is ECX;
594afb647cSTimo Kreuzer
604afb647cSTimo Kreuzer __fma3_is_available = 0;
614afb647cSTimo Kreuzer __cpuid(CPUID, 1);
624afb647cSTimo Kreuzer if (CPUID[2] & (1 << 12)) {
634afb647cSTimo Kreuzer __fma3_is_available = 1;
644afb647cSTimo Kreuzer }
654afb647cSTimo Kreuzer
664afb647cSTimo Kreuzer __use_fma3_lib = __fma3_is_available;
674afb647cSTimo Kreuzer return 0;
684afb647cSTimo Kreuzer }
69