Skip to content

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

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

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

Conversation

@cobaltgit

@cobaltgit cobaltgit commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

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)

@Un1q32 Un1q32 Jun 7, 2026

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.

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

@Un1q32

Un1q32 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

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
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