folly icon indicating copy to clipboard operation
folly copied to clipboard

Swap positions of `ptr` and `extra` in PackedSyncPtr

Open goldsteinn opened this issue 3 years ago • 3 comments

Summary: Change layout: [63:48][47:0] -> [63:16][ 15:0] [extra][ ptr] -> [ ptr][extra]

Previous PackedSyncPtr was organized s.t: [63:48][47:0] [extra][ ptr]

So access pointer required a 48-bit bitmask: data_.getData() & (-1ull >> 16)

This isn't great on x86 because imm operands max out at imm32 so this requires two instructions: 1. movabs + and 2. movl + andn

Either way its almost certainly cheaper to just just a shift which can be done by swap the placements of extra and ptr s.t: [63:16][ 15:0] [ ptr][extra]

As a slightly plus, extra can also be accessed essentially for free with movzwl (which can move-elim).

On aarch64 get() might be slightly more expensive now (and extra() correspondingly cheaper) because lsl is sometimes slightly slower than and.

goldsteinn avatar Dec 10 '22 19:12 goldsteinn

Hi @goldsteinn!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

facebook-github-bot avatar Dec 10 '22 19:12 facebook-github-bot

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot avatar Dec 11 '22 21:12 facebook-github-bot

ping

goldsteinn avatar Dec 28 '22 17:12 goldsteinn

@Orvid has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Jan 03 '23 22:01 facebook-github-bot

@Orvid merged this pull request in facebook/folly@5c4c2530dd85cf2bea6d9b46a3e7613d70160660.

facebook-github-bot avatar Jan 07 '23 00:01 facebook-github-bot