Re: [julia-users] Numer of ones in bitstype

2016-08-13 Thread jw3126
Using the leading_zeros hint, I can access the first bit as follows:

firstbit(x) = leading_ones(x) > 0

This seems indirect however. And the code native also seems longer then 
what I would have hoped for:

@code_native firstbit(x)

.text
Filename: In[78]
Source line: 1
pushq   %rbp
movq%rsp, %rbp
Source line: 1
notb%dil
movzbl  %dil, %eax
movl$15, %ecx
bsrl%eax, %eax
cmovel  %ecx, %eax
xorl$7, %eax
testb   %al, %al
setne   %al
popq%rbp
ret
Is there a more efficient way in julia?



On Friday, August 12, 2016 at 2:10:37 PM UTC+2, jw3126 wrote:
>
> Thank you both!
>
> On Thursday, August 11, 2016 at 9:17:13 PM UTC+2, Erik Schnetter wrote:
>>
>> See also "leading_zeros".
>>
>> -erik
>>
>> On Thu, Aug 11, 2016 at 1:52 PM, Tom Breloff  wrote:
>>
>>> help?> count_ones
>>> search: count_ones count_zeros
>>>
>>>   count_ones(x::Integer) -> Integer
>>>
>>>   Number of ones in the binary representation of x.
>>>
>>>   julia> count_ones(7)
>>>   3
>>>
>>>
>>> On Thu, Aug 11, 2016 at 1:48 PM, jw3126  wrote:
>>>
 I have a bitstype and want to know the number of ones in its bit 
 representation as well as the first bit. How to accomplish these in a 
 performant way?

>>>
>>>
>>
>>
>> -- 
>> Erik Schnetter  
>> http://www.perimeterinstitute.ca/personal/eschnetter/
>>
>

Re: [julia-users] Numer of ones in bitstype

2016-08-13 Thread jw3126
Using the leading_zeros hint, I can access the first bit as follows:

firstbit(x) = leading_ones(x) > 0

Is this the most efficient way to access the first bit in julia? The code 
native seems longer then what I would have hoped for:

@code_native firstbit(0x12)

.text
Filename: int.jl
Source line: 139
pushq   %rbp
movq%rsp, %rbp
Source line: 139
notb%dil
movzbl  %dil, %eax
movl$15, %ecx
bsrl%eax, %eax
cmovel  %ecx, %eax
xorl$7, %eax
movzbl  %al, %eax
popq%rbp
ret





On Friday, August 12, 2016 at 2:10:37 PM UTC+2, jw3126 wrote:
>
> Thank you both!
>
> On Thursday, August 11, 2016 at 9:17:13 PM UTC+2, Erik Schnetter wrote:
>>
>> See also "leading_zeros".
>>
>> -erik
>>
>> On Thu, Aug 11, 2016 at 1:52 PM, Tom Breloff  wrote:
>>
>>> help?> count_ones
>>> search: count_ones count_zeros
>>>
>>>   count_ones(x::Integer) -> Integer
>>>
>>>   Number of ones in the binary representation of x.
>>>
>>>   julia> count_ones(7)
>>>   3
>>>
>>>
>>> On Thu, Aug 11, 2016 at 1:48 PM, jw3126  wrote:
>>>
 I have a bitstype and want to know the number of ones in its bit 
 representation as well as the first bit. How to accomplish these in a 
 performant way?

>>>
>>>
>>
>>
>> -- 
>> Erik Schnetter  
>> http://www.perimeterinstitute.ca/personal/eschnetter/
>>
>

Re: [julia-users] Numer of ones in bitstype

2016-08-12 Thread jw3126
Thank you both!

On Thursday, August 11, 2016 at 9:17:13 PM UTC+2, Erik Schnetter wrote:
>
> See also "leading_zeros".
>
> -erik
>
> On Thu, Aug 11, 2016 at 1:52 PM, Tom Breloff  > wrote:
>
>> help?> count_ones
>> search: count_ones count_zeros
>>
>>   count_ones(x::Integer) -> Integer
>>
>>   Number of ones in the binary representation of x.
>>
>>   julia> count_ones(7)
>>   3
>>
>>
>> On Thu, Aug 11, 2016 at 1:48 PM, jw3126 > 
>> wrote:
>>
>>> I have a bitstype and want to know the number of ones in its bit 
>>> representation as well as the first bit. How to accomplish these in a 
>>> performant way?
>>>
>>
>>
>
>
> -- 
> Erik Schnetter > 
> http://www.perimeterinstitute.ca/personal/eschnetter/
>


Re: [julia-users] Numer of ones in bitstype

2016-08-11 Thread Erik Schnetter
See also "leading_zeros".

-erik

On Thu, Aug 11, 2016 at 1:52 PM, Tom Breloff  wrote:

> help?> count_ones
> search: count_ones count_zeros
>
>   count_ones(x::Integer) -> Integer
>
>   Number of ones in the binary representation of x.
>
>   julia> count_ones(7)
>   3
>
>
> On Thu, Aug 11, 2016 at 1:48 PM, jw3126  wrote:
>
>> I have a bitstype and want to know the number of ones in its bit
>> representation as well as the first bit. How to accomplish these in a
>> performant way?
>>
>
>


-- 
Erik Schnetter 
http://www.perimeterinstitute.ca/personal/eschnetter/


Re: [julia-users] Numer of ones in bitstype

2016-08-11 Thread Tom Breloff
help?> count_ones
search: count_ones count_zeros

  count_ones(x::Integer) -> Integer

  Number of ones in the binary representation of x.

  julia> count_ones(7)
  3


On Thu, Aug 11, 2016 at 1:48 PM, jw3126  wrote:

> I have a bitstype and want to know the number of ones in its bit
> representation as well as the first bit. How to accomplish these in a
> performant way?
>


[julia-users] Numer of ones in bitstype

2016-08-11 Thread jw3126
I have a bitstype and want to know the number of ones in its bit 
representation as well as the first bit. How to accomplish these in a 
performant way?