<commit_before>/*  This file is part of the Vc library. {{{

    Copyright (C) 2009-2012 <NAME> <<EMAIL>>

    Vc is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation, either version 3 of
    the License, or (at your option) any later version.

    Vc is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Vc.  If not, see <http://www.gnu.org/licenses/>.

}}}*/

#ifndef VC_MIC_VECTOR_H
#define VC_MIC_VECTOR_H

#ifdef CAN_OFFLOAD
#pragma offload_attribute(push, target(mic))
#endif

#include "types.h"
#include "intrinsics.h"
#include "casts.h"
#include "../common/storage.h"
#include "mask.h"
#include "vectorhelper.h"
#include "storemixin.h"
//#include "vectormultiplication.h"
#include "writemaskedvector.h"
#include "sorthelper.h"
#include "macros.h"

#ifdef isfinite
#undef isfinite
#endif
#ifdef isnan
#undef isnan
#endif

#define VC_HAVE_FMA

Vc_NAMESPACE_BEGIN(Vc_IMPL_NAMESPACE)

template<typename T> class Vector : public StoreMixin<Vector<T>, T>
{
    //friend class VectorMultiplication<T>;
    friend class WriteMaskedVector<T>;
    //friend Vector<T> operator+<>(const Vector<T> &x, const VectorMultiplication<T> &y);
    //friend Vector<T> operator-<>(const Vector<T> &x, const VectorMultiplication<T> &y);
    friend class Vector<float>;
    friend class Vector<double>;
    friend class Vector<int>;
    friend class Vector<unsigned int>;
    friend class StoreMixin<Vector<T>, T>;

public:
    FREE_STORE_OPERATORS_ALIGNED(64)
    typedef typename VectorTypeHelper<T>::Type VectorType;
    typedef typename DetermineEntryType<T>::Type EntryType;
    typedef typename DetermineVectorEntryType<T>::Type VectorEntryType;
    typedef Vector<unsigned int> IndexType;
    static constexpr size_t Size = sizeof(VectorType) / sizeof(VectorEntryType);
    enum Constants {
        MemoryAlignment = sizeof(EntryType) * Size,
        HasVectorDivision = true
    };
    typedef Vc_IMPL_NAMESPACE::Mask<Size> Mask;
    typedef typename Mask::AsArg MaskArg;
    typedef Vc::Memory<Vector<T>, Size> Memory;
    typedef Vector<T> AsArg; // for now only ICC can compile this code and it is not broken :)
    typedef VectorType VectorTypeArg;

    inline const VectorType data() const { return d.v(); }
    inline VectorType &data() { return d.v(); }

protected:
    // helper that specializes on VectorType
    typedef VectorHelper<VectorType> HV;

    // helper that specializes on T
    typedef VectorHelper<VectorEntryType> HT;

    typedef Common::VectorMemoryUnion<VectorType, VectorEntryType> StorageType;
    StorageType d;
    VC_DEPRECATED("renamed to data()") inline const VectorType vdata() const { return d.v(); }

    template<typename MemType> using UpDownC = UpDownConversion<VectorEntryType, typename std::remove_cv<MemType>::type>;

    template<typename V> static Vc_INTRINSIC VectorType _cast(VC_ALIGNED_PARAMETER(V) x) { return mic_cast<VectorType>(x); }

public:

    /**
     * Reinterpret some array of T as a vector of T. You may only do this if the pointer is
     * aligned correctly and the content of the memory isn't changed from somewhere else because
     * the load operation will happen implicitly at some later point(s).
     */
    static inline Vector fromMemory(T *mem) {
        assert(0 == (mem & (VectorAlignment - 1)));
        return reinterpret_cast<Vector<T> >(mem);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    // uninitialized
    inline Vector() {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // constants
    inline explicit Vector(VectorSpecialInitializerZero::ZEnum);
    inline explicit Vector(VectorSpecialInitializerOne::OEnum);
    inline explicit Vector(VectorSpecialInitializerIndexesFromZero::IEnum);
    static inline Vector Zero();
    static inline Vector One();
    static inline Vector IndexesFromZero();
    static Vector Random();

    ///////////////////////////////////////////////////////////////////////////////////////////
    // internal: required to enable returning objects of VectorType
    Vc_INTRINSIC Vector(VectorType x) : d(x) {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // copy
    Vc_INTRINSIC Vector(const Vector &x) : d(x.data()) {}
    Vc_INTRINSIC Vector &operator=(const Vector &v) { d.v() = v.d.v(); return *this; }

    // implict conversion from compatible Vector<U>
    template<typename U> Vc_INTRINSIC Vector(VC_ALIGNED_PARAMETER(Vector<U>) x,
            typename std::enable_if<is_implicit_cast_allowed<Vector<U>, Vector<T>>::value, void *>::type = nullptr)
        : d(StaticCastHelper<U, T>::cast(x.data())) {}

    // static_cast from the remaining Vector<U>
    template<typename U> Vc_INTRINSIC explicit Vector(VC_ALIGNED_PARAMETER(Vector<U>) x,
            typename std::enable_if<!is_implicit_cast_allowed<Vector<U>, Vector<T>>::value, void *>::type = nullptr)
        : d(StaticCastHelper<U, T>::cast(x.data())) {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // broadcast
    Vc_INTRINSIC Vector(EntryType a) : d(_set1(a)) {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // load ctors
    explicit Vc_INTRINSIC Vector(const EntryType * x) { load(x); }
    template<typename Flags = AlignedT> explicit Vc_INTRINSIC Vector(const EntryType * x, Flags flags = Flags())
    {
        load(x, flags);
    }
    template<typename OtherT, typename Flags = AlignedT> explicit Vc_INTRINSIC Vector(const OtherT *x, Flags flags = Flags())
    {
        load(x, flags);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    // load member functions
    Vc_INTRINSIC void load(const EntryType *mem) { load<AlignedT>(mem, Aligned); }
    template<typename Flags = AlignedT> Vc_INTRINSIC_L
        void load(const EntryType *mem, Flags) Vc_INTRINSIC_R;
    template<typename OtherT, typename Flags = AlignedT> Vc_INTRINSIC_L
        void load(const OtherT    *mem, Flags = Flags()) Vc_INTRINSIC_R;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // expand 1 float_v to 2 double_v                 XXX rationale? remove it for release? XXX
    // TODO: handle 8 <-> 16 conversions
    explicit Vc_ALWAYS_INLINE_L Vc_FLATTEN Vector(const Vector<typename ConcatTypeHelper<T>::Type> *a) Vc_ALWAYS_INLINE_R;
    Vc_ALWAYS_INLINE_R Vc_FLATTEN void expand(Vector<typename ConcatTypeHelper<T>::Type> *x) const Vc_ALWAYS_INLINE_R;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // zeroing<commit_msg>fix typo in macro name<commit_after>/*  This file is part of the Vc library. {{{

    Copyright (C) 2009-2012 <NAME> <<EMAIL>>

    Vc is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation, either version 3 of
    the License, or (at your option) any later version.

    Vc is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Vc.  If not, see <http://www.gnu.org/licenses/>.

}}}*/

#ifndef VC_MIC_VECTOR_H
#define VC_MIC_VECTOR_H

#ifdef CAN_OFFLOAD
#pragma offload_attribute(push, target(mic))
#endif

#include "types.h"
#include "intrinsics.h"
#include "casts.h"
#include "../common/storage.h"
#include "mask.h"
#include "vectorhelper.h"
#include "storemixin.h"
//#include "vectormultiplication.h"
#include "writemaskedvector.h"
#include "sorthelper.h"
#include "macros.h"

#ifdef isfinite
#undef isfinite
#endif
#ifdef isnan
#undef isnan
#endif

#define VC_HAVE_FMA

Vc_NAMESPACE_BEGIN(Vc_IMPL_NAMESPACE)

template<typename T> class Vector : public StoreMixin<Vector<T>, T>
{
    //friend class VectorMultiplication<T>;
    friend class WriteMaskedVector<T>;
    //friend Vector<T> operator+<>(const Vector<T> &x, const VectorMultiplication<T> &y);
    //friend Vector<T> operator-<>(const Vector<T> &x, const VectorMultiplication<T> &y);
    friend class Vector<float>;
    friend class Vector<double>;
    friend class Vector<int>;
    friend class Vector<unsigned int>;
    friend class StoreMixin<Vector<T>, T>;

public:
    FREE_STORE_OPERATORS_ALIGNED(64)
    typedef typename VectorTypeHelper<T>::Type VectorType;
    typedef typename DetermineEntryType<T>::Type EntryType;
    typedef typename DetermineVectorEntryType<T>::Type VectorEntryType;
    typedef Vector<unsigned int> IndexType;
    static constexpr size_t Size = sizeof(VectorType) / sizeof(VectorEntryType);
    enum Constants {
        MemoryAlignment = sizeof(EntryType) * Size,
        HasVectorDivision = true
    };
    typedef Vc_IMPL_NAMESPACE::Mask<Size> Mask;
    typedef typename Mask::AsArg MaskArg;
    typedef Vc::Memory<Vector<T>, Size> Memory;
    typedef Vector<T> AsArg; // for now only ICC can compile this code and it is not broken :)
    typedef VectorType VectorTypeArg;

    inline const VectorType data() const { return d.v(); }
    inline VectorType &data() { return d.v(); }

protected:
    // helper that specializes on VectorType
    typedef VectorHelper<VectorType> HV;

    // helper that specializes on T
    typedef VectorHelper<VectorEntryType> HT;

    typedef Common::VectorMemoryUnion<VectorType, VectorEntryType> StorageType;
    StorageType d;
    VC_DEPRECATED("renamed to data()") inline const VectorType vdata() const { return d.v(); }

    template<typename MemType> using UpDownC = UpDownConversion<VectorEntryType, typename std::remove_cv<MemType>::type>;

    template<typename V> static Vc_INTRINSIC VectorType _cast(VC_ALIGNED_PARAMETER(V) x) { return mic_cast<VectorType>(x); }

public:

    /**
     * Reinterpret some array of T as a vector of T. You may only do this if the pointer is
     * aligned correctly and the content of the memory isn't changed from somewhere else because
     * the load operation will happen implicitly at some later point(s).
     */
    static inline Vector fromMemory(T *mem) {
        assert(0 == (mem & (VectorAlignment - 1)));
        return reinterpret_cast<Vector<T> >(mem);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    // uninitialized
    inline Vector() {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // constants
    inline explicit Vector(VectorSpecialInitializerZero::ZEnum);
    inline explicit Vector(VectorSpecialInitializerOne::OEnum);
    inline explicit Vector(VectorSpecialInitializerIndexesFromZero::IEnum);
    static inline Vector Zero();
    static inline Vector One();
    static inline Vector IndexesFromZero();
    static Vector Random();

    ///////////////////////////////////////////////////////////////////////////////////////////
    // internal: required to enable returning objects of VectorType
    Vc_INTRINSIC Vector(VectorType x) : d(x) {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // copy
    Vc_INTRINSIC Vector(const Vector &x) : d(x.data()) {}
    Vc_INTRINSIC Vector &operator=(const Vector &v) { d.v() = v.d.v(); return *this; }

    // implict conversion from compatible Vector<U>
    template<typename U> Vc_INTRINSIC Vector(VC_ALIGNED_PARAMETER(Vector<U>) x,
            typename std::enable_if<is_implicit_cast_allowed<Vector<U>, Vector<T>>::value, void *>::type = nullptr)
        : d(StaticCastHelper<U, T>::cast(x.data())) {}

    // static_cast from the remaining Vector<U>
    template<typename U> Vc_INTRINSIC explicit Vector(VC_ALIGNED_PARAMETER(Vector<U>) x,
            typename std::enable_if<!is_implicit_cast_allowed<Vector<U>, Vector<T>>::value, void *>::type = nullptr)
        : d(StaticCastHelper<U, T>::cast(x.data())) {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // broadcast
    Vc_INTRINSIC Vector(EntryType a) : d(_set1(a)) {}

    ///////////////////////////////////////////////////////////////////////////////////////////
    // load ctors
    explicit Vc_INTRINSIC Vector(const EntryType * x) { load(x); }
    template<typename Flags = AlignedT> explicit Vc_INTRINSIC Vector(const EntryType * x, Flags flags = Flags())
    {
        load(x, flags);
    }
    template<typename OtherT, typename Flags = AlignedT> explicit Vc_INTRINSIC Vector(const OtherT *x, Flags flags = Flags())
    {
        load(x, flags);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    // load member functions
    Vc_INTRINSIC void load(const EntryType *mem) { load<AlignedT>(mem, Aligned); }
    template<typename Flags = AlignedT> Vc_INTRINSIC_L
        void load(const EntryType *mem, Flags) Vc_INTRINSIC_R;
    template<typename OtherT, typename Flags = AlignedT> Vc_INTRINSIC_L
        void load(const OtherT    *mem, Flags = Flags()) Vc_INTRINSIC_R;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // expand 1 float_v to 2 double_v                 XXX rationale? remove it for release? XXX
    // TODO: handle 8 <-> 16 conversions
    explicit Vc_ALWAYS_INLINE_L Vc_FLATTEN Vector(const Vector<typename ConcatTypeHelper<T>::Type> *a) Vc_ALWAYS_INLINE_R;
    Vc_ALWAYS_INLINE_L Vc_FLATTEN void expand(Vector<typename ConcatTypeHelper<T>::Type> *x) const Vc_ALWAYS_INLINE_R;

    ///////////////////////////////////////////////////////////////////////////////////////////
    // zeroing
{'fraction_non_alphanumeric': 0.20531519528784797, 'fraction_numerical': 0.0026646097749105954, 'mean_word_length': 2.343962485345838, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5150084', 'n_tokens_mistral': 3996, 'n_tokens_neox': 3849, 'n_words': 1169}