Seems to me the loop has been unrolled a bit to increase performance.
From: [email protected]
[mailto:[email protected]] On Behalf Of Victor Surfer
Sent: Tuesday, June 19, 2012 9:21 PM
To: [email protected]
Subject: [android-porting] Why memcmp is like this in bionic?
Hello,
I found memcmp.c in bionic is like this:
30 int memcmp(const void *s1, const void *s2, size_t n)
31 {
32 const unsigned char* p1 = s1;
33 const unsigned char* end1 = p1 + n;
34 const unsigned char* p2 = s2;
35 int d = 0;
36
37 for (;;) {
38 if (d || p1 >= end1) break;
39 d = (int)*p1++ - (int)*p2++;
40
41 if (d || p1 >= end1) break;
42 d = (int)*p1++ - (int)*p2++;
43
44 if (d || p1 >= end1) break;
45 d = (int)*p1++ - (int)*p2++;
46
47 if (d || p1 >= end1) break;
48 d = (int)*p1++ - (int)*p2++;
49 }
50 return d;
51 }
In the for loop, the same logic repeats 4 times, why? Can it no repeat?
Thx,
Victor
--
unsubscribe:
[email protected]<mailto:[email protected]>
website: http://groups.google.com/group/android-porting
ATTENTION: This e-mail contains confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and delete this message and any
attachments immediately. Any unauthorized copying, disclosure or distribution
of the material in this e-mail is strictly forbidden.
--
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting