<commit_before>#include <stdlib.h>
#include <time.h>
#include "common/dbg.h"

#include "data/spatialgrid.h"
#include "io/svg.h"
#include "math/math.h"
#include "math/vec.h"

#define BUF_SIZE 0x400

typedef struct {
  CT_Vec3f *particles;
  CT_SpatialGrid accel;
  size_t length;
  size_t num;
  size_t width;
  size_t height;
  size_t seeds;
  float eps[2];
} DLA;

typedef struct {
  CT_Vec3f *c;
  CT_Vec3f *p;
  float minD;
  float radius;
} DLA_Sel;

// clang-format off
static DLA dla = {
  .width  = 600,
  .height = 600,
  .seeds  = 16,
  .eps    = {25, 25}
};
// clang-format on

ct_inline CT_Vec3f *rand_particle(DLA *dla) {
  return ct_set3fxyz(&dla->particles[dla->num++],
                     ct_rand_normpos() * dla->width,
                     ct_rand_normpos() * dla->height, 0);
}

static void add_particle(DLA *dla) {
  CT_Vec3f *res[BUF_SIZE];
  CT_Vec3f *p = rand_particle(dla);
  while (1) {
    size_t num = ct_spgrid_select2d(&dla->accel, (float *)p, dla->eps,
                                    (void **)&res, BUF_SIZE);
    if (num > 0) {
      float minD  = 1e9;
      CT_Vec3f *c = NULL;
      for (size_t i = 0; i < num; i++) {
        float d = ct_distsq2fv((CT_Vec2f *)p, (CT_Vec2f *)res[i]);
        if (d >= 1 && d < minD) {
          minD = d;
          c    = res[i];
        }
      }
      if (c) {
        float t = 1.0f / sqrtf(minD);
        p->x    = c->x + t * (p->x - c->x);
        p->y    = c->y + t * (p->y - c->y);
        p->z    = c->z;
        ct_spgrid_insert(&dla->accel, (float *)p, p);
        return;
      }
    }<commit_msg>update DLA example for SSE4<commit_after>#include <stdlib.h>
#include <time.h>

#include "common/dbg.h"
#include "config.h"

#include "data/spatialgrid.h"
#include "io/svg.h"
#include "math/math.h"
#include "math/vec.h"

#define BUF_SIZE 0x400

typedef struct {
  CT_Vec3f *particles;
  CT_SpatialGrid accel;
  size_t length;
  size_t num;
  size_t width;
  size_t height;
  size_t seeds;
  float eps[2];
} DLA;

// clang-format off
static DLA dla = {
  .width  = 600,
  .height = 600,
  .seeds  = 16,
  .eps    = {25, 25}
};
// clang-format on

ct_inline CT_Vec3f *rand_particle(DLA *dla) {
  return ct_floor3f_imm(ct_set3fxyz(&dla->particles[dla->num++],
                                    ct_rand_normpos() * dla->width,
                                    ct_rand_normpos() * dla->height, 0));
}

static void add_particle(DLA *dla) {
  CT_Vec3f *res[BUF_SIZE];
  CT_Vec3f *p = rand_particle(dla);
  while (1) {
    size_t num = ct_spgrid_select2d(&dla->accel, (float *)p, dla->eps,
                                    (void **)&res, BUF_SIZE);
    if (num > 0) {
      float minD  = 1e9;
      CT_Vec3f *c = NULL;
      for (size_t i = 0; i < num; i++) {
        float d = ct_distsq2fv((CT_Vec2f *)p, (CT_Vec2f *)res[i]);
        if (d >= 1 && d < minD) {
          minD = d;
          c    = res[i];
        }
      }
      if (c) {
#ifdef CT_FEATURE_SSE4
        p->mmval = (p->mmval - c->mmval) *
                       _mm_rcp_ps(_mm_sqrt_ps(_mm_load1_ps(&minD))) +
                   c->mmval;
#else
        float t = 1.0f / sqrtf(minD);
        p->x    = c->x + t * (p->x - c->x);
        p->y    = c->y + t * (p->y - c->y);
#endif
        p->z = c->z;
        ct_spgrid_insert(&dla->accel, (float *)p, p);
        return;
      }
    }
{'fraction_non_alphanumeric': 0.16170724376315, 'fraction_numerical': 0.023444544634806132, 'mean_word_length': 1.9451327433628318, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4968207', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1389, 'n_words': 300}