<commit_before>/* noun/imprison.c
**
*/
#include "all.h"

/* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom.
*/
u3_noun
u3i_bytes(c3_w        a_w,
          const c3_y* b_y)
{
  u3_noun pro;
  u3t_on(mal_o);

  //  Strip trailing zeroes.
  //
  while ( a_w && !b_y[a_w - 1] ) {
    a_w--;
  }

  //  Check for cat.
  //
  if ( a_w <= 4 ) {
    if ( !a_w ) {
      return 0;
    }
    else if ( a_w == 1 ) {
      return b_y[0];
    }
    else if ( a_w == 2 ) {
      return (b_y[0] | (b_y[1] << 8));
    }
    else if ( a_w == 3 ) {
      return (b_y[0] | (b_y[1] << 8) | (b_y[2] << 16));
    }
    else if ( (b_y[3] <= 0x7f) ) {
      return (b_y[0] | (b_y[1] << 8) | (b_y[2] << 16) | (b_y[3] << 24));
    }
  }

  //  Allocate, fill, return.
  //
  {
    c3_w      len_w = (a_w + 3) >> 2;
    c3_w*     nov_w = u3a_walloc((len_w + c3_wiseof(u3a_atom)));
    u3a_atom* nov_u = (void*)nov_w;

    nov_u->mug_w = 0;
    nov_u->len_w = len_w;

    //  Clear the words.
    //
    {
      c3_w i_w;

      for ( i_w=0; i_w < len_w; i_w++ ) {
        nov_u->buf_w[i_w] = 0;
      }
    }

    //  Fill the bytes.
    //
    {
      c3_w i_w;

      for ( i_w=0; i_w < a_w; i_w++ ) {
        nov_u->buf_w[i_w >> 2] |= (b_y[i_w] << ((i_w & 3) * 8));
      }
    }

    pro = u3a_to_pug(u3a_outa(nov_w));
  }

  u3t_off(mal_o);
  return pro;
}

/* u3i_words(): Copy [a] words from [b] into an atom.
*/
u3_noun
u3i_words(c3_w        a_w,
          const c3_w* b_w)
{
  u3_noun pro;
  u3t_on(mal_o);

  //  Strip trailing zeroes.
  //
  while ( a_w && !b_w[a_w - 1] ) {
    a_w--;
  }

  //  Check for cat.
  //
  if ( !a_w ) {
    return 0;
  }
  else if ( (a_w == 1) && !(b_w[0] >> 31) ) {
    return b_w[0];
  }

  //  Allocate, fill, return.
  //
  {
    c3_w*     nov_w = u3a_walloc(a_w + c3_wiseof(u3a_atom));
    u3a_atom* nov_u = (void*)nov_w;

    nov_u->mug_w = 0;
    nov_u->len_w = a_w;

    //  Fill the words.
    //
    {
      c3_w i_w;

      for ( i_w=0; i_w < a_w; i_w++ ) {
        nov_u->buf_w[i_w] = b_w[i_w];
      }
    }

    pro = u3a_to_pug(u3a_outa(nov_w));
  }

  u3t_off(mal_o);
  return pro;
}

/* u3i_chubs(): Copy [a] chubs from [b] into an atom.
*/
u3_atom
u3i_chubs(c3_w        a_w,
          const c3_d* b_d)
{
  u3_noun pro;
  u3t_on(mal_o);

  //  Strip trailing zeroes.
  //
  while ( a_w && !b_d[a_w - 1] ) {
    a_w--;
  }

  //  Check for cat.
  //
  if ( !a_w ) {
    return 0;
  }
  else if ( (1 == a_w) && !(b_d[0] >> 31) ) {
    return (c3_w)b_d[0];
  }

  //  Allocate, fill, return.
  //
  {
    c3_w len_w = 2 * a_w;

    if ( !(b_d[a_w - 1] >> 32) ) {
      len_w--;
    }

    c3_w*     nov_w = u3a_walloc(len_w + c3_wiseof(u3a_atom));
    u3a_atom* nov_u = (void*)nov_w;

    nov_u->mug_w = 0;
    nov_u->len_w = len_w;

    //  Fill the words.
    //
    {
      c3_w i_w, x_w, max_w = a_w - 1;
      c3_d i_d;

      for ( i_w = 0; i_w < max_w; i_w++ ) {
        i_d = b_d[i_w];
        x_w = 2 * i_w;
        nov_u->buf_w[x_w] = i_d & 0xffffffffULL;
        x_w++;
        nov_u->buf_w[x_w] = i_d >> 32;
      }

      {
        i_d = b_d[i_w];
        x_w = 2 * i_w;
        nov_u->buf_w[x_w] = i_d & 0xffffffffULL;
        x_w++;
      }

      if ( x_w < len_w ) {
        nov_u->buf_w[x_w] = i_d >> 32;
      }
    }

    pro = u3a_to_pug(u3a_outa(nov_w));
  }

  u3t_off(mal_o);
  return pro;
}

/* u3i_mp(): Copy the GMP integer [a] into an atom, and clear it.
*/
u3_noun
u3i_mp(mpz_t a_mp)
{
  c3_w  pyg_w = mpz_size(a_mp) * ((sizeof(mp_limb_t)) / 4);
  c3_w* buz_w = u3a_slab(4 * pyg_w);

  mpz_export(buz_w, 0, -1, sizeof(c3_w), 0, 0, a_mp);
  mpz_clear(a_mp);

  return u3a_malt(buz_w);
}

/* u3i_vint(): increment [a].
*/
u3_noun
u3i_vint(u3_noun a)
{
  c3_assert(u3_none != a);

  if ( _(u3a_is_cat(a)) ) {
    c3_w vin_w = (a + 1);<commit_msg>u3: fixes -P profiling by moving alloc hints in imprison.c<commit_after>/* noun/imprison.c
**
*/
#include "all.h"

/* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom.
*/
u3_noun
u3i_bytes(c3_w        a_w,
          const c3_y* b_y)
{
  u3_noun pro;

  //  Strip trailing zeroes.
  //
  while ( a_w && !b_y[a_w - 1] ) {
    a_w--;
  }

  //  Check for cat.
  //
  if ( a_w <= 4 ) {
    if ( !a_w ) {
      return 0;
    }
    else if ( a_w == 1 ) {
      return b_y[0];
    }
    else if ( a_w == 2 ) {
      return (b_y[0] | (b_y[1] << 8));
    }
    else if ( a_w == 3 ) {
      return (b_y[0] | (b_y[1] << 8) | (b_y[2] << 16));
    }
    else if ( (b_y[3] <= 0x7f) ) {
      return (b_y[0] | (b_y[1] << 8) | (b_y[2] << 16) | (b_y[3] << 24));
    }
  }

  //  Allocate, fill, return.
  //
  u3t_on(mal_o);
  {
    c3_w      len_w = (a_w + 3) >> 2;
    c3_w*     nov_w = u3a_walloc((len_w + c3_wiseof(u3a_atom)));
    u3a_atom* nov_u = (void*)nov_w;

    nov_u->mug_w = 0;
    nov_u->len_w = len_w;

    //  Clear the words.
    //
    {
      c3_w i_w;

      for ( i_w=0; i_w < len_w; i_w++ ) {
        nov_u->buf_w[i_w] = 0;
      }
    }

    //  Fill the bytes.
    //
    {
      c3_w i_w;

      for ( i_w=0; i_w < a_w; i_w++ ) {
        nov_u->buf_w[i_w >> 2] |= (b_y[i_w] << ((i_w & 3) * 8));
      }
    }

    pro = u3a_to_pug(u3a_outa(nov_w));
  }
  u3t_off(mal_o);

  return pro;
}

/* u3i_words(): Copy [a] words from [b] into an atom.
*/
u3_noun
u3i_words(c3_w        a_w,
          const c3_w* b_w)
{
  u3_noun pro;

  //  Strip trailing zeroes.
  //
  while ( a_w && !b_w[a_w - 1] ) {
    a_w--;
  }

  //  Check for cat.
  //
  if ( !a_w ) {
    return 0;
  }
  else if ( (a_w == 1) && !(b_w[0] >> 31) ) {
    return b_w[0];
  }

  //  Allocate, fill, return.
  //
  u3t_on(mal_o);
  {
    c3_w*     nov_w = u3a_walloc(a_w + c3_wiseof(u3a_atom));
    u3a_atom* nov_u = (void*)nov_w;

    nov_u->mug_w = 0;
    nov_u->len_w = a_w;

    //  Fill the words.
    //
    {
      c3_w i_w;

      for ( i_w=0; i_w < a_w; i_w++ ) {
        nov_u->buf_w[i_w] = b_w[i_w];
      }
    }

    pro = u3a_to_pug(u3a_outa(nov_w));
  }
  u3t_off(mal_o);

  return pro;
}

/* u3i_chubs(): Copy [a] chubs from [b] into an atom.
*/
u3_atom
u3i_chubs(c3_w        a_w,
          const c3_d* b_d)
{
  u3_noun pro;

  //  Strip trailing zeroes.
  //
  while ( a_w && !b_d[a_w - 1] ) {
    a_w--;
  }

  //  Check for cat.
  //
  if ( !a_w ) {
    return 0;
  }
  else if ( (1 == a_w) && !(b_d[0] >> 31) ) {
    return (c3_w)b_d[0];
  }

  //  Allocate, fill, return.
  //
  u3t_on(mal_o);
  {
    c3_w len_w = 2 * a_w;

    if ( !(b_d[a_w - 1] >> 32) ) {
      len_w--;
    }

    c3_w*     nov_w = u3a_walloc(len_w + c3_wiseof(u3a_atom));
    u3a_atom* nov_u = (void*)nov_w;

    nov_u->mug_w = 0;
    nov_u->len_w = len_w;

    //  Fill the words.
    //
    {
      c3_w i_w, x_w, max_w = a_w - 1;
      c3_d i_d;

      for ( i_w = 0; i_w < max_w; i_w++ ) {
        i_d = b_d[i_w];
        x_w = 2 * i_w;
        nov_u->buf_w[x_w] = i_d & 0xffffffffULL;
        x_w++;
        nov_u->buf_w[x_w] = i_d >> 32;
      }

      {
        i_d = b_d[i_w];
        x_w = 2 * i_w;
        nov_u->buf_w[x_w] = i_d & 0xffffffffULL;
        x_w++;
      }

      if ( x_w < len_w ) {
        nov_u->buf_w[x_w] = i_d >> 32;
      }
    }

    pro = u3a_to_pug(u3a_outa(nov_w));
  }
  u3t_off(mal_o);

  return pro;
}

/* u3i_mp(): Copy the GMP integer [a] into an atom, and clear it.
*/
u3_noun
u3i_mp(mpz_t a_mp)
{
  c3_w  pyg_w = mpz_size(a_mp) * ((sizeof(mp_limb_t)) / 4);
  c3_w* buz_w = u3a_slab(4 * pyg_w);

  mpz_export(buz_w, 0, -1, sizeof(c3_w), 0, 0, a_mp);
  mpz_clear(a_mp);

  return u3a_malt(buz_w);
}

/* u3i_vint(): increment [a].
*/
u3_noun
u3i_vint(u3_noun a)
{
  c3_assert(u3_none != a);

  if ( _(u3a_is_cat(a)) ) {
    c3_w vin_w = (a + 1);
{'fraction_non_alphanumeric': 0.1839395124494851, 'fraction_numerical': 0.03767435797158128, 'mean_word_length': 1.728307254623044, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '6782848', 'n_tokens_mistral': 4212, 'n_tokens_neox': 4026, 'n_words': 734}