Skip to content

Instantly share code, notes, and snippets.

@joaofnds
Created May 19, 2019 01:50
Show Gist options
  • Select an option

  • Save joaofnds/a74cb80af43e86c2b2aea972a76fe9aa to your computer and use it in GitHub Desktop.

Select an option

Save joaofnds/a74cb80af43e86c2b2aea972a76fe9aa to your computer and use it in GitHub Desktop.
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