Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int/*64 does not support complement / not #1208

Closed
sogaiu opened this issue Jul 1, 2023 · 2 comments · Fixed by #1210
Closed

int/*64 does not support complement / not #1208

sogaiu opened this issue Jul 1, 2023 · 2 comments · Fixed by #1210

Comments

@sogaiu
Copy link
Contributor

sogaiu commented Jul 1, 2023

Currently, int/s64 and int/u64 support most of the common bit manipulation operations:

janet/src/core/inttypes.c

Lines 549 to 597 in b125cbe

static JanetMethod it_s64_methods[] = {
{"+", cfun_it_s64_add},
{"r+", cfun_it_s64_add},
{"-", cfun_it_s64_sub},
{"r-", cfun_it_s64_subi},
{"*", cfun_it_s64_mul},
{"r*", cfun_it_s64_mul},
{"/", cfun_it_s64_div},
{"r/", cfun_it_s64_divi},
{"mod", cfun_it_s64_mod},
{"rmod", cfun_it_s64_modi},
{"%", cfun_it_s64_rem},
{"r%", cfun_it_s64_remi},
{"&", cfun_it_s64_and},
{"r&", cfun_it_s64_and},
{"|", cfun_it_s64_or},
{"r|", cfun_it_s64_or},
{"^", cfun_it_s64_xor},
{"r^", cfun_it_s64_xor},
{"<<", cfun_it_s64_lshift},
{">>", cfun_it_s64_rshift},
{"compare", cfun_it_s64_compare},
{NULL, NULL}
};
static JanetMethod it_u64_methods[] = {
{"+", cfun_it_u64_add},
{"r+", cfun_it_u64_add},
{"-", cfun_it_u64_sub},
{"r-", cfun_it_u64_subi},
{"*", cfun_it_u64_mul},
{"r*", cfun_it_u64_mul},
{"/", cfun_it_u64_div},
{"r/", cfun_it_u64_divi},
{"mod", cfun_it_u64_mod},
{"rmod", cfun_it_u64_modi},
{"%", cfun_it_u64_mod},
{"r%", cfun_it_u64_modi},
{"&", cfun_it_u64_and},
{"r&", cfun_it_u64_and},
{"|", cfun_it_u64_or},
{"r|", cfun_it_u64_or},
{"^", cfun_it_u64_xor},
{"r^", cfun_it_u64_xor},
{"<<", cfun_it_u64_lshift},
{">>", cfun_it_u64_rshift},
{"compare", cfun_it_u64_compare},
{NULL, NULL}
};

Notably absent is complement / not.

Is there a technical reason this could / should not be implemented?


primo-ppcg shared some considerations regarding some implementation considerations.

@primo-ppcg
Copy link
Contributor

primo-ppcg commented Jul 1, 2023

I've implemented this on my local fork, I don't believe there's any issue:

(for n -99 100
  (assert (compare= (bnot n) (bnot (int/s64 n)))))

(assert (= (int/u64 "0xFFFF_FFFF_FFFF_FFFF") (bnot (int/u64 0))))

@bakpakin
Copy link
Member

bakpakin commented Jul 1, 2023

Just an error of omission

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants