Go to file
Quentin Carbonneaux 577b4667db negated conditions rework
Floating point comparisons are subtle due to
unordered operands (i.e., when one or two of
the operands are nans).

In amd64 we arrange post isel to make sure we
only have comparisons that will return false
on unordered operands and for which we have a
negated version (returning true on unordered
operands).  I made this situation a bit more
explicit by marking unexpected comparisons
with "?" in amd64/emit.c.

In arm64, the instruction set is rich enough
to have a negated version for all operators
that returns true on unordered inputs. So we
build a backend specific table.

I made sure to remove cmpneg() from utils.c;
it is a footgun as it does not work well for
floating point ops because of the 'unordered'
edge case.

I found the ARM docs about condition codes
pretty bad; the following C program is a
good substitute:

    #include <stdio.h>
    int
    flags(float a, float b)
    {
    	int z, c, n, v, le;
    	__asm__(
    		"fcmpe %s5, %s6\n"
    		"\tcset %0, eq\n"
    		"\tcset %1, mi\n"
    		"\tcset %2, cs\n"
    		"\tcset %3, vs\n"
    		"\tcset %4, le\n"
    	: "=r"(z),"=r"(n),"=r"(c),"=r"(v),"=r"(le)
    	: "x"(a), "x"(b)
    	: "cc");
    	printf(
    		"cmp(%g,%g): z=%d n=%d c=%d v=%d le=%d\n",
    		a, b, z, n, c, v, le);
    }
    int
    main()
    {
    	flags(1.0, 1.0);
    	flags(0.0, 1.0);
    	flags(1.0, 0.0);
    	flags(0.0, 0.0/0.0);
    	flags(0.0/0.0, 0.0);
    }

Compile & run with:

    aarch64-linux-gnu-gcc -static -no-pie flags.c
    qemu-aarch64 ./a.out
2026-04-29 17:45:20 +02:00
amd64 negated conditions rework 2026-04-29 17:45:20 +02:00
arm64 negated conditions rework 2026-04-29 17:45:20 +02:00
doc Implementation of Windows amd64_win target 2026-02-12 09:17:17 +01:00
minic minic: C23 doesn't allow bool as identifier 2025-03-16 11:27:49 +01:00
rv64 If-conversion RFC 4 - x86 only (for now), use cmovXX 2026-01-13 18:11:30 +01:00
test formatting fixes in tests 2026-02-12 09:23:13 +01:00
tools Implementation of Windows amd64_win target 2026-02-12 09:17:17 +01:00
.gitignore Global Value Numbering / Global Code Motion 2025-03-14 09:58:37 +01:00
abi.c add new target-specific abi0 pass 2022-10-03 10:41:03 +02:00
alias.c fix bug in alias analysis 2024-03-07 16:40:51 +01:00
all.h negated conditions rework 2026-04-29 17:45:20 +02:00
cfg.c fix typo in simplcfg 2026-01-13 20:36:23 +01:00
copy.c fix exponential complexity in usewidthle() 2026-04-21 13:25:00 +02:00
emit.c fix float neg on mach-o 2026-04-25 18:51:46 +02:00
fold.c gvn/gcm review 2025-03-14 13:09:21 +01:00
gcm.c gvn/gcm review 2025-03-14 13:09:21 +01:00
gvn.c remove unused variable 2026-02-28 19:05:15 +01:00
ifopt.c If-conversion RFC 4 - x86 only (for now), use cmovXX 2026-01-13 18:11:30 +01:00
LICENSE update copyright years 2026-01-13 17:09:41 +01:00
live.c refine assertion in liveness analysis 2022-06-14 09:11:44 +02:00
load.c gvn/gcm review 2025-03-14 13:09:21 +01:00
main.c update debug flag list for gvn/gcm 2026-04-27 10:08:45 +02:00
Makefile Implementation of Windows amd64_win target 2026-02-12 09:17:17 +01:00
mem.c relax one assert 2024-06-05 12:50:36 +02:00
ops.h ifopt simplifications 2026-01-13 18:11:37 +01:00
parse.c parse: deny non-digit after minus in getint 2026-02-28 19:05:57 +01:00
README 10 years of qbe! 2025-03-14 13:09:42 +01:00
rega.c idup(Ins **, Ins *, ulong) -> idup(Blk *, Ins *, ulong) 2025-03-14 09:47:05 +01:00
simpl.c idup(Ins **, Ins *, ulong) -> idup(Blk *, Ins *, ulong) 2025-03-14 09:47:05 +01:00
spill.c fix jmp arg spilling 2026-01-13 17:09:41 +01:00
ssa.c gvn/gcm review 2025-03-14 13:09:21 +01:00
util.c negated conditions rework 2026-04-29 17:45:20 +02:00

QBE - Backend Compiler              http://c9x.me/compile/

doc/    Documentation.
minic/  An example C frontend for QBE.
tools/  Miscellaneous tools (testing).
test/   Tests.
amd64/
arm64/
rv64/   Architecture-specific code.

The LICENSE file applies to all files distributed.

- Compilation and Installation

Invoke make in this directory to create the executable
file qbe.  Install using 'make install', the standard
DESTDIR and PREFIX environment variables are supported.
Alternatively, you may simply copy the qbe binary.