Thanks Fengyang

On Saturday, October 8, 2016 at 12:39:42 AM UTC-3, Fengyang Wang wrote:
>
> As Jussi Piitulainen noted, the ^ operator is backwards, so you need to 
> wrap it around a function.
>
> On Friday, October 7, 2016 at 10:05:34 AM UTC-4, Kevin Liu wrote:
>>
>> *julia> **@code_native(b^a)*
>>
>>        .section        __TEXT,__text,regular,pure_instructions
>>
>> Filename: bool.jl
>>
>> Source line: 39
>>
>>        pushq   %rbp
>>
>>        movq    %rsp, %rbp
>>
>> Source line: 39
>>
>>        xorb    $1, %sil
>>
>>        orb     %dil, %sil
>>
>>        movb    %sil, %al
>>
>>        popq    %rbp
>>
>>        ret
>>
>> *julia> **@code_native(a<=b)*
>>
>>        .section        __TEXT,__text,regular,pure_instructions
>>
>> Filename: bool.jl
>>
>> Source line: 29
>>
>>        pushq   %rbp
>>
>>        movq    %rsp, %rbp
>>
>> Source line: 29
>>
>>        xorb    $1, %dil
>>
>>        orb     %sil, %dil
>>
>>        movb    %dil, %al
>>
>>        popq    %rbp
>>
>>        ret
>>
>> *julia> **@code_native(ifelse(a,b,true))*
>>
>>        .section        __TEXT,__text,regular,pure_instructions
>>
>> Filename: operators.jl
>>
>> Source line: 48
>>
>>        pushq   %rbp
>>
>>        movq    %rsp, %rbp
>>
>>        testb   $1, %dil
>>
>> Source line: 48
>>
>>        jne     L17
>>
>>        movb    %dl, %sil
>>
>> L17:   movb    %sil, %al
>>
>>        popq    %rbp
>>
>>        ret
>>
>>
>>
>> On Friday, October 7, 2016 at 10:58:34 AM UTC-3, Kevin Liu wrote:
>>>
>>> *julia> **@code_llvm(b^a)*
>>>
>>>
>>> define i1 @"julia_^_21646"(i1, i1) {
>>>
>>> top:
>>>
>>>   %2 = xor i1 %1, true
>>>
>>>   %3 = or i1 %0, %2
>>>
>>>   ret i1 %3
>>>
>>> }
>>>
>>> On Friday, October 7, 2016 at 10:56:26 AM UTC-3, Kevin Liu wrote:
>>>>
>>>> Sorry, no need, I got this
>>>>
>>>> *julia> **@code_llvm(a<=b)*
>>>>
>>>>
>>>> define i1 @"julia_<=_21637"(i1, i1) {
>>>>
>>>> top:
>>>>
>>>>   %2 = xor i1 %0, true
>>>>
>>>>   %3 = or i1 %1, %2
>>>>
>>>>   ret i1 %3
>>>>
>>>> }
>>>>
>>>>
>>>> *julia> **@code_llvm(ifelse(a,b,true))*
>>>>
>>>>
>>>> define i1 @julia_ifelse_21636(i1, i1, i1) {
>>>>
>>>> top:
>>>>
>>>>   %3 = select i1 %0, i1 %1, i1 %2
>>>>
>>>>   ret i1 %3
>>>>
>>>> }
>>>>
>>>>
>>>> How do you read this output?
>>>>
>>>> On Friday, October 7, 2016 at 10:50:57 AM UTC-3, Kevin Liu wrote:
>>>>>
>>>>> Jeffrey, can you show the expression you put inside @code_llvm() and 
>>>>> @code_native() for evaluation? 
>>>>>
>>>>> On Friday, October 7, 2016 at 2:26:56 AM UTC-3, Jeffrey Sarnoff wrote:
>>>>>>
>>>>>> Hi Jussi,
>>>>>>
>>>>>> Your version compiles down more neatly than the ifelse version. On my 
>>>>>> system, BenchmarkTools gives nearly identical results; I don't know why, 
>>>>>> but the ifelse version is consistently a smidge faster (~%2, relative 
>>>>>> speed). Here is the llvm code and local native code for each, your 
>>>>>> version 
>>>>>> looks more tidy.  
>>>>>>
>>>>>>
>>>>>> ```
>>>>>> implies(p::Bool, q::Bool) = (p <= q)          implies(p::Bool, 
>>>>>> q::Bool) = ifelse( p, q, true )
>>>>>>
>>>>>> # llvm
>>>>>>
>>>>>>   %2 = xor i8 %0, 1                                %2 = and i8 %0, 1
>>>>>>   %3 = or i8 %2, %1                                %3 = icmp eq i8 
>>>>>> %2, 0
>>>>>>   ret i8 %3                                        %4 = select i1 %3, 
>>>>>> i8 1, i8 %1
>>>>>>                                                    ret i8 %3
>>>>>>
>>>>>> # native with some common code removed
>>>>>>
>>>>>>         xorb   $1, %dil                            testb  $1, %dil
>>>>>> orb    %sil, %dil                          movb   $1, %al
>>>>>>         movb   %dil, %al                           je     L15
>>>>>>         popq   %rbp                                movb   %sil, %al
>>>>>>         retq                                 L15:  popq   %rbp
>>>>>>                                                    retq
>>>>>> ```
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Friday, October 7, 2016 at 12:22:23 AM UTC-4, Jussi Piitulainen 
>>>>>> wrote:
>>>>>>>
>>>>>>>
>>>>>>> implies(p::Bool, q::Bool) = p <= q
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> torstai 6. lokakuuta 2016 19.10.51 UTC+3 Kevin Liu kirjoitti:
>>>>>>>>
>>>>>>>> How is an implication represented in Julia? 
>>>>>>>>
>>>>>>>>
>>>>>>>> https://en.wikipedia.org/wiki/Material_conditional#Definitions_of_the_material_conditional
>>>>>>>>
>>>>>>>

Reply via email to