A little Py Vs C++

Jens Mueller jens.k.mueller at gmx.de
Fri Nov 2 07:22:22 PDT 2012


Don Clugston wrote:
> On 02/11/12 11:57, Jens Mueller wrote:
> >Peter Alexander wrote:
> >>On Friday, 2 November 2012 at 10:24:34 UTC, Jens Mueller wrote:
> >>>Then I have a serious misunderstanding.
> >>>I thought D introduced array operations to allow the compiler to
> >>>generate efficient vector operations (in the long run), i.e.
> >>>generate
> >>>SIMD code. Why is this not working out?
> >>
> >>It works fine for large vectors. For small vectors, it is
> >>horrendously slow.
> >>
> >>The syntax a[] += b[] essentially calls a function which is designed
> >>to work for large vectors. It has to determine alignment, load
> >>everything from memory, do the operations, then store it back.
> >>
> >>The SIMD extensions allow you to define variables that are
> >>guaranteed to be aligned and will probably be in the right registers
> >>to start with. Using them, the vectors ops don't need to determine
> >>alignment, and often don't need to do lots of loads/stores.
> >>
> >>Both have their purposes.
> >
> >I see. But can't the alignment problem be solved by using align. Then
> >have the compiler emits a call that checks for alignment if none was
> >specified else use a faster version.
> 
> No. For SIMD, you cannot afford to have even a single machine
> instruction inserted, or the benefit is entirely lost.

But the compiler knows about the alignment, doesn't it?

align(16) float[4] a;
vs
float[4] a;

In the former case the compiler can generate better code and it should.
The above syntax is not supported. But my point is all the compiler
cares about is the alignment which can be specified in the code somehow.
Sorry for being stubborn.

Jens


More information about the Digitalmars-d mailing list