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

count_[ones,zeros]() fails to compile for numbers other than u32, i32 #215

Open
Firestar99 opened this issue Feb 3, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Firestar99
Copy link
Member

Expected Behaviour

count_ones and count_zeros works for u32 and i32, but does not for u8, u16, u64, i8, i16 and i64.

Example & Steps To Reproduce

// build-pass

use spirv_std::spirv;

#[spirv(fragment)]
pub fn main(#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] x: &mut [u32]) {
    x[0] = u8::count_ones(0x12);
    x[1] = u16::count_ones(0x12);
    x[2] = u32::count_ones(0x12); // u32 works
    x[3] = u64::count_ones(0x12);

    x[5] = i8::count_ones(0x12);
    x[6] = i16::count_ones(0x12);
    x[7] = i32::count_ones(0x12); // i32 works
    x[8] = i64::count_ones(0x12);
}
Error

error: cannot cast between pointer types
       from `*u32`
         to `*u8`
   --> /home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:535:5
    |
535 | /     uint_impl! {
536 | |         Self = u8,
537 | |         ActualT = u8,
538 | |         SignedT = i8,
...   |
552 | |         bound_condition = "",
553 | |     }
    | |_____^
    |
note: used from within `<u8>::count_ones`
   --> /home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:535:5
    |
535 | /     uint_impl! {
536 | |         Self = u8,
537 | |         ActualT = u8,
538 | |         SignedT = i8,
...   |
552 | |         bound_condition = "",
553 | |     }
    | |_____^
note: called by `issue_329::main`
   --> $DIR/issue-329.rs:7:12
    |
7   |     x[0] = u8::count_ones(0x12);
    |            ^^^^^^^^^^^^^^^^^^^^
note: called by `main`
   --> $DIR/issue-329.rs:6:8
    |
6   | pub fn main(#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] x: &mut [u32]) {
    |        ^^^^

error: cannot cast between pointer types
       from `*u32`
         to `*u16`
    --> /home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1151:5
     |
1151 | /     uint_impl! {
1152 | |         Self = u16,
1153 | |         ActualT = u16,
1154 | |         SignedT = i16,
...    |
1168 | |         bound_condition = "",
1169 | |     }
     | |_____^
     |
note: used from within `<u16>::count_ones`
    --> /home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1151:5
     |
1151 | /     uint_impl! {
1152 | |         Self = u16,
1153 | |         ActualT = u16,
1154 | |         SignedT = i16,
...    |
1168 | |         bound_condition = "",
1169 | |     }
     | |_____^
note: called by `issue_329::main`
    --> $DIR/issue-329.rs:8:12
     |
8    |     x[1] = u16::count_ones(0x12);
     |            ^^^^^^^^^^^^^^^^^^^^^
note: called by `main`
    --> $DIR/issue-329.rs:6:8
     |
6    | pub fn main(#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] x: &mut [u32]) {
     |        ^^^^

error: cannot cast between pointer types
       from `*u32`
         to `*u64`
    --> /home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1223:5
     |
1223 | /     uint_impl! {
1224 | |         Self = u64,
1225 | |         ActualT = u64,
1226 | |         SignedT = i64,
...    |
1240 | |         bound_condition = "",
1241 | |     }
     | |_____^
     |
note: used from within `<u64>::count_ones`
    --> /home/firestar99/.rustup/toolchains/nightly-2024-11-22-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs:1223:5
     |
1223 | /     uint_impl! {
1224 | |         Self = u64,
1225 | |         ActualT = u64,
1226 | |         SignedT = i64,
...    |
1240 | |         bound_condition = "",
1241 | |     }
     | |_____^
note: called by `issue_329::main`
    --> $DIR/issue-329.rs:10:12
     |
10   |     x[3] = u64::count_ones(0x12);
     |            ^^^^^^^^^^^^^^^^^^^^^
note: called by `main`
    --> $DIR/issue-329.rs:6:8
     |
6    | pub fn main(#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] x: &mut [u32]) {
     |        ^^^^

error: aborting due to 3 previous errors

System Info

Rust-gpu master 6e2c84d

@Firestar99 Firestar99 added the bug Something isn't working label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant