Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: add branch-free ternary op codegen and use in cgen_slice #8448

Closed
josharian opened this issue Jul 30, 2014 · 3 comments
Closed

Comments

@josharian
Copy link
Contributor

CL 112570044 introduces a JMP into the middle of slicing, which disrupts some peephole
optimization. See the CL discussion for details.

We could fix this by introducing architecture-dependent branch-free ternary ops.

Here are a couple of tested (6g) implementations of the particular function that slicing
needs. Their performance is about the same.

// eq0 returns 0 if i == j and i otherwise.
func eq0(i, j int) int {
    if i == j {
        return 0
    }
    return i
}

TEXT ·eq0(SB),$0
    MOVQ    i+0(FP),AX
    CMPQ    AX,j+8(FP)
    SETEQ   CX
    DECQ    CX
    ANDQ    AX, CX
    MOVQ    CX,r+16(FP)
    RET ,

TEXT ·eq0(SB),$0
    MOVQ    i+0(FP),AX
    MOVQ    $0,CX
    CMPQ    AX,j+8(FP)
    CMOVQNE AX,CX
    MOVQ    CX,r+16(FP)
    RET ,

I'm not sure that this is worth the effort in the near term, though, unless there are
other places that also would benefit from branch-free ?:.
@josharian
Copy link
Contributor Author

Comment 1:

copyany (walk.c) could use a branch-free max function.

@rsc
Copy link
Contributor

rsc commented Aug 25, 2014

Comment 2:

I doubt this is the right thing to do but maybe. I can fix the slice thing without this.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: add branch-free ternary op codegen and use in cgen_slice cmd/compile: add branch-free ternary op codegen and use in cgen_slice Jun 8, 2015
@josharian
Copy link
Contributor Author

Obviated by the SSA backend.

@golang golang locked and limited conversation to collaborators Mar 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants