<commit_before>// ======================================================================== //
// Copyright 2009-2014 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.                                           //
// ======================================================================== //

#pragma once

#include "primitive.h"
#include "common/scene_subdivision.h"

#define SUBDIVISION_LEVEL_DISPL 8

namespace embree
{
  struct SubdivPatchDispl1
  {
    struct Type : public PrimitiveType 
    {
      Type ();
      size_t blocks(size_t x) const; 
      size_t size(const char* This) const;
    };

    static Type type;

    /*! branching width of the tree */
    static const size_t N = 4;

    struct Node
    {
      /*! Clears the node. */
      __forceinline void clear() {
        lower_x = lower_y = lower_z = pos_inf; 
        upper_x = upper_y = upper_z = neg_inf;
      }
      
      /*! Sets bounding box of child. */
      __forceinline void set(size_t i, const BBox3fa& bounds) 
      {
        assert(i < N);
        lower_x[i] = bounds.lower.x; lower_y[i] = bounds.lower.y; lower_z[i] = bounds.lower.z;
        upper_x[i] = bounds.upper.x; upper_y[i] = bounds.upper.y; upper_z[i] = bounds.upper.z;
      }
      
      /*! Returns bounds of specified child. */
      __forceinline BBox3fa bounds(size_t i) const 
      {
        assert(i < N);
        const Vec3fa lower(lower_x[i],lower_y[i],lower_z[i]);
        const Vec3fa upper(upper_x[i],upper_y[i],upper_z[i]);
        return BBox3fa(lower,upper);
      }

      /*! intersection with single rays */
      template<bool robust>
      __forceinline size_t intersect(size_t nearX, size_t nearY, size_t nearZ,
                                     const sse3f& org, const sse3f& rdir, const sse3f& org_rdir, const ssef& tnear, const ssef& tfar, 
                                     ssef& dist) const
      {
        const size_t farX  = nearX ^ sizeof(ssef), farY  = nearY ^ sizeof(ssef), farZ  = nearZ ^ sizeof(ssef);
#if defined (__AVX2__)
        const ssef tNearX = msub(load4f((const char*)&lower_x+nearX), rdir.x, org_rdir.x);
        const ssef tNearY = msub(load4f((const char*)&lower_x+nearY), rdir.y, org_rdir.y);
        const ssef tNearZ = msub(load4f((const char*)&lower_x+nearZ), rdir.z, org_rdir.z);
        const ssef tFarX  = msub(load4f((const char*)&lower_x+farX ), rdir.x, org_rdir.x);
        const ssef tFarY  = msub(load4f((const char*)&lower_x+farY ), rdir.y, org_rdir.y);
        const ssef tFarZ  = msub(load4f((const char*)&lower_x+farZ ), rdir.z, org_rdir.z);
#else
        const ssef tNearX = (load4f((const char*)&lower_x+nearX) - org.x) * rdir.x;
        const ssef tNearY = (load4f((const char*)&lower_x+nearY) - org.y) * rdir.y;
        const ssef tNearZ = (load4f((const char*)&lower_x+nearZ) - org.z) * rdir.z;
        const ssef tFarX  = (load4f((const char*)&lower_x+farX ) - org.x) * rdir.x;
        const ssef tFarY  = (load4f((const char*)&lower_x+farY ) - org.y) * rdir.y;
        const ssef tFarZ  = (load4f((const char*)&lower_x+farZ ) - org.z) * rdir.z;
#endif

        if (robust) {
          const float round_down = 1.0f-2.0f*float(ulp);
          const float round_up   = 1.0f+2.0f*float(ulp);
          const ssef tNear = max(tNearX,tNearY,tNearZ,tnear);
          const ssef tFar  = min(tFarX ,tFarY ,tFarZ ,tfar);
          const sseb vmask = round_down*tNear <= round_up*tFar;
          const size_t mask = movemask(vmask);
          dist = tNear;
          return mask;
        }
        
#if defined(__SSE4_1__)
        const ssef tNear = maxi(maxi(tNearX,tNearY),maxi(tNearZ,tnear));
        const ssef tFar  = mini(mini(tFarX ,tFarY ),mini(tFarZ ,tfar ));
        const sseb vmask = cast(tNear) > cast(tFar);
        const size_t mask = movemask(vmask)^0xf;
#else
        const ssef tNear = max(tNearX,tNearY,tNearZ,tnear);
        const ssef tFar  = min(tFarX ,tFarY ,tFarZ ,tfar);
        const sseb vmask = tNear <= tFar;
        const size_t mask = movemask(vmask);
#endif
        dist = tNear;
        return mask;
      }
      
    public:
      ssef lower_x;           //!< X dimension of lower bounds of all 4 children.
      ssef upper_x;           //!< X dimension of upper bounds of all 4 children.
      ssef lower_y;           //!< Y dimension of lower bounds of all 4 children.
      ssef upper_y;           //!< Y dimension of upper bounds of all 4 children.
      ssef lower_z;           //!< Z dimension of lower bounds of all 4 children.
      ssef upper_z;           //!< Z dimension of upper bounds of all 4 children.
    };
    
    struct SubTree
    {
    public:
      
      __forceinline SubTree(unsigned x, unsigned y, Array2D<Vec3fa>& vertices, unsigned levels, unsigned geomID, unsigned primID)
        : bx(x), by(y), vertices(vertices), levels(levels-1), geomID(geomID), primID(primID)
      {
        build(nodes,0,0,0);
      }
      
      const BBox3fa build(Node* node, unsigned x, unsigned y, unsigned l)
      {
        if (l == levels) {
          BBox3fa bounds = empty;
          x *= 2; y *= 2;
          bounds.extend(vertices(bx+x+0,by+y+0));
          bounds.extend(vertices(bx+x+1,by+y+0));
          bounds.extend(vertices(bx+x+2,by+y+0));
          bounds.extend(vertices(bx+x+0,by+y+1));
          bounds.extend(vertices(bx+x+1,by+y+1));
          bounds.extend(vertices(bx+x+2,by+y+1));
          bounds.extend(vertices(bx+x+0,by+y+2));
          bounds.extend(vertices(bx+x+1,by+y+2));
          bounds.extend(vertices(bx+x+2,by+y+2));
          return bounds;
        }
        const size_t w = 1<<l;
        const BBox3fa b00 = build(node+w*w,2*x+0,2*y+0,l+1); node[y*w+x].set(0,b00);
        const BBox3fa b10 = build(node+w*w,2*x+1,2*y+0,l+1); node[y*w+x].set(1,b10);
        const BBox3fa b01 = build(node+w*w,2*x+0,2*y+1,l+1); node[y*w+x].set(2,b01);
        const BBox3fa b11 = build(node+w*w,2*x+1,2*y+1,l+1); node[y*w+x].set(3,b11);
        return merge(b00,b10,b01,b11);
      }
      
    public:
      unsigned bx,by;            //!< coordinates of subtree
      Array2D<Vec3fa>& vertices; //!< pointer to vertices
      unsigned levels;           //!< number of stored levels
      unsigned primID;
      unsigned geomID;
      Node nodes[];
      //Node n0;                  //!< root node
      //Node n00, n01, n10, n11;  //!< child nodes
    };
    
  public:
    <commit_msg>Changed unsized array to have size 1 to be conform to C++.<commit_after>// ======================================================================== //
// Copyright 2009-2014 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.                                           //
// ======================================================================== //

#pragma once

#include "primitive.h"
#include "common/scene_subdivision.h"

#define SUBDIVISION_LEVEL_DISPL 8

namespace embree
{
  struct SubdivPatchDispl1
  {
    struct Type : public PrimitiveType 
    {
      Type ();
      size_t blocks(size_t x) const; 
      size_t size(const char* This) const;
    };

    static Type type;

    /*! branching width of the tree */
    static const size_t N = 4;

    struct Node
    {
      /*! Clears the node. */
      __forceinline void clear() {
        lower_x = lower_y = lower_z = pos_inf; 
        upper_x = upper_y = upper_z = neg_inf;
      }
      
      /*! Sets bounding box of child. */
      __forceinline void set(size_t i, const BBox3fa& bounds) 
      {
        assert(i < N);
        lower_x[i] = bounds.lower.x; lower_y[i] = bounds.lower.y; lower_z[i] = bounds.lower.z;
        upper_x[i] = bounds.upper.x; upper_y[i] = bounds.upper.y; upper_z[i] = bounds.upper.z;
      }
      
      /*! Returns bounds of specified child. */
      __forceinline BBox3fa bounds(size_t i) const 
      {
        assert(i < N);
        const Vec3fa lower(lower_x[i],lower_y[i],lower_z[i]);
        const Vec3fa upper(upper_x[i],upper_y[i],upper_z[i]);
        return BBox3fa(lower,upper);
      }

      /*! intersection with single rays */
      template<bool robust>
      __forceinline size_t intersect(size_t nearX, size_t nearY, size_t nearZ,
                                     const sse3f& org, const sse3f& rdir, const sse3f& org_rdir, const ssef& tnear, const ssef& tfar, 
                                     ssef& dist) const
      {
        const size_t farX  = nearX ^ sizeof(ssef), farY  = nearY ^ sizeof(ssef), farZ  = nearZ ^ sizeof(ssef);
#if defined (__AVX2__)
        const ssef tNearX = msub(load4f((const char*)&lower_x+nearX), rdir.x, org_rdir.x);
        const ssef tNearY = msub(load4f((const char*)&lower_x+nearY), rdir.y, org_rdir.y);
        const ssef tNearZ = msub(load4f((const char*)&lower_x+nearZ), rdir.z, org_rdir.z);
        const ssef tFarX  = msub(load4f((const char*)&lower_x+farX ), rdir.x, org_rdir.x);
        const ssef tFarY  = msub(load4f((const char*)&lower_x+farY ), rdir.y, org_rdir.y);
        const ssef tFarZ  = msub(load4f((const char*)&lower_x+farZ ), rdir.z, org_rdir.z);
#else
        const ssef tNearX = (load4f((const char*)&lower_x+nearX) - org.x) * rdir.x;
        const ssef tNearY = (load4f((const char*)&lower_x+nearY) - org.y) * rdir.y;
        const ssef tNearZ = (load4f((const char*)&lower_x+nearZ) - org.z) * rdir.z;
        const ssef tFarX  = (load4f((const char*)&lower_x+farX ) - org.x) * rdir.x;
        const ssef tFarY  = (load4f((const char*)&lower_x+farY ) - org.y) * rdir.y;
        const ssef tFarZ  = (load4f((const char*)&lower_x+farZ ) - org.z) * rdir.z;
#endif

        if (robust) {
          const float round_down = 1.0f-2.0f*float(ulp);
          const float round_up   = 1.0f+2.0f*float(ulp);
          const ssef tNear = max(tNearX,tNearY,tNearZ,tnear);
          const ssef tFar  = min(tFarX ,tFarY ,tFarZ ,tfar);
          const sseb vmask = round_down*tNear <= round_up*tFar;
          const size_t mask = movemask(vmask);
          dist = tNear;
          return mask;
        }
        
#if defined(__SSE4_1__)
        const ssef tNear = maxi(maxi(tNearX,tNearY),maxi(tNearZ,tnear));
        const ssef tFar  = mini(mini(tFarX ,tFarY ),mini(tFarZ ,tfar ));
        const sseb vmask = cast(tNear) > cast(tFar);
        const size_t mask = movemask(vmask)^0xf;
#else
        const ssef tNear = max(tNearX,tNearY,tNearZ,tnear);
        const ssef tFar  = min(tFarX ,tFarY ,tFarZ ,tfar);
        const sseb vmask = tNear <= tFar;
        const size_t mask = movemask(vmask);
#endif
        dist = tNear;
        return mask;
      }
      
    public:
      ssef lower_x;           //!< X dimension of lower bounds of all 4 children.
      ssef upper_x;           //!< X dimension of upper bounds of all 4 children.
      ssef lower_y;           //!< Y dimension of lower bounds of all 4 children.
      ssef upper_y;           //!< Y dimension of upper bounds of all 4 children.
      ssef lower_z;           //!< Z dimension of lower bounds of all 4 children.
      ssef upper_z;           //!< Z dimension of upper bounds of all 4 children.
    };
    
    struct SubTree
    {
    public:
      
      __forceinline SubTree(unsigned x, unsigned y, Array2D<Vec3fa>& vertices, unsigned levels, unsigned geomID, unsigned primID)
        : bx(x), by(y), vertices(vertices), levels(levels-1), geomID(geomID), primID(primID)
      {
        build(nodes,0,0,0);
      }
      
      const BBox3fa build(Node* node, unsigned x, unsigned y, unsigned l)
      {
        if (l == levels) {
          BBox3fa bounds = empty;
          x *= 2; y *= 2;
          bounds.extend(vertices(bx+x+0,by+y+0));
          bounds.extend(vertices(bx+x+1,by+y+0));
          bounds.extend(vertices(bx+x+2,by+y+0));
          bounds.extend(vertices(bx+x+0,by+y+1));
          bounds.extend(vertices(bx+x+1,by+y+1));
          bounds.extend(vertices(bx+x+2,by+y+1));
          bounds.extend(vertices(bx+x+0,by+y+2));
          bounds.extend(vertices(bx+x+1,by+y+2));
          bounds.extend(vertices(bx+x+2,by+y+2));
          return bounds;
        }
        const size_t w = 1<<l;
        const BBox3fa b00 = build(node+w*w,2*x+0,2*y+0,l+1); node[y*w+x].set(0,b00);
        const BBox3fa b10 = build(node+w*w,2*x+1,2*y+0,l+1); node[y*w+x].set(1,b10);
        const BBox3fa b01 = build(node+w*w,2*x+0,2*y+1,l+1); node[y*w+x].set(2,b01);
        const BBox3fa b11 = build(node+w*w,2*x+1,2*y+1,l+1); node[y*w+x].set(3,b11);
        return merge(b00,b10,b01,b11);
      }
      
    public:
      unsigned bx,by;            //!< coordinates of subtree
      Array2D<Vec3fa>& vertices; //!< pointer to vertices
      unsigned levels;           //!< number of stored levels
      unsigned primID;
      unsigned geomID;
      Node nodes[1];
      //Node n0;                  //!< root node
      //Node n00, n01, n10, n11;  //!< child nodes
    };
    
  public:
    
{'fraction_non_alphanumeric': 0.14538861521620142, 'fraction_numerical': 0.019978106185002738, 'mean_word_length': 1.9946732227002664, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5008445', 'n_tokens_mistral': 5209, 'n_tokens_neox': 4928, 'n_words': 1173}