From fcedfddf00b3f994e4f4e40332ac7fc192c63244 Mon Sep 17 00:00:00 2001 From: polwex Date: Sun, 5 Oct 2025 21:56:51 +0700 Subject: claude is gud --- vere/pkg/noun/jets/c/clz.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 vere/pkg/noun/jets/c/clz.c (limited to 'vere/pkg/noun/jets/c/clz.c') diff --git a/vere/pkg/noun/jets/c/clz.c b/vere/pkg/noun/jets/c/clz.c new file mode 100644 index 0000000..f8da45a --- /dev/null +++ b/vere/pkg/noun/jets/c/clz.c @@ -0,0 +1,75 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" + +u3_atom +u3qc_clz(u3_atom boq, u3_atom sep, u3_atom a) +{ + if ( !_(u3a_is_cat(boq)) || (boq >= 32) ) { + return u3m_bail(c3__fail); + } + + if ( !_(u3a_is_cat(sep)) ) { + return u3m_bail(c3__fail); + } + + c3_g boq_g = boq; + c3_w sep_w = sep; + c3_w tot_w = sep_w << boq_g; + + if ( (tot_w >> boq_g) != sep_w ) { + return u3m_bail(c3__fail); + } + + c3_w met_w = u3r_met(0, a); + + if ( met_w <= tot_w ) { + tot_w -= met_w; + return u3i_word(tot_w); + } + else { + c3_w wid_w = tot_w >> 5; + c3_w bit_w = tot_w & 31; + c3_w wor_w; + + if ( bit_w ) { + wor_w = u3r_word(wid_w, a); + wor_w &= (1 << bit_w) - 1; + + if ( wor_w ) { + return bit_w - (32 - c3_lz_w(wor_w)); + } + } + + while ( wid_w-- ) { + wor_w = u3r_word(wid_w, a); + + if ( wor_w ) { + bit_w += c3_lz_w(wor_w); + break; + } + + bit_w += 32; + } + + return u3i_word(bit_w); + } +} + +u3_noun +u3wc_clz(u3_noun cor) +{ + u3_atom boq, sep, vat; + { + u3_noun sam = u3h(u3t(cor)); + u3_noun bit = u3h(sam); + + u3x_bite(bit, &boq, &sep); + vat = u3x_atom(u3t(sam)); + } + + return u3qc_clz(boq, sep, vat); +} -- cgit v1.2.3