Created
May 19, 2019 01:50
-
-
Save joaofnds/a74cb80af43e86c2b2aea972a76fe9aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
| func main() { | |
| memAddress := uint(26) | |
| // memAddressSize := uint(32) | |
| entriesNum := uint(8) | |
| indexSize := uint(math.Log2(float64(entriesNum))) | |
| // tagSize := memAddressSize - indexSize | |
| tag := memAddress >> indexSize | |
| ones := ^uint(0) | |
| indexMask := ones^(ones << indexSize) | |
| index := memAddress & indexMask | |
| fmt.Printf("reference %d (%05b)\n", memAddress, memAddress) | |
| fmt.Printf("index: %03b\ntag: %02b\n", index, tag) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment