[all-commits] [llvm/llvm-project] d78ca7: [libc++] Fix the rotate direction used in countl_z...

Armando Martín via All-commits all-commits at lists.llvm.org
Tue Sep 12 15:20:19 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d78ca7324c88a2658492f722222cc8c1eb4ace71
      https://github.com/llvm/llvm-project/commit/d78ca7324c88a2658492f722222cc8c1eb4ace71
  Author: Armando Martín <delta.deltadev.127 at gmail.com>
  Date:   2023-09-12 (Tue, 12 Sep 2023)

  Changed paths:
    M libcxx/include/__bit/countl.h
    M libcxx/include/__bit/rotate.h

  Log Message:
  -----------
  [libc++] Fix the rotate direction used in countl_zero()

This "bug" was probably not noticed because it doesn't affect any integer
type we currently support. It requires integers with more than 2x the
size of `unsigned long long`. However, with such types, the algorithm
used to break down the large integer into groups of size `unsigned long long`
didn't work because we rotated in the wrong direction.

For example, the 256 bit number (1 << 255) would yield the wrong answer
when used with the algorithm before this patch.

In particular, note that the current rotation happens to work for 128 bit
integers because it just swaps the halves in this case.

Differential Revision: https://reviews.llvm.org/D134625
Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>




More information about the All-commits mailing list