Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(413)

Delta Between Two Patch Sets: src/pkg/crypto/md5/md5block.go

Issue 6782072: code review 6782072: crypto/md5: speed up aligned writes and test/bench unal... (Closed)
Left Patch Set: Created 11 years, 4 months ago
Right Patch Set: diff -r 5eee09217fcd https://code.google.com/p/go/ Created 11 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/crypto/md5/md5_test.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 package md5 1 package md5
2 2
3 import ( 3 import (
4 "runtime" 4 "runtime"
5 "unsafe" 5 "unsafe"
6 ) 6 )
7 7
8 func block(dig *digest, p []byte) { 8 func block(dig *digest, p []byte) {
9 a := dig.s[0] 9 a := dig.s[0]
10 b := dig.s[1] 10 b := dig.s[1]
11 c := dig.s[2] 11 c := dig.s[2]
12 d := dig.s[3] 12 d := dig.s[3]
13 var X *[16]uint32 13 var X *[16]uint32
14 var xbuf [16]uint32 14 var xbuf [16]uint32
15 for len(p) >= chunk { 15 for len(p) >= chunk {
16 aa, bb, cc, dd := a, b, c, d 16 aa, bb, cc, dd := a, b, c, d
17 17
18 // This is a constant condition - it is not evaluated on each it eration. 18 // This is a constant condition - it is not evaluated on each it eration.
19 if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" { 19 if runtime.GOARCH == "amd64" || runtime.GOARCH == "386" {
20 // MD5 was designed so that x86 processors can just iter ate 20 // MD5 was designed so that x86 processors can just iter ate
21 // over the block data directly as uint32s, and we gener ate 21 // over the block data directly as uint32s, and we gener ate
22 // less code and run 1.3x faster if we take advantage of that. 22 // less code and run 1.3x faster if we take advantage of that.
23 // My apologies. 23 // My apologies.
24 X = (*[16]uint32)(unsafe.Pointer(&p[0])) 24 X = (*[16]uint32)(unsafe.Pointer(&p[0]))
25 } else if uintptr(unsafe.Pointer(&p[0]))&(unsafe.Alignof(uint32( 0))-1) == 0 {
26 X = (*[16]uint32)(unsafe.Pointer(&p[0]))
25 } else { 27 } else {
26 X = &xbuf 28 X = &xbuf
27 j := 0 29 j := 0
28 for i := 0; i < 16; i++ { 30 for i := 0; i < 16; i++ {
29 X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uin t32(p[j+2])<<16 | uint32(p[j+3])<<24 31 X[i&15] = uint32(p[j]) | uint32(p[j+1])<<8 | uin t32(p[j+2])<<16 | uint32(p[j+3])<<24
30 j += 4 32 j += 4
31 } 33 }
32 } 34 }
33 35
34 // Round 1. 36 // Round 1.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 d += dd 239 d += dd
238 240
239 p = p[chunk:] 241 p = p[chunk:]
240 } 242 }
241 243
242 dig.s[0] = a 244 dig.s[0] = a
243 dig.s[1] = b 245 dig.s[1] = b
244 dig.s[2] = c 246 dig.s[2] = c
245 dig.s[3] = d 247 dig.s[3] = d
246 } 248 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b