Skip to content

Commit

Permalink
count_bits() moved to mysys/
Browse files Browse the repository at this point in the history
--BZR--
revision-id: [email protected]
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:[email protected]|include/my_sys.h|20030504164305|534147:file_id56:BK|include/my_sys.h|19700101030959|00100|e1481e080cea69aed9:commit_id51:[email protected]|mysys/my_bit.c|20030504164305|402627:file_id74:[email protected]|mysys/my_bit.c|20011002025259|20145|cfa03cf37b5d3d60ed9:commit_id53:[email protected]|sql/item_func.cc|20030504164305|382917:file_id57:BK|sql/item_func.cc|19700101030959|01728|17497c71c268c9d4ee
testament3-sha1: 160bbdb71efd684cd6d32ce3b5708699c38f91fc
  • Loading branch information
[email protected] committed May 4, 2003
1 parent e1d1c30 commit 9b5db98
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 43 deletions.
1 change: 1 addition & 0 deletions include/my_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
42 changes: 42 additions & 0 deletions mysys/my_bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

45 changes: 2 additions & 43 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}


Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9b5db98

Please sign in to comment.