Re: Using CPU flags in C
Florian Weimer via Gcc-help <[email protected]>
| Newsgroups | gmane.comp.gcc.help |
|---|---|
| Message-ID | <[email protected]> |
* jh: > I don't really know where to look for this information. > Is it possible to use the CPU status flags to communicate information > between inline assembly and the normal C control flow? > For example, an asm statement would set the Z flag and then the C code > would jump (for example with beq or bne in the case of ARM) without > using any additional variable and comparison instruction. Using a > dummy variable is no issue if the generated code is just the > conditional branch instruction. Do you mean something like this? commit 119d658ac2aad88e306b4a66c1717e5ebf86c73f Author: Uros Bizjak <[email protected]> Date: Fri Aug 29 09:05:23 2025 +0200 x86: Use flag output operands for inline asm in atomic-machine.h Use the flag output constraints feature available in gcc 6+ ("=@cc<cond>") instead of explicitly setting a boolean variable with SETcc instruction. This approach decouples the instruction that sets the flags from the code that consumes them, allowing the compiler to create better code when working with flags users. Instead of e.g.: lock add %esi,(%rdi) sets %sil test %sil,%sil jne <...> the compiler now generates: lock add %esi,(%rdi) js <...> No functional changes intended. Signed-off-by: Uros Bizjak <[email protected]> Cc: H.J.Lu <[email protected]> Cc: Florian Weimer <[email protected]> Cc: Carlos O'Donell <[email protected]> Reviewed-by: Florian Weimer <[email protected]> <https://sourceware.org/cgit/glibc/commit/?id=119d658ac2aad88e306b4a66c1717e5ebf86c73f> Thanks, Florian