-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/internal/obj: sign extend 32-bit high immediate
Bit 19 may be set in the high immediate returned by Split32BitImmediate. (The most obvious case is for 1<<31-1). This means that the immediate will be sign-extended when used with LUI. We must sign-extend this value to make it clear that this is intentional, otherwise assemble will reject the immediate for 'not fitting in 20 bits'. Fixes golang#10 Change-Id: I83ac8a81a5fb1a9663af63bc2dee8a896567f945
- Loading branch information
Showing
3 changed files
with
42 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
//go:noinline | ||
func maxInt32() uint32 { | ||
return 1<<31-1 | ||
} | ||
|
||
func main() { | ||
x := maxInt32() | ||
if x != 1<<31-1 { | ||
riscvexit(1) | ||
} | ||
|
||
// Upper bits don't interfere in up-conversion. | ||
y := uint64(maxInt32()) + uint64(maxInt32()) | ||
if y != 1<<32-2 { | ||
riscvexit(2) | ||
} | ||
|
||
riscvexit(0) | ||
} |
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