Skip to content

Commit 67f8686

Browse files
Jade ZhaoReVe1uv
authored andcommitted
crypto/md5: Improve ARM64 MD5 performance by optimizing ROUND3 function
This commit enhances the performance of the MD5 functionality on ARM64 architecture by optimizing the ROUND3 function in the `md5block_arm64.s` assembly file. - Refactored the `ROUND3` macro to improve the computation order, introducing a new `ROUND3FIRST` macro to handle the initial calculation more efficiently. - Optimized the XOR operations in the `ROUND3` macro to reduce unnecessary instructions and improve parallelism within the ARM64 architecture. Performance testing was conducted on an ARM64 Linux machine using Go's benchmark tool. The benchmarks were run 10 times each to ensure statistical significance. The following results were observed: | Benchmark | Old Time | New Time | Change | | | (sec/op) | (sec/op) | | |-----------------------|--------------|------------- |--------| | Hash8Bytes-8 | 175.0ns 2% | 175.0ns 1% | ~ | | Hash1K-8 | 2.065µs 0% | 2.060µs 0% | -0.22% | | Hash8K-8 | 15.31µs 0% | 15.29µs 0% | -0.11% | | Hash8BytesUnaligned-8 | 174.0ns 1% | 174.0ns 1% | ~ | | Hash1KUnaligned-8 | 2.067µs 0% | 2.059µs 0% | -0.41% | | Hash8KUnaligned-8 | 15.44µs 0% | 15.45µs 0% | ~ | In terms of throughput: | Benchmark | Old Throughput | New Throughput | Change | | | (B/s) | (B/s) | | |-----------------------|-----------------|-----------------|--------| | Hash8Bytes-8 | 43.58MiB/s 2% | 43.69MiB/s 0% | +0.24% | | Hash1K-8 | 473.1MiB/s 0% | 474.0MiB/s 0% | +0.20% | | Hash8K-8 | 510.4MiB/s 0% | 511.0MiB/s 0% | +0.11% | | Hash8BytesUnaligned-8 | 43.80MiB/s 0% | 43.82MiB/s 0% | ~ | | Hash1KUnaligned-8 | 472.5MiB/s 0% | 474.3MiB/s 0% | +0.38% | | Hash8KUnaligned-8 | 506.1MiB/s 0% | 505.8MiB/s 0% | ~ | When testing with large files (e.g., a 3GB file), the runtime was reduced from 8.65 seconds to 7.39 seconds, resulting in an approximate 9% reduction in execution time. This demonstrates a more significant performance gain when handling larger datasets. Overall, these optimizations provide modest improvements for small input sizes and more noticeable performance benefits when processing larger files, especially in memory-intensive workloads like file hashing.
1 parent 6f5d774 commit 67f8686

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/crypto/md5/md5block_arm64.s

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,28 @@ loop:
9393
MOVW (5*4)(R1), R8
9494
MOVW R6, R9
9595

96+
#define ROUND3FIRST(a, b, c, d, index, const, shift) \
97+
MOVW d, R9; \
98+
EORW c, R9; \
99+
EORW b, R9; \
100+
ADDW $const, a; \
101+
ADDW R8, a; \
102+
MOVW (index*4)(R1),R8; \
103+
ADDW R9, a; \
104+
RORW $(32-shift), a; \
105+
ADDW b, a
106+
96107
#define ROUND3(a, b, c, d, index, const, shift) \
108+
EORW a, R9; \
109+
EORW b, R9; \
97110
ADDW $const, a; \
98111
ADDW R8, a; \
99112
MOVW (index*4)(R1), R8; \
100-
EORW d, R9; \
101-
EORW b, R9; \
102113
ADDW R9, a; \
103114
RORW $(32-shift), a; \
104-
MOVW b, R9; \
105115
ADDW b, a
106116

107-
ROUND3(R4,R5,R6,R7, 8,0xfffa3942, 4);
117+
ROUND3FIRST(R4,R5,R6,R7, 8,0xfffa3942, 4);
108118
ROUND3(R7,R4,R5,R6,11,0x8771f681,11);
109119
ROUND3(R6,R7,R4,R5,14,0x6d9d6122,16);
110120
ROUND3(R5,R6,R7,R4, 1,0xfde5380c,23);

0 commit comments

Comments
 (0)