Merge lp:~akopytov/percona-server/bug1132351 into lp:percona-server/5.5

Proposed by Alexey Kopytov
Status: Merged
Approved by: Sergei Glushchenko
Approved revision: 451
Merged at revision: 457
Proposed branch: lp:~akopytov/percona-server/bug1132351
Merge into: lp:percona-server/5.5
Diff against target: 57 lines (+40/-0)
1 file modified
Percona-Server/include/m_string.h (+40/-0)
To merge this branch: bzr merge lp:~akopytov/percona-server/bug1132351
Reviewer Review Type Date Requested Status
Sergei Glushchenko (community) g2 Approve
Review via email: mp+150230@code.launchpad.net

Description of the change

    Bug #1132351: Suboptimal code in skip_trailing_space()

    Implemented an optimized version of skip_trailing_space() for x86_64
    CPUs which allow unaligned data access and (for recent models) do not
    have any performance penalties for such access.

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) wrote :
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

Approve

review: Approve (g2)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Percona-Server/include/m_string.h'
2--- Percona-Server/include/m_string.h 2012-02-17 09:57:45 +0000
3+++ Percona-Server/include/m_string.h 2013-02-24 15:13:24 +0000
4@@ -263,6 +263,45 @@
5 @return the last non-space character
6 */
7
8+#ifdef __x86_64__
9+
10+#if SIZEOF_LONG != 8
11+# error "SIZEOF_LONG != 8"
12+#endif
13+
14+/* Modern x86_64 CPUs do not have penalties for unaligned access */
15+
16+static inline const uchar *skip_trailing_space(const uchar *ptr, size_t len)
17+{
18+ const uchar *begin;
19+ ulong UNINIT_VAR(val);
20+
21+ if (unlikely(ptr == NULL))
22+ return NULL;
23+
24+ begin= ptr;
25+ ptr= ptr + len - 8;
26+
27+ while (ptr >= begin && (val= (*(ulong *) ptr) ^ 0x2020202020202020) == 0)
28+ ptr-= 8;
29+
30+ if (likely(ptr >= begin))
31+ {
32+ do {
33+ ptr++;
34+ } while (val>>= 8);
35+
36+ return ptr;
37+ }
38+
39+ for (ptr= ptr + 8; ptr > begin && ptr[-1] == 0x20; ptr--)
40+ /* empty */;
41+
42+ return ptr;
43+}
44+
45+#else
46+
47 static inline const uchar *skip_trailing_space(const uchar *ptr,size_t len)
48 {
49 const uchar *end= ptr + len;
50@@ -288,6 +327,7 @@
51 end--;
52 return (end);
53 }
54+#endif
55
56 static inline void lex_string_set(LEX_STRING *lex_str, const char *c_str)
57 {

Subscribers

People subscribed via source and target branches