Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is simd code a standard code that can be used to optimize any program


really i'v a problem in thinking about this code


Thanks for all helps :-D
Posted
Updated 22-Apr-10 21:59pm
v5

SIMD is processor architecture. C# is a language that is compiled for a virtual "universal processor" (the CIL, or MSIL), which is then again optimised to run on the physical processor. As such, C# is very remote from the physical processor's architecture. If C# was to take advantage of SIMD architectures, this would not be impossible, but it would be an effect of the porting of the CIL to an SIMD architecture, and of optimisations that lay way beyong the reach of C#. The latest incarnation of C# (4.0) already contain various optimisation possiblities towards parallelisation, but NOT optimisations towards SIMD architectures. If you want to look at code for SIMD architectures, you will have to (today) look at very much lower languages, and to my knowledge, at the pure assembly language (for example the instructions for Intel's MMX instructions). Higher level-languages, like C#, or C, may attempt to profit from these instructions, but this will always be through their compilers attempt at optimisation. Now, there may be higher-level languages that offer you the option of targeting these architectures, but you are in the area of fundamental research here. I suggest you orient your query to more 'academic' forum.
Oh, yes and BTW, SIMD cannot be used to optimise 'any' code. The application area of SIMD is quite narrow, and mostly applies to Vector and Matrix operations, which makes it very well suited to graphics and visualisation.
 
Share this answer
 
v2
There is no way to explicitly use SIMD instructions in .NET. I'm pretty sure that the CLR will use them if available, but to ensure their use in your own code you'll have to write the routines using SIMD in something else like C/C++/assembly, compile them as a separate library of native code, and call them using P/Invoke.
 
Share this answer
 
Use C or C++ for this, that would be a better option for your requirement.
 
Share this answer
 
This just cannot be done in C#.
I suppose you want to use the MMX instruction set to do this.
You should build a library in C/C++ which
- Checks if the processor has the MMX instruction set.
- Emit assembly code for using MMX.
- If the processor does not support MMX, you'll have to supply a fallback using normal calculations.
Do not call this library for every calculation you want to perform: gather a fair bit of application data, and then P/Invoke your lib to do a series of calculations. If you call your library for every calculation, the overhead of P/Invoke will easily negate any performance gain, and your program will be slower than if you'd just let the CLR do it's thing.

A nice writeup on this can be found Here[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900