0
Commit Graph

21 Commits

Author SHA1 Message Date
Alex Attar
764f74690c Replace IsPowerOfTwo with std::has_single_bit.
This CL replaces the deprecated IsPowerOfTwo function with the
std::has_single_bit function from the C++20 standard library.

Bug: 40256225
Change-Id: I7541ab0caad4ae6c14670dd7ad000e42d28edc7e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6070097
Commit-Queue: Alex Attar <aattar@google.com>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1392263}
2024-12-05 14:46:15 +00:00
Avi Drissman
c73aa5d213 Remove base::bits::IsPowerOfTwo
Replace all uses with std::has_single_bit.

Bug: 1414634
Change-Id: Ibda2a6c7788cdb99f550ba8b49ecf8522ed02c5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5038430
Commit-Queue: Avi Drissman <avi@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1234558}
2023-12-07 17:24:22 +00:00
Avi Drissman
db766e5b91 Use concepts to clean base/bits.h, require unsigned types
In preparation for the migration to <bit>, require unsigned types, and
use concepts to clean things up. Provide a "deprecated do not use"
version of the functions for code that has yet to be cleaned up.

Bypasses the presubmit because it needs to refer to a banned type
(though it does not use it).

NOPRESUBMIT=true

Bug: 1414634
Change-Id: I5b9ea3c9e9023499669a141d9aa522e0fe21d129
Low-Coverage-Reason: LARGE_SCALE_REFACTOR Renaming and migration of other people’s code
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5041522
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1230243}
2023-11-28 22:40:29 +00:00
Avi Drissman
6f303a54c5 Remove bit counting functions
Uses of CountLeadingZeroBits and CountTrailingZeroBits have been
updated to use std:: functions, so remove those functions.

Bug: 1414634
Change-Id: I2b2a1f901b6f132be842f15501dd6a7750645dbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5028837
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1226098}
2023-11-17 15:09:58 +00:00
Lei Zhang
ce16fc06f9 Stop using CHAR_BIT in base::LeftmostBit()
Since there are always 8 bits in a byte, just use the value of 8 instead
of the CHAR_BIT constant. CHAR_BIT can potentially be a value other than
8.

Also make the same change to the PartitionAlloc version of
LeftmostBit(), and fix a typo in the unit test for LeftmostBit().

Change-Id: Ic70502feda6288cfa63acb5ae1794b342a39cdeb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4649469
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Olivier Li <olivierli@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1163049}
2023-06-27 17:11:29 +00:00
Avi Drissman
e4622aaecc Update copyright headers in base/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c34.

An earlier version of this CL, https://crrev.com/c/3879904,
was reverted due to an issue that was resolved with
https://crrev.com/c/3881211.

No-Try: true
Bug: 1098010
Change-Id: Ibd6ffb97e66835bc299fe7b85876c3e2927b2345
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3883841
Auto-Submit: Avi Drissman <avi@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044747}
2022-09-08 20:36:06 +00:00
Daniel Cheng
3d1108defc Revert "Update copyright headers in base/"
This reverts commit eccb7e8107.

Reason for revert: https://crbug.com/1361092

Original change's description:
> Update copyright headers in base/
>
> The methodology used to generate this CL is documented in
> https://crbug.com/1098010#c21.
>
> No-Try: true
> Bug: 1098010
> Change-Id: Icd01cc1648eab4b0550afcff2bee17076359a132
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3879904
> Owners-Override: Avi Drissman <avi@chromium.org>
> Commit-Queue: Avi Drissman <avi@chromium.org>
> Auto-Submit: Avi Drissman <avi@chromium.org>
> Reviewed-by: Mark Mentovai <mark@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1044191}

Bug: 1098010
Change-Id: Iefdde85d3d44fabe09906cd725b39a4e0b359491
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3880811
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044252}
2022-09-07 23:42:04 +00:00
Avi Drissman
eccb7e8107 Update copyright headers in base/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c21.

No-Try: true
Bug: 1098010
Change-Id: Icd01cc1648eab4b0550afcff2bee17076359a132
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3879904
Owners-Override: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044191}
2022-09-07 21:26:21 +00:00
Peter Kasting
6a4bf14c6c Prevent unsafe narrowing: base/ for Android
Bug: 1292951
Change-Id: I7cd54513a8c55b8a011997707edd925b935091f5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3752744
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1023727}
2022-07-13 14:53:33 +00:00
Peter Kasting
0aa10873fc Prevent unsafe narrowing: base/bits*
* Switch CLZ and similar functions to returning int, which matches what
  the similar STL functions do in C++20
* Remove unnecessary wrappers

Bug: 1292951
Change-Id: I5d4e187c468630fa5bfc7c05d2cff1f9104acbc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3668914
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1009170}
2022-05-31 18:04:03 +00:00
Benoit Lize
c90419f6bf [base] bits::Align() -> bits::AlignUp().
to the new call. The old one is still there, as there are many callers
across the codebase.

bits: :Align() is confusing, and not uniform (the opposite is called
bits: :AlignDown()). Make naming consistent, and convert base/allocator
Change-Id: I7f94e9a41665107c109bc120bca56232d1f5cbd5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550796
Commit-Queue: Benoit L <lizeb@chromium.org>
Reviewed-by: Chris Palmer <palmer@chromium.org>
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#849665}
2021-02-02 18:04:25 +00:00
Mike Wittman
668debf823 Add bits::Align functions for pointers
Supports alignment of pointers without forcing users to employ the
casts required to use the existing functions. Enables only for pointers
to 1 byte types (e.g. uint8_t/char) to avoid ambiguity about whether
alignment is measured in bytes or sizeof of the pointed-to type.

Updates code to use the new functions.

Change-Id: If196122876c7e753b3faaa116fdf1874d8cf1db9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2300342
Commit-Queue: Mike Wittman <wittman@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Wan-Teh Chang <wtc@google.com>
Reviewed-by: vmpstr <vmpstr@chromium.org>
Auto-Submit: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792136}
2020-07-28 03:10:30 +00:00
OlivierLi
02b94c5905 Introduce the bits::LeftmostBit<T> function.
This avoid having to type 1 << (numbits_ - 1) in several places which
can make code harder to read and can be typo prone. This function can
also be used within another template.

Change-Id: I46af3ab832bb58a6565702a391db028b2a69807f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2222526
Commit-Queue: Oliver Li <olivierli@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#773344}
2020-05-29 21:30:56 +00:00
Lei Zhang
0c01026d0c Add base::bits::AlignDown().
Like base::bits::Align(), but rounds down instead. Replace duplicate
implementations.

Change-Id: I7ad74d021feba26a34f2c80bc025e9ab9fe6660a
Reviewed-on: https://chromium-review.googlesource.com/c/1369047
Reviewed-by: vmpstr <vmpstr@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615610}
2018-12-11 18:56:09 +00:00
Vlad Tsyrklevich
5d2331ff7f Implement base::bits functions for MSVC 32-bit targets
Currently, base::bits::Count{Leading,Trailing}ZeroBits fail to link
when used with 64-bit inputs on 32-bit MSVC builds because MSVC only
implements the _BitScan{Forward,Reverse}64 intrinsics for 64-bit
builds. Fix this by implementing equivalent support using 32-bit
intrinsics.

Change-Id: I9b9095abd03587c29dd642df65cf9783bd9b202d
Reviewed-on: https://chromium-review.googlesource.com/c/1321253
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Commit-Queue: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607887}
2018-11-14 03:33:03 +00:00
Michael Lippautz
b6d0db428b [base] Add bits::IsPowerOfTwo
Adds helper for computing whether a number is power of two.

Change-Id: Ifd7e01ec1aad644fd9c6ac78600edd013076c9fb
Reviewed-on: https://chromium-review.googlesource.com/1065960
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560988}
2018-05-23 07:19:42 +00:00
Michael Lippautz
e8b6bdc031 [base] Add templatized CountLeadingZeroBits/CountTrailingZeroBits
Bug: chromium:757440
Change-Id: I59f77f644a900f5fa1480867eb8be22b35bd3ad8
Reviewed-on: https://chromium-review.googlesource.com/758415
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Michael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515947}
2017-11-13 15:34:35 +00:00
Chris Palmer
79df70945a Move wtf/BitwiseOperations.h into base/bits.h.
Part of the plan for WTF, and supports the PartitionAllocator move as well.

BUG=632441
R=dcheng@chromium.org, esprehn@chromium.org

Review URL: https://codereview.chromium.org/2512593002 .

Cr-Commit-Position: refs/heads/master@{#433301}
2016-11-18 21:27:12 +00:00
avi
9b6f42934e Switch to standard integer types in base/.
BUG=138542
TBR=mark@chromium.org
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1538743002

Cr-Commit-Position: refs/heads/master@{#366910}
2015-12-26 22:16:15 +00:00
primiano
32a7f50559 Align base::Pickle allocations to 4k boundaries
Currently the growth logic of base::Pickle (the one that kicks
in exceeding the current capacity when writing) is as follows:
new_payload_capacity = current_payload_capacity * 2
with an initial payload capacity of 64 bytes.

However, the size of the heap held by Pickle (the one which gets
realloc-ated on each growth) is:
payload_capacity + header_size (typically 4-20 bytes).

In practice, this means that when the Pickle is expanded, the
size of its underlying heap becomes a power of two plus some extra.
This causes funky behaviors of realloc, which makes extremely
difficult to estimate the size of a pickle (for the sake of
memory profiling, Pickle is used to store TracedValue(s)).

This CL adds a small adjustment to the Pickle growth strategy,
making the underlying realloc sizes close to a full page size.
This in turn makes the realloc behavior much more predictable.

As a bonus this CL refactors the use of "Align", moving it to
base/bits.h

BUG=512383

Review URL: https://codereview.chromium.org/1249643007

Cr-Commit-Position: refs/heads/master@{#340318}
2015-07-24 20:14:12 +00:00
apatrick@google.com
6d1729ee95 Moved bits.h from O3D to Chrome base.
TEST=none
BUG=none

Review URL: http://codereview.chromium.org/373001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32428 0039d316-1c4b-4281-b951-d872f2087c98
2009-11-18 23:08:39 +00:00