Find first set

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Find first set

Matthew Hammer
Hi Rust Developers,

I’m in need of this bit-level operation:

  http://en.wikipedia.org/wiki/Find_first_set

I’m happy to implement it as a loop, but it seems like many architectures support it directly, as does libc.

Does anyone know if this is implemented in the Rust standard library or among the current primitives?

Searching for “ffs” in the source tree got me nowhere.

Thanks,
-Matt

_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: Find first set

Kevin McGuire
On Mon, Jan 12, 2015 at 11:12 AM, Matthew Hammer <[hidden email]> wrote:

> Hi Rust Developers,
> I’m in need of this bit-level operation:
>
>   http://en.wikipedia.org/wiki/Find_first_set
>
> I’m happy to implement it as a loop, but it seems like many architectures
> support it directly, as does libc.
>
> Does anyone know if this is implemented in the Rust standard library or
> among the current primitives?
>
> Searching for “ffs” in the source tree got me nowhere.
>
> Thanks,
> -Matt

I know that there have been people who have brought this to attention.
I know there is likely someone who has written a solution, but I can
not remember where it was located.

I do remember that it involved the usage of inline assembly and
#[cfg()] directives. It essentially provided a general implementation
that worked everywhere, then it provided implementations specific to a
certain architecture. By using the config attribute one could toggle
between the generic or architecture specific method being implemented
and thus callable.

I do not know for certain if it is or is not implemented in the
standard library, but I have the feeling that it is not. I tried to
look for it but failed.
_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev
Reply | Threaded
Open this post in threaded view
|

Re: Find first set

Peter Marheine
You can express ffs in terms of nlz, which is available as
Int::leading_zeros and appears to be implemented with LLVM intrinsics
for most types.

On Mon, Jan 12, 2015 at 10:17 AM, Kevin McGuire <[hidden email]> wrote:

> On Mon, Jan 12, 2015 at 11:12 AM, Matthew Hammer <[hidden email]> wrote:
>> Hi Rust Developers,
>> I’m in need of this bit-level operation:
>>
>>   http://en.wikipedia.org/wiki/Find_first_set
>>
>> I’m happy to implement it as a loop, but it seems like many architectures
>> support it directly, as does libc.
>>
>> Does anyone know if this is implemented in the Rust standard library or
>> among the current primitives?
>>
>> Searching for “ffs” in the source tree got me nowhere.
>>
>> Thanks,
>> -Matt
>
> I know that there have been people who have brought this to attention.
> I know there is likely someone who has written a solution, but I can
> not remember where it was located.
>
> I do remember that it involved the usage of inline assembly and
> #[cfg()] directives. It essentially provided a general implementation
> that worked everywhere, then it provided implementations specific to a
> certain architecture. By using the config attribute one could toggle
> between the generic or architecture specific method being implemented
> and thus callable.
>
> I do not know for certain if it is or is not implemented in the
> standard library, but I have the feeling that it is not. I tried to
> look for it but failed.
> _______________________________________________
> Rust-dev mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/rust-dev



--
Peter Marheine
Don't Panic
_______________________________________________
Rust-dev mailing list
[hidden email]
https://mail.mozilla.org/listinfo/rust-dev