Hi,
I'm converting a linux/bsd library with a function checking for cpu sse caps.
What is the correct way to do this on illumos?
Here is the original piece of code checking for these caps:
static void check_os_katmai_support( void )
{
// printf ("omg\n");
#if defined(VISUAL_ARCH_X86)
#if defined(VISUAL_OS_FREEBSD)
int has_sse=0, ret;
visual_size_t len=sizeof(has_sse);
ret = sysctlbyname("hw.instruction_sse", &has;sse, &len; NULL, 0);
if (ret || !has_sse)
__lv_cpu_caps.hasSSE=0;
#elif defined(VISUAL_OS_NETBSD) || defined(VISUAL_OS_OPENBSD)
int has_sse, has_sse2, ret, mib[2];
visual_size_t varlen;
mib[0] = CTL_MACHDEP;
mib[1] = CPU_SSE;
varlen = sizeof(has_sse);
ret = sysctl(mib, 2, &has;sse, &varlen; NULL, 0);
if (ret
__lv_cpu_caps.hasSSE=0;
} else {
__lv_cpu_caps.hasSSE=1;
}
mib[1] = CPU_SSE2;
varlen = sizeof(has_sse2);
ret = sysctl(mib, 2, &has;sse2, &varlen; NULL, 0);
if (ret
__lv_cpu_caps.hasSSE2=0;
} else {
__lv_cpu_caps.hasSSE2=1;
}
__lv_cpu_caps.hasSSE = 0; /* FIXME ?!?!? */
#elif defined(VISUAL_OS_WIN32)
LPTOP_LEVEL_EXCEPTION_FILTER exc_fil;
if ( __lv_cpu_caps.hasSSE ) {
exc_fil = SetUnhandledExceptionFilter(win32_sig_handler_sse);
__asm __volatile ("xorps %xmm0, %xmm0");
SetUnhandledExceptionFilter(exc_fil);
}
#elif defined(VISUAL_OS_LINUX)
// printf ("omg1\n");
// printf ("omg2\n");
struct sigaction saved_sigill;
struct sigaction saved_sigfpe;
/* Save the original signal handlers.
*/
sigaction( SIGILL, NULL, &saved;sigill );
sigaction( SIGFPE, NULL, &saved;sigfpe );
signal( SIGILL, (void (*)(int))sigill_handler_sse );
signal( SIGFPE, (void (*)(int))sigfpe_handler_sse );
/* Emulate test for OSFXSR in CR4. The OS will set this bit if it
* supports the extended FPU save and restore required for SSE. If
* we execute an SSE instruction on a PIII and get a SIGILL, the OS
* doesn't support Streaming SIMD Exceptions, even if the processor
* does.
*/
if ( __lv_cpu_caps.hasSSE ) {
__asm __volatile ("xorps %xmm1, %xmm0");
}
/* Emulate test for OSXMMEXCPT in CR4. The OS will set this bit if
* it supports unmasked SIMD FPU exceptions. If we unmask the
* exceptions, do a SIMD divide-by-zero and get a SIGILL, the OS
* doesn't support unmasked SIMD FPU exceptions. If we get a SIGFPE
* as expected, we're okay but we need to clean up after it.
*
* Are we being too stringent in our requirement that the OS support
* unmasked exceptions? Certain RedHat 2.2 kernels enable SSE by
* setting CR4.OSFXSR but don't support unmasked exceptions. Win98
* doesn't even support them. We at least know the user-space SSE
* support is good in kernels that do support unmasked exceptions,
* and therefore to be safe I'm going to leave this test in here.
*/
if ( __lv_cpu_caps.hasSSE ) {
// test_os_katmai_exception_support();
}
/* Restore the original signal handlers.
*/
sigaction( SIGILL, &saved;sigill, NULL );
sigaction( SIGFPE, &saved;sigfpe, NULL );
#else
// printf ("hier dan3\n");
/* We can't use POSIX signal handling to test the availability of
* SSE, so we disable it by default.
*/
__lv_cpu_caps.hasSSE=0;
#endif /* __linux__ */
// printf ("hier dan\n");
#endif
// printf ("hier dan ha\n");
}
-------------------------------------------
illumos-discuss
Archives: https://www.listbox.com/member/archive/182180/=now
RSS Feed: https://www.listbox.com/member/archive/rss/182180/21175430-2e6923be
Modify Your Subscription:
https://www.listbox.com/member/?member_id=21175430&id_secret=21175430-6a77cda4
Powered by Listbox: http://www.listbox.com