x86 Assembly Programming Guidelines?

All development related issues welcome

Moderator: Moderator Team

x86 Assembly Programming Guidelines?

Postby mattst88 » Mon Jan 01, 2007 9:23 am

When coding for ReactOS, are there guidelines for assembly programming? Can MMX/3DNow!/SSE code be used or is there a specific emphasis on maintaining compatibility with processors that do not support these features?

Obviously it is possible to write portable (across x86 processors) assembly that uses the cpuid instruction to check for the presence of the SIMD instruction sets, but there are even x86 processors without the cpuid instruction.

My question ultimately boils down to: to what extent should coders maintain backwards compatibility with aging x86 processors?

Should all functions using inline SIMD assembly utilize cpuid to verify the CPU supports the said instruction set and if not use a fallback?
mattst88
 
Posts: 4
Joined: Sun Nov 20, 2005 9:19 pm

Postby hto » Mon Jan 01, 2007 5:47 pm

IMO, CPUID should not be used. Because there is Win32 function GetSystemInfo(), which can give processor type. It is more portable.
hto
 
Posts: 2188
Joined: Sun Oct 01, 2006 3:43 pm

Postby oiaohm » Wed Jan 03, 2007 2:38 am

There is more of importance of keeping compatibility with platforms.

There are cases where there is no gain going to asm. Number one asm does not optimize by most compliers. So can not be processed out by the complier. Ie block of code called with all constant values and a constant result. Many not even exist in the completed binary.
Poor Example
Code: Select all
void reducing() {
int c,a;
c=10;
a=c+5;
c=a;
};


A function like this would not even exist in completed code. Because the complier knows it does nothing. It would simplely be removed by the optimiser.

Now if you put some asm in there the complier is no longer sure.

Note compliers like gcc and msvc will produce a lot of MMX/3DNow!/SSE code from C just by telling it to build for a processor supporting it. And in some cases turning on options.

Its not only compatibility with aging processors. There are still new X86 compatible processors produced where CPUID is optional. Transmedia processors for one.

Asm is for special things. Really special things. Using it can have real negative effects.

The best way of handling processor depend features is not cpuid because that can get you into trouble. The best way is as hto said GetSystemInfo(). If it needs to be patched for the reason that CPUID is missing or not working ie chip broken. Your code will still work.

Also other version functions. With dlls have exports as points to functions when dll is loaded points set to the correct functions for current processor.

Yes it is possible to build a C files with different processor options and bind it into one dll. So the speed boost can be gained in some cases without droping to asm. Lot simpler in the long run. Since if setup right the C code can be exactly the same for all processor types. Even that it performs a lot differently at run time. Spliting of functions inside C is done by using the complier command line define so that the start of the function gets named processor type.

There is more than one way of getting to the same end resualt.
Some are simpler to look after.

If working at kernel level there should be a equal function to GetSystemInfo().

Please just don't use ASM because you think it will be faster. It better be faster than what the C complier will produce.
oiaohm
 
Posts: 1322
Joined: Sun Dec 12, 2004 8:40 am

Postby GreatLord » Wed Jan 03, 2007 7:00 am

Hi
in reactos we optimze few thing with pure asm. Reason for it is gcc or msvc can not produce good asm code and we need all speed bost we can get. But optimzing stuff in asm are not a easy task and it take long time todo.

example of stuff we have optimze
memcpy = it is writen both in C and ASM for no compiler can optimze it
good so we need hand optimze it.

memmove = it is writen both in C and ASM for no compiler can optimze it
good so we need hand optimze it.

few bltblt stuff = it is writen both in C and ASM for no compiler can optimze it

so on.

optimze stuff in asm are not easy and u really need known what u are doing. if u whant optimze some thing in asm for ReactOS do it. But u need also test all case it can come, and it is really working.

ReactOS build system we can define diffent asm optimzing for a certly cpu
without using cpuid or any other. we doing a compiler flag thing say this version should only run on xxx and higher. at moment we have put the defualt build flags to I486, so all C code are optimze for I486 and higher.
see config.xml for setting.
GreatLord
Developer
 
Posts: 926
Joined: Tue Nov 30, 2004 10:26 am
Location: Sweden


Return to Development Help

Who is online

Users browsing this forum: No registered users and 3 guests