Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-21981

Replace arithmetic + with bitwise OR when possible

    XMLWordPrintable

    Details

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              marko Marko Mäkelä
              Reporter:
              marko Marko Mäkelä
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: