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: emit variable byte-sized bit tests on amd64 #25156

josharian opened this issue Apr 29, 2018 · 1 comment


Copy link

@josharian josharian commented Apr 29, 2018

Conversation moved from CL 109716.

Consider this code from the runtime:

// Information from the compiler about the layout of stack frames.
type bitvector struct {
	n        int32 // # of bits
	bytedata *uint8

// ptrbit returns the i'th bit in bv.
func (bv *bitvector) ptrbit(i uintptr) uint8 {
	b := *(addb(bv.bytedata, i/8))
	return (b >> (i % 8)) & 1

ptrbit should generate a BTL instruction on amd64, but instead it generates RSH and AND. (Related work: CL 105037.) IIRC, we intentionally don't generate BTL instructions for constant-offset bit tests for bytes, since the equivalent TEST instruction is shorter or faster.

cc @rasky

@josharian josharian added this to the Unplanned milestone Apr 29, 2018

This comment has been minimized.

Copy link

@rasky rasky commented Apr 29, 2018

To clarify: I think ptrbit should generate a BTL instruction when ptrbit is used as part of a comparison: bv.ptrbit(i) == 1 or similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.