arch-specific template code

Marc Glisse marc.glisse@inria.fr
Tue Aug 28 12:33:00 GMT 2012


On Tue, 28 Aug 2012, Ulrich Drepper wrote:

> On Mon, Aug 27, 2012 at 6:26 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
>> My personal opinion is that a concrete example, small, but meaningful and
>> rather self contained, would help. To be honest, at this stage, isn't clear
>> to me which kind of arch-specific optimizations you are thinking about.
>
> Here is a first example.  Note that for now I just added the code in
> the middle of random.tcc.  This is an implementation for the
> normal_distribution<double>::__generate<> function using SSE3.  The
> resulting code runs about 25% faster.  There is really no way to use
> the function for any other architecture because it heavily depends on
> the x86 intrinsics and hence the x86 instructions.

Actually, it looks to me like most of it can be rewritten using gcc's 
vector extensions. _mm_mul_pd(a,b) is just a*b, a[0] gives the first 
element, __m128d v={d1, d2} creates a vector, etc. I probably looked at it 
way too fast, but the only problematic instruction I found was hadd, and 
the fact that the compiler can't optimize v[0]+v[1] to hadd (on suitable 
architectures) yet is worth fixing. Then the only architecture specific 
part is deciding whether to use that code.

Am I missing some fundamental reason why this approach couldn't work? And 
if not for this specific function, possibly for some others? Endianness 
issues are all I could come up with.

-- 
Marc Glisse



More information about the Libstdc++ mailing list