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

[BUG] Count leading zeros can't be used at compile time #3847

Open
martinvuyk opened this issue Dec 8, 2024 · 0 comments
Open

[BUG] Count leading zeros can't be used at compile time #3847

martinvuyk opened this issue Dec 8, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@martinvuyk
Copy link
Contributor

martinvuyk commented Dec 8, 2024

Bug description

Count leading zeros can't be used at compile time. This is actually part of #933. This blocks a lot of other work to fully support unicode due to it needing this function.

part of the error: note: LLVM intrinsic operand has unknown value: #pop<simd 15> : !pop.scalar<ui8>

CC: @lattner

Steps to reproduce

from bit import count_leading_zeros

fn _utf8_first_byte_sequence_length(b: Byte) -> Int:
    """Get the length of the sequence starting with given byte. Do note that
    this does not work correctly if given a continuation byte."""

    debug_assert(
        (b & 0b1100_0000) != 0b1000_0000,
        "Function does not work correctly if given a continuation byte.",
    )
    return int(count_leading_zeros(~b)) + int(b < 0b1000_0000)

fn main():
    print(_utf8_first_byte_sequence_length(ord("a")) == 1)
    print(_utf8_first_byte_sequence_length("🔥".as_bytes()[0]) == 4)
    alias `🔥` = "🔥".as_bytes()[0]
    alias length = _utf8_first_byte_sequence_length(`🔥`)
    print(length == 4)

System information

- Provide version information for Mojo by pasting the output of `mojo -v`
`mojo 24.6.0.dev2024120805`
@martinvuyk martinvuyk added bug Something isn't working mojo-repo Tag all issues with this label labels Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant