1
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
get_ptr_compare(len) returns a pointer to a optimal byte-compare function
18
for a array of stringpointer where all strings have size len.
19
The bytes are compare as unsigned chars.
22
#include "mysys_priv.h"
23
#include <myisampack.h>
27
* On Solaris, memcmp() is normally faster than the unrolled ptr_compare_N
28
* functions, as memcmp() is usually a platform-specific implementation
29
* written in assembler, provided in /usr/lib/libc/libc_hwcap*.so.1.
30
* This implementation is also usually faster than the built-in memcmp
31
* supplied by GCC, so it is recommended to build with "-fno-builtin-memcmp"
32
* in CFLAGS if building with GCC on Solaris.
37
static int native_compare(size_t *length, unsigned char **a, unsigned char **b)
39
return memcmp(*a, *b, *length);
44
static int ptr_compare(size_t *compare_length, uchar **a, uchar **b);
45
static int ptr_compare_0(size_t *compare_length, uchar **a, uchar **b);
46
static int ptr_compare_1(size_t *compare_length, uchar **a, uchar **b);
47
static int ptr_compare_2(size_t *compare_length, uchar **a, uchar **b);
48
static int ptr_compare_3(size_t *compare_length, uchar **a, uchar **b);
51
/* Get a pointer to a optimal byte-compare function for a given size */
54
qsort2_cmp get_ptr_compare (size_t size __attribute__((unused)))
56
return (qsort2_cmp) native_compare;
59
qsort2_cmp get_ptr_compare (size_t size)
62
return (qsort2_cmp) ptr_compare;
64
case 0: return (qsort2_cmp) ptr_compare_0;
65
case 1: return (qsort2_cmp) ptr_compare_1;
66
case 2: return (qsort2_cmp) ptr_compare_2;
67
case 3: return (qsort2_cmp) ptr_compare_3;
69
return 0; /* Impossible */
75
Compare to keys to see witch is smaller.
76
Loop unrolled to make it quick !!
79
#define cmp(N) if (first[N] != last[N]) return (int) first[N] - (int) last[N]
83
static int ptr_compare(size_t *compare_length, uchar **a, uchar **b)
85
reg3 int length= *compare_length;
86
reg1 uchar *first,*last;
91
if (*first++ != *last++)
92
return (int) first[-1] - (int) last[-1];
94
return (int) first[0] - (int) last[0];
98
static int ptr_compare_0(size_t *compare_length,uchar **a, uchar **b)
100
reg3 int length= *compare_length;
101
reg1 uchar *first,*last;
119
static int ptr_compare_1(size_t *compare_length,uchar **a, uchar **b)
121
reg3 int length= *compare_length-1;
122
reg1 uchar *first,*last;
124
first= *a+1; last= *b+1;
140
static int ptr_compare_2(size_t *compare_length,uchar **a, uchar **b)
142
reg3 int length= *compare_length-2;
143
reg1 uchar *first,*last;
145
first= *a +2 ; last= *b +2;
162
static int ptr_compare_3(size_t *compare_length,uchar **a, uchar **b)
164
reg3 int length= *compare_length-3;
165
reg1 uchar *first,*last;
167
first= *a +3 ; last= *b +3;
187
void my_store_ptr(uchar *buff, size_t pack_length, my_off_t pos)
189
switch (pack_length) {
191
case 8: mi_int8store(buff,pos); break;
192
case 7: mi_int7store(buff,pos); break;
193
case 6: mi_int6store(buff,pos); break;
194
case 5: mi_int5store(buff,pos); break;
196
case 4: mi_int4store(buff,pos); break;
197
case 3: mi_int3store(buff,pos); break;
198
case 2: mi_int2store(buff,pos); break;
199
case 1: buff[0]= (uchar) pos; break;
200
default: DBUG_ASSERT(0);
205
my_off_t my_get_ptr(uchar *ptr, size_t pack_length)
208
switch (pack_length) {
210
case 8: pos= (my_off_t) mi_uint8korr(ptr); break;
211
case 7: pos= (my_off_t) mi_uint7korr(ptr); break;
212
case 6: pos= (my_off_t) mi_uint6korr(ptr); break;
213
case 5: pos= (my_off_t) mi_uint5korr(ptr); break;
215
case 4: pos= (my_off_t) mi_uint4korr(ptr); break;
216
case 3: pos= (my_off_t) mi_uint3korr(ptr); break;
217
case 2: pos= (my_off_t) mi_uint2korr(ptr); break;
218
case 1: pos= (my_off_t) *(uchar*) ptr; break;
219
default: DBUG_ASSERT(0); return 0;