ObjFW  Check-in [b29adaf0bb]

Overview
Comment:OFMD5Hash: Optimize by making it more readable

This has more resemblance to the implementation of the other hashes,
while the old method had more resemblance to how the algorithm is
described in the RFC.

It turns out that Clang generates better code when re-assigning all
variables to rotate them by one instead of accessing the variables by an
iteration-dependent index.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b29adaf0bb1df329fecb9968876f5c66951557ce513bf995c53ce88bf0c4aac0
User & Date: js on 2014-09-03 18:53:24
Other Links: manifest | tags
Context
2014-09-03
22:22
Add OFRIPEMD160Hash check-in: 126d9d3aa1 user: js tags: trunk
18:53
OFMD5Hash: Optimize by making it more readable check-in: b29adaf0bb user: js tags: trunk
15:46
Add OFSHA384Hash and OFSHA512Hash check-in: 23f6c0f84d user: js tags: trunk
Changes

Modified src/OFMD5Hash.m from [8c6a093adf] to [38980867ce].

79
80
81
82
83
84
85
86
87
88
89




90
91
92
93
94
95
96
97






98
99
100
101
102
103
104
79
80
81
82
83
84
85




86
87
88
89








90
91
92
93
94
95
96
97
98
99
100
101
102







-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+







	new[0] = state[0];
	new[1] = state[1];
	new[2] = state[2];
	new[3] = state[3];

	byteSwapVectorIfBE(buffer, 16);

#define LOOP_BODY(f)							   \
	{								   \
		const uint_fast8_t a = (4 - (i & 3)) & 3;		   \
		const uint_fast8_t b = (a + 1) & 3;			   \
#define LOOP_BODY(f)							      \
	{								      \
		uint32_t tmp = new[3];					      \
		tmp = new[3];						      \
		const uint_fast8_t c = (a + 2) & 3;			   \
		const uint_fast8_t d = (a + 3) & 3;			   \
		const uint_fast8_t r = rotateBits[(i % 4) + (i / 16) * 4]; \
									   \
		new[a] += f(new[b], new[c], new[d]) +			   \
		    buffer[wordOrder[i]] + table[i];			   \
		new[a] = OF_ROL(new[a], r);				   \
		new[a] += new[b];					   \
		new[0] += f(new[1], new[2], new[3]) +			      \
		    buffer[wordOrder[i]] + table[i];			      \
		new[3] = new[2];					      \
		new[2] = new[1];					      \
		new[1] += OF_ROL(new[0], rotateBits[(i % 4) + (i / 16) * 4]); \
		new[0] = tmp;\
	}

	for (; i < 16; i++)
		LOOP_BODY(F)
	for (; i < 32; i++)
		LOOP_BODY(G)
	for (; i < 48; i++)