Giter Site home page Giter Site logo

Comments (5)

AgnerF avatar AgnerF commented on June 16, 2024

Try this

#include "vectorclass.h"
#include "vectormath_trig.h"
#include "complexvec1.h"
...

    Complex4f a = ...
    // separate real and imaginary parts
    Vec8f b = permute8<0,2,4,6,1,3,5,7>(a.to_vector());
    Vec4f re = b.get_low();
    Vec4f im = b.get_high();
    Vec4f angle = atan2(im,re);
    Vec4f radius = sqrt(re*re + im*im);
    // join real and imag parts back together
    Vec8f c = permute8<0,4,1,5,2,6,3,7>(Vec8f(re,im));
    Complex4f d = Complex4f(c);  // d = a

from add-on.

robinchrist avatar robinchrist commented on June 16, 2024

I know this way and I also use it, but I think it would be more intuitive and comfortable if you wouldn't have to do this "manually".

from add-on.

AgnerF avatar AgnerF commented on June 16, 2024

It is awkward to make a function with two return values in C++. But it may be useful to have a few examples in the manual showing how to separate real and imaginary parts.

from add-on.

robinchrist avatar robinchrist commented on June 16, 2024

I thought about something like

Vec16f to_deinterleaved_vector() const {
    return permute16<0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 15>(y);
}

This would drastically reduce the probability of typos in the template argument (and thus bugs which are quite difficult to track down).

I also think it's efficient enough:
https://godbolt.org/z/-zqz6U
Clang generates the same code for the first three variants, but seems to be confused by the fourth.
Which do you think would be the most efficient?
I suppose the

        vmovaps ymmword ptr [rsi], ymm2
        vmovaps ymmword ptr [rdx], ymm0
        vzeroupper

would disappear in practice when the function is inlined by the compiler.

For AVX512 instruction set, there are differences in the generated code:
https://godbolt.org/z/ejkGYL

from add-on.

AgnerF avatar AgnerF commented on June 16, 2024

Functions to interleave and split into real and imag parts are added now

from add-on.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.