Skip to content
Snippets Groups Projects
Select Git revision
  • d04d4da652cebc65020035822b79c6afc6da8c09
  • master default protected
2 results

sve_complex_float.hpp

Blame
  • Bine Brank's avatar
    Bine Brank authored
    d04d4da6
    History
    sve_complex_float.hpp 7.36 KiB
    /*
    
       Copyright (C) 2019, Forschungszentrum Juelich
    
       Author(s): Bine Brank, b.brank@fz-juelich.de
    
       Redistribution and use in source and binary forms, with or without
       modification, are permitted provided that the following conditions are
       met:
        - Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
        - Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in the
          documentation and/or other materials provided with the distribution.
        - Neither the name(s) of the copyright holder(s) nor the names of its
          contributors may be used to endorse or promote products derived
          from this software without specific prior written permission.
    
       THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    
    */
    
    #ifndef SVE_COMPLEX_FLOAT_HPP
    #define SVE_COMPLEX_FLOAT_HPP
    
    
    template<>
    struct svetype<complex<float>>{
        typedef svfloat32x2_t vec;
        typedef svuint32_t intvec;
        typedef complex<float> scal;
    
        static inline vec vload(svbool_t pg, const scal *base)
        { return svld2_f32(pg, (float32_t *) base); } 
    
        static inline vec vload_gatherindex(svbool_t pg, const scal *base, intvec indices )
        { 
            intvec index = svmul_z(pg, indices, 2);
            svfloat32_t real = svld1_gather_index(pg, (float32_t *) base, index);
            svfloat32_t imag = svld1_gather_index(pg, ((float32_t *) base) + 1, index);
            return {real, imag};
        } 
    
        static inline void vstore(svbool_t pg, scal* base, vec data)
        { svst2_f32(pg, (float32_t *) base, data); }
    
        static inline intvec index(int32_t base, int32_t step)
        { return svindex_u32(base, step); }
    
        static inline uint32_t count()
        { return svcntw(); }
    
        static inline svbool_t svtrue()
        { return svptrue_b32(); }
    
        static inline svbool_t svwhile(int32_t op1, int32_t op2)
        { return svwhilelt_b32(op1, op2); }
    
        static inline vec dup_all(scal op)
        { return {svdup_f32(real(op)), svdup_f32(imag(op))};}
    
        static inline vec dup_z(svbool_t pg, scal op)
        { return {svdup_f32_z(pg, real(op)), svdup_f32_z(pg, imag(op))};}
    
        static inline vec neg_z(svbool_t pg, vec op1)
        { return {svneg_f32_z(pg, op1.v0), svneg_f32_z(pg, op1.v1)}; }
    
        static inline svfloat32_t abs_z(svbool_t pg, vec op1)
        {
            svfloat32_t temp = svmul_f32_z(pg, op1.v0, op1.v0);
            temp = svmla_f32_z(pg, temp, op1.v1, op1.v1); 
            return svsqrt_f32_z(pg, temp);
        }
    
        static inline vec conj_z(svbool_t pg, vec op1)
        { return {op1.v0, svneg_f32_z(pg, op1.v1)}; }
    
        static inline vec mulscal_z(svbool_t pg, vec op1, scal op2)
        { 
            svfloat32_t retemp = svmul_n_f32_z(pg, op1.v0, op2.real());
            svfloat32_t imtemp = svmul_n_f32_z(pg, op1.v0, op2.imag());
            svfloat32_t re = svmls_n_f32_z(pg, retemp, op1.v1, op2.imag()); 
            svfloat32_t im = svmla_n_f32_z(pg, imtemp, op1.v1, op2.real()); 
            return {re, im};
        }
    
        static inline vec and_z(svbool_t pg, vec op1, vec op2)
        {
            svuint32_t re = svand_z(pg, svreinterpret_u32(op1.v0), svreinterpret_u32(op2.v0));
            svuint32_t im = svand_z(pg, svreinterpret_u32(op1.v1), svreinterpret_u32(op2.v1));
            return {svreinterpret_f32(re), svreinterpret_f32(im)};
        }
    
        static inline vec orr_z(svbool_t pg, vec op1, vec op2)
        {
            svuint32_t re = svorr_z(pg, svreinterpret_u32(op1.v0), svreinterpret_u32(op2.v0));
            svuint32_t im = svorr_z(pg, svreinterpret_u32(op1.v1), svreinterpret_u32(op2.v1));
            return {svreinterpret_f32(re), svreinterpret_f32(im)};
        }
    
        static inline vec eor_z(svbool_t pg, vec op1, vec op2)
        {
            svuint32_t re = sveor_z(pg, svreinterpret_u32(op1.v0), svreinterpret_u32(op2.v0));
            svuint32_t im = sveor_z(pg, svreinterpret_u32(op1.v1), svreinterpret_u32(op2.v1));
            return {svreinterpret_f32(re), svreinterpret_f32(im)};
        }
    
        static inline vec not_z(svbool_t pg, vec op1, vec op2)
        {
            svuint32_t re = svnot_z(pg, svreinterpret_u32(op1.v0), svreinterpret_u32(op2.v0));
            svuint32_t im = svnot_z(pg, svreinterpret_u32(op1.v1), svreinterpret_u32(op2.v1));
            return {svreinterpret_f32(re), svreinterpret_f32(im)};
        }
    
        // vector vector operations
        static inline vec add_z(svbool_t pg, vec op1, vec op2)
        {
            svfloat32_t re = svadd_f32_z(pg, op1.v0, op2.v0);
            svfloat32_t im = svadd_f32_z(pg, op1.v1, op2.v1);
            return {re, im};
        }
    
        static inline vec sub_z(svbool_t pg, vec op1, vec op2)
        {
            svfloat32_t re = svsub_f32_z(pg, op1.v0, op2.v0);
            svfloat32_t im = svsub_f32_z(pg, op1.v1, op2.v1);
            return {re, im};
        }
    
        static inline vec mul_z(svbool_t pg, vec op1, vec op2)
        {
            svfloat32_t retemp = svmul_f32_z(pg, op1.v0, op2.v0);
            svfloat32_t imtemp = svmul_f32_z(pg, op1.v0, op2.v1);
            svfloat32_t re = svmls_f32_z(pg, retemp, op1.v1, op2.v1); 
            svfloat32_t im = svmla_f32_z(pg, imtemp, op1.v1, op2.v0); 
            return {re, im};
    
        }
    
        static inline vec div_z(svbool_t pg, vec op1, vec op2)
        {
            svfloat32_t retemp = svmul_f32_z(pg, op1.v0, op2.v0);
            svfloat32_t imtemp = svmul_f32_z(pg, op1.v1, op2.v0);
            svfloat32_t re = svmla_f32_z(pg, retemp, op1.v1, op2.v1); 
            svfloat32_t im = svmla_f32_z(pg, retemp, op1.v0, op2.v1); 
            svfloat32_t denom = svadd_f32_z(pg, svmul_f32_z(pg, op2.v0, op2.v0), svmul_f32_z(pg, op2.v1, op2.v1));
            return {svdiv_f32_z(pg, re, denom), svdiv_f32_z(pg, im, denom)};
    
        }
    
        static inline vec muladdscalar_z(svbool_t pg, vec op1, vec op2, scal op3)
        {
            svfloat32_t retemp = svmla_n_f32_z(pg, op1.v0, op2.v0, op3.real());
            svfloat32_t imtemp = svmla_n_f32_z(pg, op1.v1, op2.v0, op3.imag());
            svfloat32_t re = svmls_n_f32_z(pg, retemp, op2.v1, op3.imag());
            svfloat32_t im = svmla_n_f32_z(pg, imtemp, op2.v1, op3.real());
            return { re, im };
        }
    
        static inline scal reduce_sum( svbool_t pg, vec op )
        { return svaddv_f32(pg, op.v0) + svaddv_f32(pg, op.v1) * (complex<float>)1i; }
    
        static inline vec max_z(svbool_t pg, vec op1, vec op2)
        {
            svfloat32_t temp1 = abs_z(pg, op1);
            svfloat32_t temp2 = abs_z(pg, op2);
            svbool_t cmp = svcmpgt_f32(pg, temp1, temp2);
            return { svsel(cmp, op1.v0, op2.v0), svsel(cmp, op1.v1, op2.v1) };
        }
    
        static inline vec min_z(svbool_t pg, vec op1, vec op2)
        {
            svfloat32_t temp1 = abs_z(pg, op1);
            svfloat32_t temp2 = abs_z(pg, op2);
            svbool_t cmp = svcmplt_f32(pg, temp1, temp2);
            return { svsel(cmp, op1.v0, op2.v0), svsel(cmp, op1.v1, op2.v1) };
        }
    };
    
    #endif // SVE_COMPLEX_FLOAT_HPP