Skip to main content
gamedev.net
🔒 Locked

SIMD

Started by ArnoAtWork Jan 15, 2003 at 1:06 PM 5 replies 500+ views
Original Post
ArnoAtWork
ArnoAtWork
I use VC++ and streaming SIMD functions. Does this class and function exists on UNIX?
S1CA
S1CA
SSE is a feature of the CPU so nothing to do with compiler, language or OS.

If the UNIX box you were compiling for had CPU(s) which feature SSE then yes, they would run SSE code.

Inline assembly using SSE in a C/C++ program would compile on UNIX based/targeting compilers - as long as you have a compiler which supports SSE in inline assembly .

Vector intrinsics for SSE would also compile on UNIX based/targeting compiles - as long as you have a compiler which supports SSE intrinsics

Which compiler are you intending on UNIX?, whether SSE code will compile on UNIX depends entirely on that.
So your question doesn''t make much sense as it stands, there isn''t a yes/no answer unless you tell us which compiler you use under UNIX.


AFAIK the Intel C/C++ Compiler is available for Linux, and that does fully support inline SSE and SSE intrinsics.

500

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
walkingcarcass
walkingcarcass
is there a way to determine SSE capabilities of the processor at runtime?

********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back
spraff.net: don't laugh, I'm still just starting...
Evil Bill
Evil Bill
Thanks to Simon (S1CA) who gave me this a while ago:

          
// FPU:

#define PF_FPU 1<<0

// MMX:

#define PF_MMX 1<<1

// AMD MMX:

#define PF_EMMX 1<<2

// 3DNow!:

#define PF_3DNOW 1<<3

// 3DNow Extensions:

#define PF_E3DNOW 1<<4

// SIMD:

#define PF_SSE 1<<5


BOOL GetCPUFeatures(char* szMan, DWORD dwFeatures)
{
BOOL bHasCPUID = FALSE;
DWORD dwStdFeatures = 0;
DWORD dwExFeatures = 0;

szMan[12] = 0;
dwFeatures = 0;
_asm
{
// First check for a CPUID instruction (at least a 486) //

pushfd
pop eax
mov edx, eax
xor eax, 1<<21
push eax
popfd
pushfd
pop eax
xor eax,edx
jz short done
mov [bHasCPUID], 1

// Get Manufacturer //

mov eax, 0 // CPUID function 0 : Manufacturer + highest CPUID

cpuid
mov dword ptr szMan, ebx
mov dword ptr szMan+4, edx
mov dword ptr szMan+8, ecx

// AMD ('AuthenticAMD')? //

cmp ebx, 'htuA'
jne short not_amd
cmp edx, 'itne'
jne short not_amd
cmp ecx, 'DMAc'
je get_features
not_amd:

// Intel ('GenuineIntel')? //

cmp ebx, 'uneG'
jne short not_intel
cmp edx, 'Ieni'
jne short not_intel
cmp ecx, 'letn'
je get_features
not_intel:

// Cyrix ('CyrixInstead')? //

cmp ebx, 'iryC'
jne short not_cyrix
cmp edx, 'snIx'
jne short not_cyrix
cmp ecx, 'deat'
je get_features
not_cyrix:

get_features:
cmp eax, 1
jb short done
mov eax, 1 // CPUID function 1 : Features + Version

cpuid
mov [dwStdFeatures], edx

// Next find out which extended features are present (if any) //

mov eax, 0x80000000 // CPUID 80000000 : how many extended features

cpuid
cmp eax, 0x80000001 // check for at least 1 extended function

jb short done
mov eax, 0x80000001 // CPUID 80000001 : Extended features list

cpuid
mov [dwExFeatures], edx
done:
}

if(!bHasCPUID)
return FALSE;

// FPU (Floating Point Unit) //

if(dwStdFeatures & 1<<0)
dwFeatures |= PF_FPU;
else
return FALSE;

// MMX (Multi Media eXtensions) //

if(dwStdFeatures & 1<<23)
dwFeatures |= PF_MMX;

// AMD MMX Extensions //

if(dwExFeatures & 1<<22)
dwFeatures |= PF_EMMX;

// AMD 3DNow! present //

if(dwExFeatures & 1<<31)
dwFeatures |= PF_3DNOW;

// AMD 3DNow! Extensions //

if(dwExFeatures & 1<<30)
dwFeatures |= PF_E3DNOW;

// SSE present //

if(dwStdFeatures & 1<<25)
dwFeatures |= PF_SSE;

return TRUE;
}


Edit: Damn tags messing up the source




[edited by - Evil Bill on January 15, 2003 3:45:31 PM]
Member of the Unban Mindwipe Society (UMWS)
S1CA
S1CA
Yep.

Search www.amd.com and developer.intel.com for

"CPUID"

You''ll find source code and docs regarding the extensions specific to each manufacturer.

Rough recipe (see their sites for code):

1) determine CPUID availability by writing to bit 21 of EFLAGS and seeing if it changes.

2) CPUID with EAX=0 to get vendor info AND highest value of EAX supported

3) CPUID with EAX=1 to get basic features + version

4) CPUID with EAX=0x80000000 to find out how many extended features

5) CPUID with EAX=0x80000001 to find which extended features

6) For standard features: bit0=FPU, bit23=MMX, bit22=AMD MMX additions

7) For extended features: bit31=3DNow!, bit30=Extended 3DNow!, bit25=SSE*


[You may want to double check the SSE bit - the doc I was going off when I wrote that the code above is based on was while SSE was still in beta]


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Jan Wassenberg
Jan Wassenberg
> SSE is a feature of the CPU so nothing to do with compiler, language or OS.
The OS has to save the SSE state on task switch via fxsave / fxrstor, and indicates this support by setting cr4.OSFXSR. I don''t know which *nix version(s) do this.
Note: MMX extensions and cache control instructions don''t change SSE state, so you can use them regardless.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
walkingcarcass
walkingcarcass
thanks! nice to get a swift and complete response once in a while

********


A Problem Worthy of Attack
Proves It''s Worth by Fighting Back
spraff.net: don't laugh, I'm still just starting...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.