Skip to content

Commit

Permalink
bound check hints concrete (f redesign)
Browse files Browse the repository at this point in the history
  • Loading branch information
davecgh committed Jul 15, 2024
1 parent 75e2da8 commit 31147f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion crypto/blake256/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ func (h *hasher) saveState(target []byte, prefix uint32) []byte {
h.putSavedState(state[:], prefix)
return append(target, state[:]...)
}
_ = target[:len(target)+SavedStateSize] // Bounds check hint to compiler.
h.putSavedState(target[len(target):len(target)+SavedStateSize], prefix)
return target[:len(target)+SavedStateSize]
}
Expand Down
11 changes: 7 additions & 4 deletions crypto/blake256/internal/compress/blocks_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ func blocksGeneric(state *State, msg []byte, counter uint64) {
// Ideally these hints wouldn't be necessary, but they do make quite a big
// difference in avoiding a bunch of additional bounds checks as determined
// by both reviewing the resulting compiled asm as well as benchmarks.
h := state.CV[:8] // Bounds check hint to compiler.
s := state.S[:4] // Bounds check hint to compiler.
m := state.scratch[:16] // Bounds check hint to compiler.
h := &state.CV
s := &state.S
m := &state.scratch
_ = h[7] // Bounds check hints to compiler.
_ = s[3] // Bounds check hint to compiler.
_ = m[15] // Bounds check hint to compiler.
for numBlocks := len(msg) >> blockSizeLog2; numBlocks > 0; numBlocks-- {
_ = msg[:64] // Bounds check hint to compiler.
_ = msg[63] // Bounds check hint to compiler.

// Convert the provided message of at least 64 bytes to an array of 16
// 32-bit unsigned big-endian words.
Expand Down

0 comments on commit 31147f9

Please sign in to comment.