summaryrefslogtreecommitdiff
path: root/vere/pkg/noun/jets/c/ctz.c
blob: ff74e244c348541195f58f17a7bd08efe917613b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"

u3_atom
u3qc_ctz(u3_atom a)
{
  c3_w wor_w, i_w = 0;

  if ( 0 == a ) {
    return 0;
  }

  do {
    wor_w = u3r_word(i_w++, a);
  }
  while ( !wor_w );

  {
    c3_w bit_d = i_w - 1;
    bit_d *= 32;
    bit_d += c3_tz_w(wor_w);
    return u3i_chub(bit_d);
  }
}

u3_noun
u3wc_ctz(u3_noun cor)
{
  return u3qc_ctz(u3x_atom(u3h(u3t(cor))));
}