Skip to main content
GameDev.net gamedev.net
🔒 Locked

SIMD

Started by ArnoAtWork Mar 19, 2003 at 3:42 PM 7 replies 300+ views
Original Post
ArnoAtWork
ArnoAtWork
I tried to understand something. You program something and you use PIII assembler instructions. If you have the good compiler, everything is great and you have an optimised program. Obviously, the PIII instructions can only be compiled on PC because Intel is for PC, but what is going on if you run the application on AMD? As the program will call PIII instructions, does a AMD can easily understand and execute correctly what is asked?
JohnBolton
JohnBolton
If the instruction is not supported by the processor, you will get an "illegal instruction" exception (or something like that). Same with 3DNow instructions on an Intel CPU or SIMD on a PII.

Also, you can still compile the code on a machine that can''t run it.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
n0ob
n0ob
It is most likely the case that AMD is compatible with Intel commands. When IBM created their first PC, they used Intel. All other pcs after that which claimed to be IBM compatible had to be compatible. Thus, it''s likely that AMD is compatible with Intel. ?

Kings of Chaos
ArnoAtWork
ArnoAtWork
I am surprised.

A lot of software uses assembler to be optimised. So, how to developp a library to be used by all processor but also to be optimised when it''s possible?
Omaha
Omaha
Provided you have a compiler capable, you should be able to build a program for ANY platform on ANY platform.

Executing, on the other hand, is where that target platform becomes important. If you try and feed a program with SPARC instructions into an Intel box you''ll probably end up disappointed.

However, I''m pretty sure AMD CPUs (At least he current batch, the new ones are another story) are compatible with Intel''s ISA. Both Intel and AMD have their "specialized" instructions, 3DNow, etc., and when those come into play you might have to switch off code, but the basic instructions should accomplish the same goal.
Jan Wassenberg
Jan Wassenberg
quote:
A lot of software uses assembler to be optimised. So, how to developp a library to be used by all processor but also to be optimised when it''s possible?

You''ll need to write a code path for each relevant CPU family; 3 ways to choose the code to run:
1) compile at install - probably the nicest way to do it, but not feasible on consumer Windows boxes
2) assign function pointer based on CPU detection at runtime - performance penalty, especially if it''s a small piece of code
3) copy the appropriate code into a buffer in your code seg on initialization - this is a bit more work, but no runtime penalty.

Athlon XPs, to the best of my knowledge, support a superset of the P3''s features, including SSE. P4s and XPs also have mutually incompatible instructions (SSE2 and 3DNow! [pro]).

500x1
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
ArnoAtWork
ArnoAtWork
>3) copy the appropriate code into a buffer in your code seg on initialization - this is a bit more work, but no runtime penalty

How do you do that?
Jan Wassenberg
Jan Wassenberg
> SIMD is out. WOMD is in.
hehe
While we''re at it:
Q: How does America know Iraq possesses WMD?
A: They kept the receipts.

harr

somewhat more seriously:
1) write a dummy function p, fill it with n nops or int3s or whatever (n = max{k} sizeof(code_path[k])).
This is best done in asm (times n db 0x90).
2) enable write access to p with VirtualProtect
3) copy desired code into p
4) restore protection
-> good to go.
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

Topic Locked

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

Sign in to reply to this topic.