[MDEV-21981] Replace arithmetic + with bitwise OR when possible Created: 2020-03-19 Updated: 2020-03-31 Resolved: 2020-03-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Server, Storage Engine - Aria, Storage Engine - MyISAM |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.2.32, 10.3.23, 10.4.13, 10.5.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Marko Mäkelä | Assignee: | Marko Mäkelä |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | performance | ||
| Issue Links: |
|
||||||||
| Description |
|
Several macros such as sint2korr() and uint4korr() are using the arithmetic + operator while a bitwise or operator would suffice. GCC 5 and later, as well as clang 5 and later can detect patterns consisting of bitwise or and shifts by multiples of 8 bits, such as those used in the InnoDB function mach_read_from_4(). They actually translate that verbose low-level code into high-level machine language (i486 bswap instruction or fuse it into the Haswell movbe instruction). We should do the same for MariaDB Server code that is outside InnoDB. Note: The Microsoft C compiler is lacking this optimization. There, we might consider using _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64(). But, those would be unaligned reads, which are bad for reasons stated in MDEV-20277, and besides, outside InnoDB, most data is already being stored in the native little-endian format of that compiler. |
| Comments |
| Comment by Michael Widenius [ 2020-03-19 ] |
|
Note that in MyISAM and Aria, all integers, floats, doubles and record pointers index are stored in high-byte-first order for fast byte-by-byte comparison. I am all good to change our current macros in: byte_order_generic.h to use | instead of + |