SIMD support...

Manu turkeyman at gmail.com
Fri Jan 6 13:43:12 PST 2012


On 6 January 2012 22:40, Martin Nowak <dawg at dawgfoto.de> wrote:

> On Fri, 06 Jan 2012 20:00:15 +0100, Manu <turkeyman at gmail.com> wrote:
>
>  On 6 January 2012 20:17, Martin Nowak <dawg at dawgfoto.de> wrote:
>>
>>  There is another benefit.
>>> Consider the following:
>>>
>>> __vec128 addps(__vec128 a, __vec128 b) pure
>>> {
>>>   __vec128 res = a;
>>>
>>>   if (__ctfe)
>>>   {
>>>       foreach(i; 0 .. 4)
>>>          res[i] += b[i];
>>>   }
>>>   else
>>>   {
>>>       asm (res, b)
>>>
>>>       {
>>>           addps res, b;
>>>       }
>>>   }
>>>   return res;
>>>
>>> }
>>>
>>>
>> You don't need to use inline ASM to be able to do this, it will work the
>> same with intrinsics.
>> I've detailed numerous problems with using inline asm, and complications
>> with extending the inline assembler to support this.
>>
>>  Don't get me wrong here. The idea is to find out if intrinsics
> can be build with the help of inlineable asm functions.
> The ctfe support is one good reason to go with a library solution.


/agree, this is a nice argument to support putting it in libraries.


> Most compilers can't reschedule code around inline asm blocks. There are a
>> lot of reasons for this, google can help you.
>> The main reason is that a COMPILER doesn't attempt to understand the
>> assembly it's being asked to insert inline. The information that it may
>> use
>>
> It doesn't have to understand the assembly.
> Wrapping these in functions creates an IR expression with inputs and
> outputs.
> Declaring them as pure gives the compiler free hands to apply whatever
> optimizations he does normally on an IR tree.
> Common subexpressions elimination, removing dead expressions...


These functions shouldn't be functions... if they're not all inlined, then
the implementation is broken.
Once you inline all these micro asm blocks; 100 small asm blocks inlined in
a single function, you're making a very hard time for the optimiser.


> Same problem as above. The compiler would need to understand enough about
>> assembly to perform optimisation on the assembly its self to clean this
>> up.
>> Using intrinsics, all the register allocation, load/store code, etc, is
>> all
>> in the regular realm of compiling the language, and the code generation
>> and
>> optimisation will all work as usual.
>>
>>  There is no informational difference between the intrinsic
>
> __m128 _mm_add_ps(__m128 a, __m128 b);
>
> and an inline assembler version
>

There is actually. To the compiler, the intrinsic is a normal function,
with some hook in the code generator to produce the appropriate opcode when
it's performing actual code generation.
On most compilers, the inline asm on the other hand, is unknown to the
compiler, the optimiser can't do much anymore, because it doesn't know what
the inline asm has done, and the code generator just goes and pastes your
asm code inline where you told it to. It doesn't know if you've written to
aliased variables, called functions, etc.. it can no longer safely
rearrange code around the inline asm block.. which means it's not free to
pipeline the code efficiently.

So the argument here is that intrinsics in D can easier be
> mapped to existing intrinsics in GCC?
> I do understand that this will be pretty difficult for GDC
> to implement.
> Reminds me that Walter has stated several times how much
> better an internal assembler can integrate with the language.


Basically yes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120106/77544408/attachment.html>


More information about the Digitalmars-d mailing list