Skip to content

Make spin-waiting a little more power efficient on desktop#202

Open
cobaltgit wants to merge 7 commits into
ButterscotchRunner:mainfrom
cobaltgit:desktop-spinwait
Open

Make spin-waiting a little more power efficient on desktop#202
cobaltgit wants to merge 7 commits into
ButterscotchRunner:mainfrom
cobaltgit:desktop-spinwait

Conversation

@cobaltgit
Copy link
Copy Markdown
Contributor

@cobaltgit cobaltgit commented Jun 7, 2026

Supports x86, ARMv7+, RISC-V GCC/Clang/MSVC, otherwise falls back to a no-op.

Uses the pause/yield instruction to stop busy-looping from using CPU while waiting for the next frame to begin

Comment thread src/common.h Outdated
#include <intrin.h>
#define YIELD() __yield()
#elif defined(__aarch64__) || (defined(__arm__) && defined(__ARM_ARCH) && (__ARM_ARCH >= 7))
#if defined(__GNUC__) && (__GNUC__ < 5)
Copy link
Copy Markdown
Contributor

@Un1q32 Un1q32 Jun 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang appears to have this too, clang does define __GNUC__ but it pretends to be GCC 4.2.1

@Un1q32
Copy link
Copy Markdown
Contributor

Un1q32 commented Jun 7, 2026

Intrinsics are not standard C, so you should put the whole YIELD block behind an #ifdef __GNUC__, with a fallback to make it a no-op.

Comment thread src/common.h Outdated
Comment thread src/common.h
#include <immintrin.h>
#define YIELD() _mm_pause()
#endif
#elif defined(_M_ARM64) || defined(_M_ARM)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this MSVC? If so make the #ifdef __GNUC__ into #if defined(__GNUC__) and add an #elif defined(_MSC_VER) that this can go into.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also move out the x86 MSVC path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants