-
Notifications
You must be signed in to change notification settings - Fork 17.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-branch.go1.10] cmd/compile: fix constant folding of right sh…
…ifts The sub-word shifts need to sign-extend before shifting, to avoid bringing in data from higher in the argument. Fixes #23812 Change-Id: I0a95a0b49c48f3b40b85765bb4a9bb492be0cd73 Reviewed-on: https://go-review.googlesource.com/93716 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]> (cherry picked from commit 755b36a) Reviewed-on: https://go-review.googlesource.com/94215 Reviewed-by: Brad Fitzpatrick <[email protected]>
- Loading branch information
Showing
4 changed files
with
55 additions
and
21 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
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,34 @@ | ||
// run | ||
|
||
// Copyright 2018 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 main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
want := int32(0x3edae8) | ||
got := foo(1) | ||
if want != got { | ||
panic(fmt.Sprintf("want %x, got %x", want, got)) | ||
} | ||
} | ||
|
||
func foo(a int32) int32 { | ||
return shr1(int32(shr2(int64(0x14ff6e2207db5d1f), int(a))), 4) | ||
} | ||
|
||
func shr1(n int32, m int) int32 { return n >> uint(m) } | ||
|
||
func shr2(n int64, m int) int64 { | ||
if m < 0 { | ||
m = -m | ||
} | ||
if m >= 64 { | ||
return n | ||
} | ||
|
||
return n >> uint(m) | ||
} |