From 9b5db98984de9cd16de02f996cb5b6837d1ca797 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" Date: Sun, 4 May 2003 18:43:07 +0200 Subject: [PATCH] count_bits() moved to mysys/ --BZR-- revision-id: sp1r-serg@serg.mylan-20030504164307-50437 property-file-info: ld7:file_id61:sp1f-my_sys.h-19700101030959-lyllvna5vzqfcjnmlcrutgqocylhtb547:message29:count_bits() moved to mysys/ property-file-info: 4:path16:include/my_sys.hed7:file_id61:sp1f-my_bit.c-20011002025259-hm5ohs3amppmwowrn2xe4bha3huzjgb27:message29:count_bits() moved to mysys/ property-file-info: 4:path14:mysys/my_bit.ced7:file_id65:sp1f-item_func.cc-19700101030959-3wmsx76yvc25sroqpfrx2n77kqdxxn3y7:message29:count_bits() moved to mysys/ property-file-info: 4:path16:sql/item_func.ccee property-sp1-file-info: ld9:commit_id53:serg@serg.mylan|include/my_sys.h|20030504164305|534147:file_id56:BK|include/my_sys.h|19700101030959|00100|e1481e080cea69aed9:commit_id51:serg@serg.mylan|mysys/my_bit.c|20030504164305|402627:file_id74:monty@hundin.mysql.fi|mysys/my_bit.c|20011002025259|20145|cfa03cf37b5d3d60ed9:commit_id53:serg@serg.mylan|sql/item_func.cc|20030504164305|382917:file_id57:BK|sql/item_func.cc|19700101030959|01728|17497c71c268c9d4ee testament3-sha1: 160bbdb71efd684cd6d32ce3b5708699c38f91fc --- include/my_sys.h | 1 + mysys/my_bit.c | 42 ++++++++++++++++++++++++++++++++++++++++++ sql/item_func.cc | 45 ++------------------------------------------- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/include/my_sys.h b/include/my_sys.h index c67a150f24f..603b3bad6bd 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -749,6 +749,7 @@ extern my_bool my_uncompress(byte *, ulong *, ulong *); extern byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen); extern ulong checksum(const byte *mem, uint count); extern uint my_bit_log2(ulong value); +uint my_count_bits(ulonglong v); extern void my_sleep(ulong m_seconds); #ifdef __WIN__ diff --git a/mysys/my_bit.c b/mysys/my_bit.c index 0ff487afe03..55dd72f5f76 100644 --- a/mysys/my_bit.c +++ b/mysys/my_bit.c @@ -29,3 +29,45 @@ uint my_bit_log2(ulong value) for (bit=0 ; value > 1 ; value>>=1, bit++) ; return bit; } + +static char nbits[256] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, +}; + +uint my_count_bits(ulonglong v) +{ +#if SIZEOF_LONG_LONG > 4 + /* The following code is a bit faster on 16 bit machines than if we would + only shift v */ + ulong v2=(ulong) (v >> 32); + return (uint) (uchar) (nbits[(uchar) v] + + nbits[(uchar) (v >> 8)] + + nbits[(uchar) (v >> 16)] + + nbits[(uchar) (v >> 24)] + + nbits[(uchar) (v2)] + + nbits[(uchar) (v2 >> 8)] + + nbits[(uchar) (v2 >> 16)] + + nbits[(uchar) (v2 >> 24)]); +#else + return (uint) (uchar) (nbits[(uchar) v] + + nbits[(uchar) (v >> 8)] + + nbits[(uchar) (v >> 16)] + + nbits[(uchar) (v >> 24)]); +#endif +} + diff --git a/sql/item_func.cc b/sql/item_func.cc index 6c23b0aa424..532a7cedec0 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1110,47 +1110,6 @@ longlong Item_func_find_in_set::val_int() return 0; } -static char nbits[256] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8, -}; - -uint count_bits(ulonglong v) -{ -#if SIZEOF_LONG_LONG > 4 - /* The following code is a bit faster on 16 bit machines than if we would - only shift v */ - ulong v2=(ulong) (v >> 32); - return (uint) (uchar) (nbits[(uchar) v] + - nbits[(uchar) (v >> 8)] + - nbits[(uchar) (v >> 16)] + - nbits[(uchar) (v >> 24)] + - nbits[(uchar) (v2)] + - nbits[(uchar) (v2 >> 8)] + - nbits[(uchar) (v2 >> 16)] + - nbits[(uchar) (v2 >> 24)]); -#else - return (uint) (uchar) (nbits[(uchar) v] + - nbits[(uchar) (v >> 8)] + - nbits[(uchar) (v >> 16)] + - nbits[(uchar) (v >> 24)]); -#endif -} - longlong Item_func_bit_count::val_int() { ulonglong value= (ulonglong) args[0]->val_int(); @@ -1159,7 +1118,7 @@ longlong Item_func_bit_count::val_int() null_value=1; /* purecov: inspected */ return 0; /* purecov: inspected */ } - return (longlong) count_bits(value); + return (longlong) my_count_bits(value); } @@ -2221,7 +2180,7 @@ bool Item_func_match::fix_fields(THD *thd,struct st_table_list *tlist) used_tables_cache|=item->used_tables(); } /* check that all columns come from the same table */ - if (count_bits(used_tables_cache) != 1) + if (my_count_bits(used_tables_cache) != 1) key=NO_SUCH_KEY; const_item_cache=0; table=((Item_field *)fields.head())->field->table;