1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:22:22 +00:00
2018-12-16 12:37:35 +08:00

32 lines
1005 B
ArmAsm

// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "textflag.h"
//
// https://github.com/golang/go/issues/14288
//
// from rsc:
// But expanding what I said yesterday just a bit:
// never use MOVB or MOVW with a register destination,
// since it's inefficient (it's a read-modify-write on the target register).
// Instead use MOVL for reg->reg and use MOVBLZX or MOVWLZX for mem->reg;
// those are pure writes on the target register.
//
// , bool, 使 MOVBLZX.
// 使 MOVB , go test ,
// go run runme.go .
//
// func AsmIf(ok bool, a, b int) int
TEXT ·AsmIf(SB), NOSPLIT, $0-32
MOVBQZX ok+0(FP), AX // ok
MOVQ a+8(FP), BX // a
MOVQ b+16(FP), CX // b
CMPQ AX, $0 // test ok
JEQ 3(PC) // if !ok, skip 2 line
MOVQ BX, ret+24(FP) // return a
RET
MOVQ CX, ret+24(FP) // return b
RET