~mpu/qbe

2 2

Kw cmp ops for Kl result

Details
Message ID
<CAAS8gYDtNQXgL64u2HEnvi4DYFTsy0ro1G-V3SP9iwJaVn9MJg@mail.gmail.com>
DKIM signature
pass
Download raw message
For if-conversion of Kl values I would like to generate a Kl result
straight from cmp ops, rather than adding an extra ext instruction.

This seems to work, superficially, for example test/load1.ssa:

------------

rolandpj@rolandpj-VivoBook-ASUSLaptop-X515DAP-M515DA:~/src/qbe$ qbe
-dK test/load1.ssa
**** Function f ****
> Block merge:

> If-conversion:

                $f if-converting @start -> @true, @false -> @end - nphis 1

> After if-conversion:

function $f() {
@start
    %cond =w par
    %x =l alloc4 4
    %y =l alloc4 4
    storew 0, %x
    %ifc.1 =l cnew %cond, 0      <--- just this, ignore the rest
    %ifc.2 =w neg %ifc.1
    %ifc.3 =w sub %ifc.1, 1
    %ifc.4 =l xor %x, %y
    %ifc.5 =l and %ifc.2, %x
    %ifc.6 =l and %ifc.3, %y
    %ptr =l or %ifc.5, %ifc.6
@end
    storew 1, %ptr
    %result =w loadsw %x
    retw %result
}

----------------

x86 assembler output:

rolandpj@rolandpj-VivoBook-ASUSLaptop-X515DAP-M515DA:~/src/qbe$ qbe
test/load1.ssa

                $f if-converting @start -> @true, @false -> @end - nphis 1
.text
.globl f
f:
    endbr64
    pushq %rbp
    movq %rsp, %rbp
    subq $16, %rsp
    movl $0, -8(%rbp)
    cmpl $0, %edi
    setnz %cl
    movzbq %cl, %rcx    <---- looks sound
    movl %ecx, %eax
    negl %eax
    subl $1, %ecx
    leaq -8(%rbp), %rdx
    andq %rdx, %rax
    leaq -4(%rbp), %rdx
    andq %rdx, %rcx
    orq %rcx, %rax
    movl $1, (%rax)
    movl -8(%rbp), %eax
    leave
    ret
.type f, @function
.size f, .-f
/* end function f */

.section .note.GNU-stack,"",@progbits

-----------

However hare make check is failing...

I guess RTFC, but maybe this is just a bad idea?

R
Details
Message ID
<CAAS8gYB5Gfr_C3TODFxfO6bmrXXV7xNedPE63e8FGgvwwvo8sQ@mail.gmail.com>
In-Reply-To
<CAAS8gYDtNQXgL64u2HEnvi4DYFTsy0ro1G-V3SP9iwJaVn9MJg@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message
> For if-conversion of Kl values I would like to generate a Kl result
> straight from cmp ops, rather than adding an extra ext instruction.

RTFM - https://c9x.me/compile/doc/il.html#Comparisons

"Comparison instructions return an integer value (either a word or a long)"

This should just work, so likely my SNAFU.

R
Details
Message ID
<5dfcaf4e-4b80-4ab0-80dc-381ebacce638@app.fastmail.com>
In-Reply-To
<CAAS8gYB5Gfr_C3TODFxfO6bmrXXV7xNedPE63e8FGgvwwvo8sQ@mail.gmail.com> (view parent)
DKIM signature
pass
Download raw message

On Wed, Aug 7, 2024, at 10:55, Roland Paterson-Jones wrote:
>> For if-conversion of Kl values I would like to generate a Kl result
>> straight from cmp ops, rather than adding an extra ext instruction.
>
> This should just work

Yes, if it does not it's a bug :).
Reply to thread Export thread (mbox)