godot/thirdparty/embree/kernels/bvh/bvh_traverser1.h

// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "bvh.h"
#include "node_intersector1.h"
#include "../common/stack_item.h"

#define NEW_SORTING_CODE

namespace embree
{
  namespace isa
  {
    /*! BVH regular node traversal for single rays. */
    template<int N, int types>
    class BVHNNodeTraverser1Hit;

#if defined(__AVX512VL__) // SKX

    template<int N>
    __forceinline void isort_update(vint<N> &dist, const vint<N> &d)
    {
      const vint<N> dist_shift = align_shift_right<N-1>(dist,dist);
      const vboolf<N> m_geq = d >= dist;
      const vboolf<N> m_geq_shift = m_geq << 1;
      dist = select(m_geq,d,dist);
      dist = select(m_geq_shift,dist_shift,dist);
    }

    template<int N>
    __forceinline void isort_quick_update(vint<N> &dist, const vint<N> &d) {
      dist = align_shift_right<N-1>(dist,permute(d,vint<N>(zero)));
    }

    __forceinline size_t permuteExtract(const vint8& index, const vllong4& n0, const vllong4& n1) {
      return toScalar(permutex2var((__m256i)index,n0,n1));
    }

    __forceinline float permuteExtract(const vint8& index, const vfloat8& n) {
      return toScalar(permute(n,index));
    }

#endif

    /* Specialization for BVH4. */
    BVHNNodeTraverser1Hit<4, types>;

    /* Specialization for BVH8. */
    BVHNNodeTraverser1Hit<8, types>;
  }
}