From 8c638594b14296c4dce3db4adbb1a3de27a148e9 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 05:59:20 +0200 Subject: [PATCH 01/14] aor jet registration causes segfault --- bazel/common_settings.bzl | 4 ++-- pkg/noun/jets/q.h | 1 + pkg/noun/jets/tree.c | 3 +++ pkg/noun/jets/w.h | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl index 68a2232cd1..6a61de1292 100644 --- a/bazel/common_settings.bzl +++ b/bazel/common_settings.bzl @@ -14,7 +14,7 @@ string_flag = rule( def vere_library(copts = [], linkopts = [], **kwargs): native.cc_library( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], + "//:debug": ["-O0", "-g3", "-DC3DBG"], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], @@ -39,7 +39,7 @@ def vere_library(copts = [], linkopts = [], **kwargs): def vere_binary(copts = [], linkopts = [], **kwargs): native.cc_binary( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], + "//:debug": ["-O0", "-g3", "-DC3DBG"], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], diff --git a/pkg/noun/jets/q.h b/pkg/noun/jets/q.h index fd7c5981fb..b4fe7cd73e 100644 --- a/pkg/noun/jets/q.h +++ b/pkg/noun/jets/q.h @@ -48,6 +48,7 @@ /** Tier 3. **/ + u3_noun u3qc_aor(u3_atom, u3_atom); u3_noun u3qc_bex(u3_atom); u3_noun u3qc_xeb(u3_atom); u3_noun u3qc_can(u3_atom, u3_noun); diff --git a/pkg/noun/jets/tree.c b/pkg/noun/jets/tree.c index e40fe03846..bf06268b5b 100644 --- a/pkg/noun/jets/tree.c +++ b/pkg/noun/jets/tree.c @@ -2463,6 +2463,8 @@ static u3j_core _138_two__by_d[] = static u3j_harm _138_two_mate_a[] = {{".2", u3wb_mate, c3y}, {}}; +static u3j_harm _138_two_aor_a[] = {{".2", u3wc_aor, c3y}, {}}; + static u3j_core _138_two_d[] = { { "tri", 3, 0, _138_tri_d, no_hashes, _140_tri_ho }, @@ -2489,6 +2491,7 @@ static u3j_core _138_two_d[] = { "welp", 7, _140_two_welp_a, 0, no_hashes }, { "zing", 7, _140_two_zing_a, 0, no_hashes }, + { "aor", 7, _138_two_aor_a, 0, no_hashes }, { "bex", 7, _140_two_bex_a, 0, no_hashes }, { "cat", 7, _140_two_cat_a, 0, no_hashes }, { "can", 7, _140_two_can_a, 0, no_hashes }, diff --git a/pkg/noun/jets/w.h b/pkg/noun/jets/w.h index 34716971bd..275740cd97 100644 --- a/pkg/noun/jets/w.h +++ b/pkg/noun/jets/w.h @@ -50,6 +50,7 @@ /** Tier 3. **/ + u3_noun u3wc_aor(u3_noun); u3_noun u3wc_bex(u3_noun); u3_noun u3wc_xeb(u3_noun); u3_noun u3wc_can(u3_noun); From 76d83269672b21274ea470f6bb2959b04c1c8e28 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:01:20 +0200 Subject: [PATCH 02/14] aor jet --- pkg/noun/jets/c/aor.c | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 pkg/noun/jets/c/aor.c diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c new file mode 100644 index 0000000000..29fd78960d --- /dev/null +++ b/pkg/noun/jets/c/aor.c @@ -0,0 +1,83 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" + + + static u3_atom + _aor_tramp(u3_noun a, + u3_noun b) + { + if ( c3y == u3r_sing(a, b) ) { + return c3y; + } + else { + if ( c3y == u3ud(a) ) { + if ( c3y == u3ud(b) ) { + c3_w len_a, len_b, i = 0; + c3_y *a_bytes = u3r_bytes_all(&len_a, a); + c3_y *b_bytes = u3r_bytes_all(&len_b, b); + while ( (i < len_a) && (i < len_b) ) { + c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; + if (a_slice != b_slice) { + return u3qa_lth(a_slice, b_slice); + } + i++; + } + return u3m_bail(c3__fail); + } + else { + return c3y; + } + } + else { + if ( c3y == u3ud(b) ) { + return c3n; + } + else { + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + return 3; + } + else { + return 2; + } + } + } + } + } + + u3_noun + u3qc_aor(u3_noun a, + u3_noun b) + { + u3_noun out = 4; + while ( 1 ) { + out = _aor_tramp(a, b); + if (out == 2) { + a = u3h(a); + b = u3h(b); + } + else if (out == 3) { + a = u3t(a); + b = u3t(b); + } + else { + return out; + } + } + } + + u3_noun + u3wc_aor(u3_noun cor) + { + u3_noun a, b; + + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + return u3m_bail(c3__exit); + } else { + return u3qc_aor(a, b); + } + } + From 1a66d26a9240dad4cd21aa5fe124aea5222e332c Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:23:56 +0200 Subject: [PATCH 03/14] aor don't copy --- pkg/noun/jets/c/aor.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 29fd78960d..ea35290617 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,15 +16,25 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - c3_w len_a, len_b, i = 0; - c3_y *a_bytes = u3r_bytes_all(&len_a, a); - c3_y *b_bytes = u3r_bytes_all(&len_b, b); - while ( (i < len_a) && (i < len_b) ) { - c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; - if (a_slice != b_slice) { - return u3qa_lth(a_slice, b_slice); - } - i++; + u3a_atom* a_u = u3a_to_ptr(a); + u3a_atom* b_u = u3a_to_ptr(b); + c3_w len_w_a, len_w_b, i_w = 0; + c3_w *a_words = a_u->buf_w; + c3_w *b_words = b_u->buf_w; + while ( (i_w < len_w_a) && (i_w < len_w_b) ) { + c3_w a_w = a_words[i_w], b_w = b_words[i_w]; + c3_y a_y = a_w & 0xFF, b_y = b_w & 0xFF; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + a_y = a_w & 0xFF00; + b_y = b_w & 0xFF00; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + a_y = a_w & 0xFF0000; + b_y = b_w & 0xFF0000; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + a_y = a_w & 0xFF000000; + b_y = b_w & 0xFF000000; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + i_w++; } return u3m_bail(c3__fail); } From 3f862f86cb855ef57b15cdd5a22e67548545cf02 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:26:04 +0200 Subject: [PATCH 04/14] len_w --- pkg/noun/jets/c/aor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index ea35290617..47e07f62c4 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -18,7 +18,8 @@ if ( c3y == u3ud(b) ) { u3a_atom* a_u = u3a_to_ptr(a); u3a_atom* b_u = u3a_to_ptr(b); - c3_w len_w_a, len_w_b, i_w = 0; + c3_w len_w_a = a_u->len_w, len_w_b = b_u->len_w; + c3_w i_w = 0; c3_w *a_words = a_u->buf_w; c3_w *b_words = b_u->buf_w; while ( (i_w < len_w_a) && (i_w < len_w_b) ) { From 2638bc35cb32c7d519d6f15583c87ba87f228ee9 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:34:25 +0200 Subject: [PATCH 05/14] inline lth --- pkg/noun/jets/c/aor.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 47e07f62c4..12688f3681 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -25,16 +25,20 @@ while ( (i_w < len_w_a) && (i_w < len_w_b) ) { c3_w a_w = a_words[i_w], b_w = b_words[i_w]; c3_y a_y = a_w & 0xFF, b_y = b_w & 0xFF; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + a_y = a_w & 0xFF00; b_y = b_w & 0xFF00; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + a_y = a_w & 0xFF0000; b_y = b_w & 0xFF0000; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + a_y = a_w & 0xFF000000; b_y = b_w & 0xFF000000; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + i_w++; } return u3m_bail(c3__fail); From f7fc53c1a0050b0e875da35ce95daf88068f8073 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 10:02:09 +0200 Subject: [PATCH 06/14] rollback to copy --- pkg/noun/jets/c/aor.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 12688f3681..0ee6f6b0f5 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,30 +16,17 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - u3a_atom* a_u = u3a_to_ptr(a); - u3a_atom* b_u = u3a_to_ptr(b); - c3_w len_w_a = a_u->len_w, len_w_b = b_u->len_w; - c3_w i_w = 0; - c3_w *a_words = a_u->buf_w; - c3_w *b_words = b_u->buf_w; - while ( (i_w < len_w_a) && (i_w < len_w_b) ) { - c3_w a_w = a_words[i_w], b_w = b_words[i_w]; - c3_y a_y = a_w & 0xFF, b_y = b_w & 0xFF; - if (a_y != b_y) return __(a_y < b_y); - - a_y = a_w & 0xFF00; - b_y = b_w & 0xFF00; - if (a_y != b_y) return __(a_y < b_y); - - a_y = a_w & 0xFF0000; - b_y = b_w & 0xFF0000; - if (a_y != b_y) return __(a_y < b_y); - - a_y = a_w & 0xFF000000; - b_y = b_w & 0xFF000000; - if (a_y != b_y) return __(a_y < b_y); - - i_w++; + c3_w len_a, len_b, i = 0; + c3_y *a_bytes = u3r_bytes_all(&len_a, a); + c3_y *b_bytes = u3r_bytes_all(&len_b, b); + while ( (i < len_a) && (i < len_b) ) { + c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; + u3m_p("a_slice", a_slice); + u3m_p("b_slice", b_slice); + if (a_slice != b_slice) { + return __(a_slice < b_slice); + } + i++; } return u3m_bail(c3__fail); } @@ -79,6 +66,7 @@ b = u3t(b); } else { + u3m_p("out", out); return out; } } @@ -87,6 +75,7 @@ u3_noun u3wc_aor(u3_noun cor) { + // return u3_none; u3_noun a, b; if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { From 2be5296db5044d3b888820d5df8007baf7b558c0 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 12:47:16 +0200 Subject: [PATCH 07/14] jet fix no copy --- pkg/noun/jets/c/aor.c | 51 +++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 0ee6f6b0f5..8514e78319 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,19 +16,44 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - c3_w len_a, len_b, i = 0; - c3_y *a_bytes = u3r_bytes_all(&len_a, a); - c3_y *b_bytes = u3r_bytes_all(&len_b, b); - while ( (i < len_a) && (i < len_b) ) { - c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; - u3m_p("a_slice", a_slice); - u3m_p("b_slice", b_slice); - if (a_slice != b_slice) { - return __(a_slice < b_slice); + c3_w len_a_w, len_b_w, i_w = 0; + c3_w *a_words, *b_words; + c3_w a_w, b_w; + if ( c3y == u3a_is_cat(a) ) { + len_a_w = 1; + a_words = &a; + } + else { + u3a_atom* a_u = u3a_to_ptr(a); + len_a_w = (a_u->len_w); + a_words = a_u->buf_w; + } + if ( c3y == u3a_is_cat(b) ) { + len_b_w = 1; + b_words = &b; + } + else { + u3a_atom* b_u = u3a_to_ptr(b); + len_b_w = (b_u->len_w); + b_words = b_u->buf_w; + } + while ( (i_w < len_a_w) && (i_w < len_b_w) ) { + c3_y a_y, b_y; + a_w = a_words[i_w]; + b_w = b_words[i_w]; + for (c3_w j = 0; j < 4; j++) { + a_y = a_w % (1 << 8); + b_y = b_w % (1 << 8); + if ( a_y != b_y ) return __(a_y < b_y); + a_w = a_w >> 8; + b_w = b_w >> 8; } - i++; + i_w++; + } + if ( len_a_w == len_b_w) { + return u3m_bail(c3__fail); // impossible: nonequal atoms with equal payloads } - return u3m_bail(c3__fail); + return __(len_a_w < len_b_w); } else { return c3y; @@ -54,7 +79,7 @@ u3qc_aor(u3_noun a, u3_noun b) { - u3_noun out = 4; + u3_noun out; while ( 1 ) { out = _aor_tramp(a, b); if (out == 2) { @@ -66,7 +91,6 @@ b = u3t(b); } else { - u3m_p("out", out); return out; } } @@ -75,7 +99,6 @@ u3_noun u3wc_aor(u3_noun cor) { - // return u3_none; u3_noun a, b; if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { From 0c9d7682a65356ca1acee9e45b23899a2c679cb8 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 12:48:57 +0200 Subject: [PATCH 08/14] restore common settings --- bazel/common_settings.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl index 6a61de1292..68a2232cd1 100644 --- a/bazel/common_settings.bzl +++ b/bazel/common_settings.bzl @@ -14,7 +14,7 @@ string_flag = rule( def vere_library(copts = [], linkopts = [], **kwargs): native.cc_library( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG"], + "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], @@ -39,7 +39,7 @@ def vere_library(copts = [], linkopts = [], **kwargs): def vere_binary(copts = [], linkopts = [], **kwargs): native.cc_binary( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG"], + "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], From 663a54af3d3639a05d242cf2104950f640cffd3b Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 16:36:03 +0200 Subject: [PATCH 09/14] optimizations --- pkg/noun/jets/c/aor.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 8514e78319..d19a7864e4 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,9 +16,9 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - c3_w len_a_w, len_b_w, i_w = 0; + c3_w len_a_w, len_b_w; c3_w *a_words, *b_words; - c3_w a_w, b_w; + c3_y a_y, b_y; if ( c3y == u3a_is_cat(a) ) { len_a_w = 1; a_words = &a; @@ -37,21 +37,13 @@ len_b_w = (b_u->len_w); b_words = b_u->buf_w; } - while ( (i_w < len_a_w) && (i_w < len_b_w) ) { - c3_y a_y, b_y; - a_w = a_words[i_w]; - b_w = b_words[i_w]; + c3_w len_min = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min; i_w++) { for (c3_w j = 0; j < 4; j++) { - a_y = a_w % (1 << 8); - b_y = b_w % (1 << 8); + a_y = (a_words[i_w] >> (8*j)) & 0xFF; + b_y = (b_words[i_w] >> (8*j)) & 0xFF; if ( a_y != b_y ) return __(a_y < b_y); - a_w = a_w >> 8; - b_w = b_w >> 8; } - i_w++; - } - if ( len_a_w == len_b_w) { - return u3m_bail(c3__fail); // impossible: nonequal atoms with equal payloads } return __(len_a_w < len_b_w); } From cb13d69c5bb634e71aaa27a6264b8e91046ca1f0 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 17:09:30 +0200 Subject: [PATCH 10/14] remove helping function --- pkg/noun/jets/c/aor.c | 119 ++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 68 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index d19a7864e4..0feb0bd9d0 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -6,87 +6,70 @@ #include "noun.h" - static u3_atom - _aor_tramp(u3_noun a, - u3_noun b) + u3_noun + u3qc_aor(u3_noun a, + u3_noun b) { - if ( c3y == u3r_sing(a, b) ) { - return c3y; - } - else { - if ( c3y == u3ud(a) ) { - if ( c3y == u3ud(b) ) { - c3_w len_a_w, len_b_w; - c3_w *a_words, *b_words; - c3_y a_y, b_y; - if ( c3y == u3a_is_cat(a) ) { - len_a_w = 1; - a_words = &a; - } - else { - u3a_atom* a_u = u3a_to_ptr(a); - len_a_w = (a_u->len_w); - a_words = a_u->buf_w; - } - if ( c3y == u3a_is_cat(b) ) { - len_b_w = 1; - b_words = &b; + while ( 1 ) { + if ( c3y == u3r_sing(a, b) ) { + return c3y; + } + else { + if ( c3y == u3ud(a) ) { + if ( c3y == u3ud(b) ) { + c3_w len_a_w, len_b_w; + c3_w *a_words, *b_words; + c3_y a_y, b_y; + if ( c3y == u3a_is_cat(a) ) { + len_a_w = 1; + a_words = &a; + } + else { + u3a_atom* a_u = u3a_to_ptr(a); + len_a_w = (a_u->len_w); + a_words = a_u->buf_w; + } + if ( c3y == u3a_is_cat(b) ) { + len_b_w = 1; + b_words = &b; + } + else { + u3a_atom* b_u = u3a_to_ptr(b); + len_b_w = (b_u->len_w); + b_words = b_u->buf_w; + } + c3_w len_min = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min; i_w++) { + for (c3_w j = 0; j < 4; j++) { + a_y = (a_words[i_w] >> (8*j)) & 0xFF; + b_y = (b_words[i_w] >> (8*j)) & 0xFF; + if ( a_y != b_y ) return __(a_y < b_y); + } + } + return __(len_a_w < len_b_w); } else { - u3a_atom* b_u = u3a_to_ptr(b); - len_b_w = (b_u->len_w); - b_words = b_u->buf_w; - } - c3_w len_min = c3_min(len_a_w, len_b_w); - for (c3_w i_w = 0; i_w < len_min; i_w++) { - for (c3_w j = 0; j < 4; j++) { - a_y = (a_words[i_w] >> (8*j)) & 0xFF; - b_y = (b_words[i_w] >> (8*j)) & 0xFF; - if ( a_y != b_y ) return __(a_y < b_y); - } + return c3y; } - return __(len_a_w < len_b_w); - } - else { - return c3y; - } - } - else { - if ( c3y == u3ud(b) ) { - return c3n; } else { - if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { - return 3; + if ( c3y == u3ud(b) ) { + return c3n; } else { - return 2; + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + a = u3t(a); + b = u3t(b); + } + else { + a = u3h(a); + b = u3h(b); + } } } } } } - - u3_noun - u3qc_aor(u3_noun a, - u3_noun b) - { - u3_noun out; - while ( 1 ) { - out = _aor_tramp(a, b); - if (out == 2) { - a = u3h(a); - b = u3h(b); - } - else if (out == 3) { - a = u3t(a); - b = u3t(b); - } - else { - return out; - } - } - } u3_noun u3wc_aor(u3_noun cor) From f54e67120a71c81e34ce88eac8a43be54e6cc6a1 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 18:13:04 +0200 Subject: [PATCH 11/14] refactor to follow hoon flow --- pkg/noun/jets/c/aor.c | 82 +++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 0feb0bd9d0..9125ea2e85 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -11,61 +11,51 @@ u3_noun b) { while ( 1 ) { - if ( c3y == u3r_sing(a, b) ) { - return c3y; + if ( c3y == u3r_sing(a, b) ) return c3y; + if ( c3n == u3ud(a) ) { + if ( c3y == u3ud(b) ) return c3n; + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + a = u3t(a); + b = u3t(b); + } + else { + a = u3h(a); + b = u3h(b); + } } else { - if ( c3y == u3ud(a) ) { - if ( c3y == u3ud(b) ) { - c3_w len_a_w, len_b_w; - c3_w *a_words, *b_words; - c3_y a_y, b_y; - if ( c3y == u3a_is_cat(a) ) { - len_a_w = 1; - a_words = &a; - } - else { - u3a_atom* a_u = u3a_to_ptr(a); - len_a_w = (a_u->len_w); - a_words = a_u->buf_w; - } - if ( c3y == u3a_is_cat(b) ) { - len_b_w = 1; - b_words = &b; - } - else { - u3a_atom* b_u = u3a_to_ptr(b); - len_b_w = (b_u->len_w); - b_words = b_u->buf_w; - } - c3_w len_min = c3_min(len_a_w, len_b_w); - for (c3_w i_w = 0; i_w < len_min; i_w++) { - for (c3_w j = 0; j < 4; j++) { - a_y = (a_words[i_w] >> (8*j)) & 0xFF; - b_y = (b_words[i_w] >> (8*j)) & 0xFF; - if ( a_y != b_y ) return __(a_y < b_y); - } - } - return __(len_a_w < len_b_w); + if ( c3n == u3ud(b) ) return c3y; + { + c3_w len_a_w, len_b_w; + c3_w *a_words, *b_words; + c3_y a_y, b_y; + if ( c3y == u3a_is_cat(a) ) { + len_a_w = 1; + a_words = &a; } else { - return c3y; + u3a_atom* a_u = u3a_to_ptr(a); + len_a_w = a_u->len_w; + a_words = a_u->buf_w; } - } - else { - if ( c3y == u3ud(b) ) { - return c3n; + if ( c3y == u3a_is_cat(b) ) { + len_b_w = 1; + b_words = &b; } else { - if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { - a = u3t(a); - b = u3t(b); - } - else { - a = u3h(a); - b = u3h(b); + u3a_atom* b_u = u3a_to_ptr(b); + len_b_w = b_u->len_w; + b_words = b_u->buf_w; + } + c3_w len_min = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min; i_w++) { + for (c3_w j = 0; j < 4; j++) { + a_y = (a_words[i_w] >> (8*j)) & 0xFF; + b_y = (b_words[i_w] >> (8*j)) & 0xFF; + if ( a_y != b_y ) return __(a_y < b_y); } } + return __(len_a_w < len_b_w); } } } From f04a8bcfdf02f5e735b39155d163cff1e9272d84 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 20:30:01 +0200 Subject: [PATCH 12/14] little endian optimization --- pkg/noun/jets/c/aor.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 9125ea2e85..5d6b705879 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -4,7 +4,64 @@ #include "jets/w.h" #include "noun.h" +#include "portable.h" +#if defined(c3_endian) && defined(c3_endian_little) && (c3_endian == c3_endian_little) + + u3_noun + u3qc_aor(u3_noun a, + u3_noun b) + { + while ( 1 ) { + if ( c3y == u3r_sing(a, b) ) return c3y; + if ( c3n == u3ud(a) ) { + if ( c3y == u3ud(b) ) return c3n; + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + a = u3t(a); + b = u3t(b); + } + else { + a = u3h(a); + b = u3h(b); + } + } + else { + if ( c3n == u3ud(b) ) return c3y; + { + c3_w len_a_y, len_b_y; + c3_y *a_bytes, *b_bytes; + c3_y a_y, b_y; + if ( c3y == u3a_is_cat(a) ) { + len_a_y = 4; + a_bytes = (c3_y*)&a; + } + else { + u3a_atom* a_u = u3a_to_ptr(a); + len_a_y = (a_u->len_w)*4; + a_bytes = (c3_y*)(a_u->buf_w); + } + if ( c3y == u3a_is_cat(b) ) { + len_b_y = 4; + b_bytes = (c3_y*)&b; + } + else { + u3a_atom* b_u = u3a_to_ptr(b); + len_b_y = (b_u->len_w)*4; + b_bytes = (c3_y*)(b_u->buf_w); + } + c3_w len_min = c3_min(len_a_y, len_b_y); + for (c3_w i_y = 0; i_y < len_min; i_y++) { + a_y = a_bytes[i_y]; + b_y = b_bytes[i_y]; + if ( a_y != b_y ) return __(a_y < b_y); + } + return __(len_a_y < len_b_y); + } + } + } + } + +#else u3_noun u3qc_aor(u3_noun a, @@ -60,6 +117,8 @@ } } } + +#endif u3_noun u3wc_aor(u3_noun cor) From 3ddba6af6157421daad401cba496cede4f11d9cd Mon Sep 17 00:00:00 2001 From: Quodss Date: Mon, 5 Aug 2024 19:27:42 +0200 Subject: [PATCH 13/14] length fix, remove dead code --- pkg/noun/jets/c/aor.c | 69 ++----------------------------------------- 1 file changed, 2 insertions(+), 67 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 5d6b705879..d19d1858cf 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -4,9 +4,6 @@ #include "jets/w.h" #include "noun.h" -#include "portable.h" - -#if defined(c3_endian) && defined(c3_endian_little) && (c3_endian == c3_endian_little) u3_noun u3qc_aor(u3_noun a, @@ -28,25 +25,22 @@ else { if ( c3n == u3ud(b) ) return c3y; { - c3_w len_a_y, len_b_y; + c3_w len_a_y = u3r_met(3, a); + c3_w len_b_y = u3r_met(3, b);; c3_y *a_bytes, *b_bytes; c3_y a_y, b_y; if ( c3y == u3a_is_cat(a) ) { - len_a_y = 4; a_bytes = (c3_y*)&a; } else { u3a_atom* a_u = u3a_to_ptr(a); - len_a_y = (a_u->len_w)*4; a_bytes = (c3_y*)(a_u->buf_w); } if ( c3y == u3a_is_cat(b) ) { - len_b_y = 4; b_bytes = (c3_y*)&b; } else { u3a_atom* b_u = u3a_to_ptr(b); - len_b_y = (b_u->len_w)*4; b_bytes = (c3_y*)(b_u->buf_w); } c3_w len_min = c3_min(len_a_y, len_b_y); @@ -60,65 +54,6 @@ } } } - -#else - - u3_noun - u3qc_aor(u3_noun a, - u3_noun b) - { - while ( 1 ) { - if ( c3y == u3r_sing(a, b) ) return c3y; - if ( c3n == u3ud(a) ) { - if ( c3y == u3ud(b) ) return c3n; - if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { - a = u3t(a); - b = u3t(b); - } - else { - a = u3h(a); - b = u3h(b); - } - } - else { - if ( c3n == u3ud(b) ) return c3y; - { - c3_w len_a_w, len_b_w; - c3_w *a_words, *b_words; - c3_y a_y, b_y; - if ( c3y == u3a_is_cat(a) ) { - len_a_w = 1; - a_words = &a; - } - else { - u3a_atom* a_u = u3a_to_ptr(a); - len_a_w = a_u->len_w; - a_words = a_u->buf_w; - } - if ( c3y == u3a_is_cat(b) ) { - len_b_w = 1; - b_words = &b; - } - else { - u3a_atom* b_u = u3a_to_ptr(b); - len_b_w = b_u->len_w; - b_words = b_u->buf_w; - } - c3_w len_min = c3_min(len_a_w, len_b_w); - for (c3_w i_w = 0; i_w < len_min; i_w++) { - for (c3_w j = 0; j < 4; j++) { - a_y = (a_words[i_w] >> (8*j)) & 0xFF; - b_y = (b_words[i_w] >> (8*j)) & 0xFF; - if ( a_y != b_y ) return __(a_y < b_y); - } - } - return __(len_a_w < len_b_w); - } - } - } - } - -#endif u3_noun u3wc_aor(u3_noun cor) From d24221754cb1a04802024c38130762dbf0bed3f1 Mon Sep 17 00:00:00 2001 From: Quodss Date: Mon, 5 Aug 2024 19:55:52 +0200 Subject: [PATCH 14/14] naming conventions --- pkg/noun/jets/c/aor.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index d19d1858cf..248661e777 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -25,31 +25,31 @@ else { if ( c3n == u3ud(b) ) return c3y; { - c3_w len_a_y = u3r_met(3, a); - c3_w len_b_y = u3r_met(3, b);; - c3_y *a_bytes, *b_bytes; - c3_y a_y, b_y; + c3_w len_a_w = u3r_met(3, a); + c3_w len_b_w = u3r_met(3, b);; + c3_y *buf_a_y, *buf_b_y; + c3_y cut_a_y, cut_b_y; if ( c3y == u3a_is_cat(a) ) { - a_bytes = (c3_y*)&a; + buf_a_y = (c3_y*)&a; } else { u3a_atom* a_u = u3a_to_ptr(a); - a_bytes = (c3_y*)(a_u->buf_w); + buf_a_y = (c3_y*)(a_u->buf_w); } if ( c3y == u3a_is_cat(b) ) { - b_bytes = (c3_y*)&b; + buf_b_y = (c3_y*)&b; } else { u3a_atom* b_u = u3a_to_ptr(b); - b_bytes = (c3_y*)(b_u->buf_w); + buf_b_y = (c3_y*)(b_u->buf_w); } - c3_w len_min = c3_min(len_a_y, len_b_y); - for (c3_w i_y = 0; i_y < len_min; i_y++) { - a_y = a_bytes[i_y]; - b_y = b_bytes[i_y]; - if ( a_y != b_y ) return __(a_y < b_y); + c3_w len_min_w = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min_w; i_w++) { + cut_a_y = buf_a_y[i_w]; + cut_b_y = buf_b_y[i_w]; + if ( cut_a_y != cut_b_y ) return __(cut_a_y < cut_b_y); } - return __(len_a_y < len_b_y); + return __(len_a_w < len_b_w); } } }