-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/compile: fix bit length intrinsic for 16/8 bits on GOAMD64=v3
Upper bits of registers for uint8/uint16 are junk. Make sure we mask those off before using LZCNT (leading zeros count). Fixes #52681 Change-Id: I0ca9e62f23bcb1f6ad2a787fa9895322afaa2533 Reviewed-on: https://go-review.googlesource.com/c/go/+/403815 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@google.com>
- Loading branch information
Showing
3 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package test | ||
|
||
import ( | ||
"math/bits" | ||
"testing" | ||
) | ||
|
||
func TestBitLen64(t *testing.T) { | ||
for i := 0; i <= 64; i++ { | ||
got := bits.Len64(1 << i) | ||
want := i + 1 | ||
if want == 65 { | ||
want = 0 | ||
} | ||
if got != want { | ||
t.Errorf("Len64(1<<%d) = %d, want %d", i, got, want) | ||
} | ||
} | ||
} | ||
|
||
func TestBitLen32(t *testing.T) { | ||
for i := 0; i <= 32; i++ { | ||
got := bits.Len32(1 << i) | ||
want := i + 1 | ||
if want == 33 { | ||
want = 0 | ||
} | ||
if got != want { | ||
t.Errorf("Len32(1<<%d) = %d, want %d", i, got, want) | ||
} | ||
} | ||
} | ||
|
||
func TestBitLen16(t *testing.T) { | ||
for i := 0; i <= 16; i++ { | ||
got := bits.Len16(1 << i) | ||
want := i + 1 | ||
if want == 17 { | ||
want = 0 | ||
} | ||
if got != want { | ||
t.Errorf("Len16(1<<%d) = %d, want %d", i, got, want) | ||
} | ||
} | ||
} | ||
|
||
func TestBitLen8(t *testing.T) { | ||
for i := 0; i <= 8; i++ { | ||
got := bits.Len8(1 << i) | ||
want := i + 1 | ||
if want == 9 { | ||
want = 0 | ||
} | ||
if got != want { | ||
t.Errorf("Len8(1<<%d) = %d, want %d", i, got, want) | ||
} | ||
} | ||
} |