1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-21743 Split up SUPER privilege to smaller privileges

This commit is contained in:
Alexander Barkov
2020-02-28 21:59:01 +04:00
parent 91ba789aaf
commit a1e330de5a
82 changed files with 1511 additions and 236 deletions

View File

@@ -25,16 +25,50 @@ C_MODE_START
extern const uchar _my_bits_reverse_table[256];
/*
Find smallest X in 2^X >= value
This can be used to divide a number with value by doing a shift instead
*/
static inline uint my_bit_log2(ulong value)
/*
my_bit_log2_xxx()
In the given value, find the highest bit set,
which is the smallest X that satisfies the condition: (2^X >= value).
Can be used as a reverse operation for (1<<X), to find X.
Examples:
- returns 0 for (1<<0)
- returns 1 for (1<<1)
- returns 2 for (1<<2)
- returns 2 for 3, which has (1<<2) as the highest bit set.
Note, the behaviour of log2(0) is not defined.
Let's return 0 for the input 0, for the code simplicity.
See the 000x branch. It covers both (1<<0) and 0.
*/
static inline CONSTEXPR uint my_bit_log2_hex_digit(uint8 value)
{
uint bit;
for (bit=0 ; value > 1 ; value>>=1, bit++) ;
return bit;
return value & 0x0C ? /*1100*/ (value & 0x08 ? /*1000*/ 3 : /*0100*/ 2) :
/*0010*/ (value & 0x02 ? /*0010*/ 1 : /*000x*/ 0);
}
static inline CONSTEXPR uint my_bit_log2_uint8(uint8 value)
{
return value & 0xF0 ? my_bit_log2_hex_digit(value >> 4) + 4:
my_bit_log2_hex_digit(value);
}
static inline CONSTEXPR uint my_bit_log2_uint16(uint16 value)
{
return value & 0xFF00 ? my_bit_log2_uint8((uint8) (value >> 8)) + 8 :
my_bit_log2_uint8((uint8) value);
}
static inline CONSTEXPR uint my_bit_log2_uint32(uint32 value)
{
return value & 0xFFFF0000UL ?
my_bit_log2_uint16((uint16) (value >> 16)) + 16 :
my_bit_log2_uint16((uint16) value);
}
static inline CONSTEXPR uint my_bit_log2_uint64(ulonglong value)
{
return value & 0xFFFFFFFF00000000ULL ?
my_bit_log2_uint32((uint32) (value >> 32)) + 32 :
my_bit_log2_uint32((uint32) value);
}