CMOV assembly instruction compilation fails

99 views
Skip to first unread message

Florian Uekermann

unread,
May 27, 2014, 7:39:20 AM5/27/14
to golan...@googlegroups.com
I started playing around with assembly functions in go after looking at the assembly output

I found out that there are conditional move instructions ( http://golang.org/src/cmd/6l/6.out.h#L419 - I am on Linux 64bit ),
but I can't figure out how to use them correctly. This assembly implementation of the Less function:

// func lessMYASM(a,b int) bool
TEXT    ·lessMYASM+0(SB),$0-24
MOVQ    a+0(FP),BX
MOVQ    b+8(FP),BP
MOVB    $0,ret+16(FP)
CMPQ    BX,BP
CMOVLLE $1,ret+16(FP)
RET     ,

results in the following compilation error for me:
main.lessMYASM: doasm: notfound from=75 to=74 (20) CMOVLLE $1,ret+24(SP)

One thing that surprises me on top of this error is that I can't find any CMOVBxx instructions
and that the error message replaced 16 with 24 in the end.

What am I doing wrong here?

Best regards,
Florian

Jan Mercl

unread,
May 27, 2014, 7:52:32 AM5/27/14
to Florian Uekermann, golang-nuts
On Tue, May 27, 2014 at 1:39 PM, Florian Uekermann
<florian....@googlemail.com> wrote:
> I started playing around with assembly functions in go after looking at the
> assembly output
> for generating booleans yesterday (
> https://groups.google.com/forum/#!topic/golang-nuts/eG3uUl3GQD4 )
>
> I found out that there are conditional move instructions (
> http://golang.org/src/cmd/6l/6.out.h#L419 - I am on Linux 64bit ),
> but I can't figure out how to use them correctly. This assembly
> implementation of the Less function:
>
> // func lessMYASM(a,b int) bool
> TEXT ·lessMYASM+0(SB),$0-24
> MOVQ a+0(FP),BX
> MOVQ b+8(FP),BP
> MOVB $0,ret+16(FP)
> CMPQ BX,BP
> CMOVLLE $1,ret+16(FP)
> RET ,

Seems like there's no immediate operand for CMOV - dst must be a reg
and src a reg/mem: http://www.rcollins.org/p6/opcodes/CMOV.html

-j

Florian Uekermann

unread,
May 27, 2014, 8:24:16 AM5/27/14
to golan...@googlegroups.com, Florian Uekermann
Seems like there's no immediate operand for CMOV - dst must be a reg
and src a reg/mem: http://www.rcollins.org/p6/opcodes/CMOV.html

-j

Thanks, that helped a lot. Especially the hint that I need to use registers.
I would have not figured that out myself.

jonathan....@gmail.com

unread,
May 27, 2014, 8:37:42 AM5/27/14
to golan...@googlegroups.com, Florian Uekermann
Great that the Go asm syntax now supports cmov. I remember the last time I needed that the only option was to enter the instruction opcodes as bytes.
Reply all
Reply to author
Forward
0 new messages