Skip to content

Commit

Permalink
Improve codegen for address pinning.
Browse files Browse the repository at this point in the history
We avoid one instruction and the memory access.

Instead of generating:

```
leaq   0xb98201(%rip), %rax
movq   %rax, -0x8(%rsp)
```

It now generated just:

```
leaq   0xb981c1(%rip), %rax
```

PiperOrigin-RevId: 589152440
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Dec 8, 2023
1 parent 4955fc4 commit b08e00b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/google/protobuf/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ class MessageLite;

namespace internal {


template <typename T>
void StrongPointer(T* var) {
#if defined(__GNUC__)
asm("" : : "r"(var));
#else
auto volatile unused = var;
(void)&unused; // Use address to avoid an extra load of "unused".
#endif
}


// See comments on `AllocateAtLeast` for information on size returning new.
struct SizedPtr {
void* p;
Expand Down

0 comments on commit b08e00b

Please sign in to comment.