<commit_before>// ======================================================================== //
// Copyright 2009-2013 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "bvh4hair_intersector1.h"
#include "geometry/bezier1i_intersector1.h"

namespace embree
{ 
  namespace isa
  {
#if 0
    __forceinline bool BVH4HairIntersector1::intersectBox(const BBox3fa& aabb, const Ray& ray, const Vec3fa& org_rdir, const Vec3fa& rdir, float& tNear, float& tFar)
    {
#if defined (__AVX2__)
      const Vec3fa tLowerXYZ = msub(aabb.lower,rdir,org_rdir);
      const Vec3fa tUpperXYZ = msub(aabb.upper,rdir,org_rdir);
#else
      const Vec3fa tLowerXYZ = (aabb.lower - ray.org) * rdir;
      const Vec3fa tUpperXYZ = (aabb.upper - ray.org) * rdir;
#endif

#if defined(__SSE4_1__)
      const Vec3fa tNearXYZ = mini(tLowerXYZ,tUpperXYZ);
      const Vec3fa tFarXYZ  = maxi(tLowerXYZ,tUpperXYZ);
      tNear = max(max(tNearXYZ.x,tNearXYZ.y),max(tNearXYZ.z,tNear)); // FIXME: using mini here makes things slower
      tFar  = min(min(tFarXYZ .x,tFarXYZ .y),min(tFarXYZ .z,tFar ));
      return tNear <= tFar;
#else
      const Vec3fa tNearXYZ = min(tLowerXYZ,tUpperXYZ);
      const Vec3fa tFarXYZ  = max(tLowerXYZ,tUpperXYZ);
      tNear = max(reduce_max(tNearXYZ),tNear);
      tFar  = min(reduce_min(tFarXYZ ),tFar);
      return tNear <= tFar;
#endif
    }
#endif

    __forceinline size_t BVH4HairIntersector1::intersectBox(const AffineSpaceSOA4& naabb, const Ray& ray, ssef& tNear, ssef& tFar)
    {
      const sse3f dir = xfmVector(naabb,sse3f(ray.dir));
      const sse3f rdir = rcp(dir);
      const sse3f org = xfmPoint (naabb,sse3f(ray.org));
      const sse3f tLowerXYZ = - org * rdir;     // (Vec3fa(zero) - org) * rdir;
      const sse3f tUpperXYZ = rdir + tLowerXYZ; // (Vec3fa(one ) - org) * rdir;

//#if defined(__SSE4_1__)
//      const sse3f tNearXYZ = mini(tLowerXYZ,tUpperXYZ);
//      const sse3f tFarXYZ  = maxi(tLowerXYZ,tUpperXYZ);
//#else
      const sse3f tNearXYZ = min(tLowerXYZ,tUpperXYZ);
      const sse3f tFarXYZ  = max(tLowerXYZ,tUpperXYZ);
//#endif

//#if defined(__SSE4_1__)
//        tNear = maxi(maxi(tNearX,tNearY),maxi(tNearZ,tNear));
//        tFar  = mini(mini(tFarX ,tFarY ),mini(tFarZ ,tFar));
//        const sseb vmask = cast(tNear) > cast(tFar);
//        size_t mask = movemask(vmask)^0xf;
//#else
        tNear = max(tNearXYZ.x,tNearXYZ.y,tNearXYZ.z,tNear);
        tFar  = min(tFarXYZ.x ,tFarXYZ.y ,tFarXYZ.z ,tFar);
        const sseb vmask = tNear <= tFar;
        size_t mask = movemask(vmask);
//#endif
      return mask;
    }

    __forceinline void BVH4HairIntersector1::intersectBezier(const LinearSpace3fa& ray_space, Ray& ray, const Bezier1& bezier)
    {
      /* load bezier curve control points */
      STAT3(normal.trav_prims,1,1,1);
      const Vec3fa& v0 = bezier.p0;
      const Vec3fa& v1 = bezier.p1;
      const Vec3fa& v2 = bezier.p2;
      const Vec3fa& v3 = bezier.p3;

      /* transform control points into ray space */
      Vec3fa w0 = xfmVector(ray_space,v0-ray.org); w0.w = v0.w;
      Vec3fa w1 = xfmVector(ray_space,v1-ray.org); w1.w = v1.w;
      Vec3fa w2 = xfmVector(ray_space,v2-ray.org); w2.w = v2.w;
      Vec3fa w3 = xfmVector(ray_space,v3-ray.org); w3.w = v3.w;
      BezierCurve3D curve2D(w0,w1,w2,w3,0.0f,1.0f,4);

      /* subdivide 3 levels at once */ 
      const avx4f p0 = curve2D.eval(coeff0[0],coeff0[1],coeff0[2],coeff0[3]);
      const avx4f p1 = curve2D.eval(coeff1[0],coeff1[1],coeff1[2],coeff1[3]);

      /* approximative intersection with cone */
      const avx4f v = p1-p0;
      const avx4f w = -p0;<commit_msg>some performance optimizations for bvh4hair<commit_after>// ======================================================================== //
// Copyright 2009-2013 Intel Corporation                                    //
//                                                                          //
// Licensed under the Apache License, Version 2.0 (the "License");          //
// you may not use this file except in compliance with the License.         //
// You may obtain a copy of the License at                                  //
//                                                                          //
//     http://www.apache.org/licenses/LICENSE-2.0                           //
//                                                                          //
// Unless required by applicable law or agreed to in writing, software      //
// distributed under the License is distributed on an "AS IS" BASIS,        //
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
// See the License for the specific language governing permissions and      //
// limitations under the License.                                           //
// ======================================================================== //

#include "bvh4hair_intersector1.h"
#include "geometry/bezier1i_intersector1.h"

namespace embree
{ 
  namespace isa
  {
#if 0
    __forceinline bool BVH4HairIntersector1::intersectBox(const BBox3fa& aabb, const Ray& ray, const Vec3fa& org_rdir, const Vec3fa& rdir, float& tNear, float& tFar)
    {
#if defined (__AVX2__)
      const Vec3fa tLowerXYZ = msub(aabb.lower,rdir,org_rdir);
      const Vec3fa tUpperXYZ = msub(aabb.upper,rdir,org_rdir);
#else
      const Vec3fa tLowerXYZ = (aabb.lower - ray.org) * rdir;
      const Vec3fa tUpperXYZ = (aabb.upper - ray.org) * rdir;
#endif

#if defined(__SSE4_1__)
      const Vec3fa tNearXYZ = mini(tLowerXYZ,tUpperXYZ);
      const Vec3fa tFarXYZ  = maxi(tLowerXYZ,tUpperXYZ);
      tNear = max(max(tNearXYZ.x,tNearXYZ.y),max(tNearXYZ.z,tNear)); // FIXME: using mini here makes things slower
      tFar  = min(min(tFarXYZ .x,tFarXYZ .y),min(tFarXYZ .z,tFar ));
      return tNear <= tFar;
#else
      const Vec3fa tNearXYZ = min(tLowerXYZ,tUpperXYZ);
      const Vec3fa tFarXYZ  = max(tLowerXYZ,tUpperXYZ);
      tNear = max(reduce_max(tNearXYZ),tNear);
      tFar  = min(reduce_min(tFarXYZ ),tFar);
      return tNear <= tFar;
#endif
    }
#endif

    __forceinline size_t BVH4HairIntersector1::intersectBox(const AffineSpaceSOA4& naabb, const Ray& ray, ssef& tNear, ssef& tFar)
    {
      const sse3f dir = xfmVector(naabb,sse3f(ray.dir));
      const sse3f rdir = rcp(dir);
      const sse3f org = xfmPoint(naabb,sse3f(ray.org));
      const sse3f tLowerXYZ = - org * rdir;     // (Vec3fa(zero) - org) * rdir;
      const sse3f tUpperXYZ = rdir + tLowerXYZ; // (Vec3fa(one ) - org) * rdir;

#if defined(__SSE4_1__)
      const ssef tNearX = mini(tLowerXYZ.x,tUpperXYZ.x);
      const ssef tNearY = mini(tLowerXYZ.y,tUpperXYZ.y);
      const ssef tNearZ = mini(tLowerXYZ.z,tUpperXYZ.z);
      const ssef tFarX  = maxi(tLowerXYZ.x,tUpperXYZ.x);
      const ssef tFarY  = maxi(tLowerXYZ.y,tUpperXYZ.y);
      const ssef tFarZ  = maxi(tLowerXYZ.z,tUpperXYZ.z);
      tNear = maxi(maxi(tNearX,tNearY),maxi(tNearZ,tNear));
      tFar  = mini(mini(tFarX ,tFarY ),mini(tFarZ ,tFar));
      const sseb vmask = cast(tNear) > cast(tFar);
      size_t mask = movemask(vmask)^0xf;
#else
      const ssef tNearX = min(tLowerXYZ.x,tUpperXYZ.x);
      const ssef tNearY = min(tLowerXYZ.y,tUpperXYZ.y);
      const ssef tNearZ = min(tLowerXYZ.z,tUpperXYZ.z);
      const ssef tFarX  = max(tLowerXYZ.x,tUpperXYZ.x);
      const ssef tFarY  = max(tLowerXYZ.y,tUpperXYZ.y);
      const ssef tFarZ  = max(tLowerXYZ.z,tUpperXYZ.z);
      tNear = max(tNearX,tNearY,tNearZ,tNear);
      tFar  = min(tFarX ,tFarY ,tFarZ ,tFar);
      const sseb vmask = tNear <= tFar;
      size_t mask = movemask(vmask);
#endif
      return mask;
    }

    __forceinline void BVH4HairIntersector1::intersectBezier(const LinearSpace3fa& ray_space, Ray& ray, const Bezier1& bezier)
    {
      /* load bezier curve control points */
      STAT3(normal.trav_prims,1,1,1);
      const Vec3fa& v0 = bezier.p0;
      const Vec3fa& v1 = bezier.p1;
      const Vec3fa& v2 = bezier.p2;
      const Vec3fa& v3 = bezier.p3;

      /* transform control points into ray space */
      Vec3fa w0 = xfmVector(ray_space,v0-ray.org); w0.w = v0.w;
      Vec3fa w1 = xfmVector(ray_space,v1-ray.org); w1.w = v1.w;
      Vec3fa w2 = xfmVector(ray_space,v2-ray.org); w2.w = v2.w;
      Vec3fa w3 = xfmVector(ray_space,v3-ray.org); w3.w = v3.w;
      BezierCurve3D curve2D(w0,w1,w2,w3,0.0f,1.0f,4);

      /* subdivide 3 levels at once */ 
      const avx4f p0 = curve2D.eval(coeff0[0],coeff0[1],coeff0[2],coeff0[3]);
      const avx4f p1 = curve2D.eval(coeff1[0],coeff1[1],coeff1[2],coeff1[3]);

      /* approximative intersection with cone */
      const avx4f v = p1-p0;
      const avx4f w = -p0;
{'fraction_non_alphanumeric': 0.14557288976133897, 'fraction_numerical': 0.02696559561938217, 'mean_word_length': 2.3529615517838587, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6712060', 'n_tokens_mistral': 3673, 'n_tokens_neox': 3461, 'n_words': 758}