Commit graph

1395 commits

Author SHA1 Message Date
sam
78e209820f Update all.h 2024-10-29 22:56:53 +13:00
sam
c403479279 Merge branch 'merge' 2024-10-29 22:50:30 +13:00
sam
a5741ed125 add extra functions and clean up makefile and readme 2024-10-29 22:41:07 +13:00
Quentin Carbonneaux
90050202f5 fix various codegen bugs on arm64
- dynamic allocations could generate
  bad 'and' instructions (for the
  and with -16 in salloc()).
- symbols used in w context would
  generate adrp and add instructions
  on wN registers while they seem to
  only work on xN registers.

Thanks to Rosie for reporting them.
2024-10-01 19:42:50 +02:00
Quentin Carbonneaux
626f0b2781 skip preludes for some leaf fns
When rbp is not necessary to compile
a leaf function, we skip saving and
restoring it.
2024-08-23 18:31:53 +02:00
Alexey Yerin
bb8de8c633 arm64/isel: Avoid signed overflow when handling immediates
Clang incorrectly optimizes this negation with -O2 and causes QBE to
emit 0 in place of INT64_MIN.
2024-08-15 23:21:05 +02:00
Quentin Carbonneaux
efcb5465e5 align emitted code
Functions are now aligned on 16-byte
boundaries. This mimics gcc and should
help reduce the maximum perf impact of
cosmetic code changes. Previously, any
change in the output of qbe could have
far reaching implications on alignment.

Thanks to Roland Paterson-Jones for
pointing out the variability issue.
2024-08-15 23:11:41 +02:00
sam
d2f4528797 switch to tmpfile so it works on musl 2024-07-24 21:01:29 +12:00
sam
e154997862 fix dep on config.h 2024-07-24 20:41:38 +12:00
sam
8a91f9a249 turn qbe into an embeddable library 2024-07-24 20:30:53 +12:00
Quentin Carbonneaux
e8fa27bcdb drop imul rewriting
This was cute to do, but it is
largely inconsequential, as shown
by the rough timings below:

    benchmarking mul8_lea
      3.9 ticks ± 0.88 (min: 3)
    benchmarking mul8_imul
      3.3 ticks ± 0.27 (min: 3)
    benchmarking div8_udiv
      6.5 ticks ± 0.52 (min: 6)
    benchmarking div8_shr
      3.3 ticks ± 0.34 (min: 3)
2024-06-19 12:39:26 +02:00
Quentin Carbonneaux
7de34d3454 no mul->shl as it confuses address matching
Additionally, the strength-reduction
for small powers of two is handled
by amd64/emit.c now.
2024-06-19 10:58:17 +02:00
Quentin Carbonneaux
6dab93b4b2 cheaper mul by small constants on amd64 2024-06-18 17:06:56 +02:00
Quentin Carbonneaux
96f18be71d simplify 8*x as well as x*8 2024-06-18 16:59:42 +02:00
Quentin Carbonneaux
0631bc4fec prevent bogus simplifications 2024-06-17 13:24:22 +02:00
Quentin Carbonneaux
e7ebdc8fb6 qbe has its own magic 2024-06-17 13:17:39 +02:00
Quentin Carbonneaux
b5be429091 fix unintended assignment 2024-06-16 22:31:38 +02:00
Quentin Carbonneaux
ddf5ced4a7 revert 4bc4c958
Hopefully the right time now!
2024-06-16 22:26:51 +02:00
Roland Paterson-Jones
7a19de5cf4 Simplify int mul/udiv/urem of 2^N into shl/shr/and.
Passes the "standard" test suite.

(cproc bootstrap, hare[c] make test, roland units, linpack/coremark run)

However linpack benchmark is now notably slower. Coremark is ~2% faster.

As noticed before, linmark timing is dubious, and maybe my cheap (AMD) laptop
prefers mul to shl.
2024-06-16 21:42:17 +02:00
Roland Paterson-Jones
cf9f95f521 Optab-driven copy detection 2024-06-09 22:33:38 +02:00
Quentin Carbonneaux
2c2051542b relax one assert
In this branch we only need that br[b->loop].b
is defined. This is the case if b->loop >= n.
2024-06-05 12:50:36 +02:00
Erica Z
c8220b638b replace asm keyword
when applying a custom set of CFLAGS under clang that does not include
-std=c99, asm is treated as a keyword and as such can not be used as an
identifier. this prevents the issue by renaming the offending variables.
2024-05-28 10:39:41 +02:00
Quentin Carbonneaux
620277c004 add width info for comparisons
Comparisons return a 1-bit value, in theory
we could add a Wu1 width for them but I did
not bother and just used Wub. This simply
means that if a frontend generates an extsb
of a comparison result (silly), we will not
generate good code.
2024-05-03 21:51:30 +02:00
Quentin Carbonneaux
1dd22a9b47 function params must be unique 2024-04-27 10:52:03 +02:00
Quentin Carbonneaux
b24af7d3f7 revert 1b7770e271
Quotes are used on Apple target
variants to flag that we must
not add the _ symbol prefix.
2024-04-22 14:01:50 +02:00
Michael Forney
99169df2ff parse: use dynamically sized hashtable for temporaries
This significantly improves parsing performance for massive functions
with a huge number of temporaries. Parsing the 86MiB IL produced
by cproc during zig bootstrap drops from 17m15s to 2.5s (over 400x
speedup).

The speedup is much smaller for IL produced from normal non-autogenerated
C code. Parsing the sqlite3 amalgamation drops from 0.40s to 0.33s.
2024-04-13 13:31:02 +02:00
Quentin Carbonneaux
fc98435f81 add "make wc" 2024-04-12 11:49:00 +02:00
Quentin Carbonneaux
875c1abf93 drop unnecessary check 2024-04-12 11:37:35 +02:00
Quentin Carbonneaux
8ded7a56a2 add common linkage for data 2024-04-12 11:33:58 +02:00
Quentin Carbonneaux
4a809d69b5 fold scaled offsets in addresses 2024-04-11 14:14:53 +02:00
Quentin Carbonneaux
8e8f706436 drop over-zealous offset accumulation 2024-04-11 10:22:46 +02:00
Quentin Carbonneaux
2d046a0ac6 use mgen in amd64/isel.c 2024-04-09 21:47:16 +02:00
Quentin Carbonneaux
a609527752 mgen: match automatons and C generation
The algorithm to generate matchers
took a long time to be discovered
and refined to its present version.
The rest of mgen is mostly boring
engineering.

Extensive fuzzing ensures that the
two core components of mgen (tables
and matchers generation) are correct
on specific problem instances.
2024-04-09 21:45:42 +02:00
Quentin Carbonneaux
56e2263ca4 fuse ac rules in ins-tree matching
The initial plan was to have one
matcher per ac-variant, but that
leads to way too much generated
code. Instead, we can fuse ac
variants of the rules and have
a smarter matching algorithm to
recover bound variables.
2024-04-09 21:34:57 +02:00
Quentin Carbonneaux
8a5e1c3a23 does not look too good 2024-04-09 21:34:57 +02:00
Quentin Carbonneaux
a374da3c2e modulo ac matching and more tests 2024-04-09 21:32:49 +02:00
Quentin Carbonneaux
24d1324424 wip ins-tree matcher 2024-04-09 21:32:49 +02:00
Quentin Carbonneaux
a2ad38086c mcf's improved rsval()
It is semantically the same but
does not rely on implementation-
defined behavior.
2024-04-07 22:18:01 +02:00
Quentin Carbonneaux
dc3f7d7c4a fix accidentally noop loop
Credit goes to Roland Paterson-Jones
for spotting this bug.
2024-04-04 21:56:50 +02:00
Quentin Carbonneaux
de5ced474d do not parse +N constants
The parsing code for these constants
conflicts with the Tplus token.
2024-04-03 23:30:07 +02:00
Richard McCormack
c8fc20b8ef Eliminate fully overlapping blits after coalescing stack slots
I noticed that my compiler was generating redundant blits, and after
looking through the QBE debug output I believe that I found some low
hanging fruit to help clean them up.

I'm new to this codebase, so please treat this patch with a lot of
skepticism. Happy to make any changes.

Thanks for reviewing, and thank you for QBE!
2024-04-03 22:12:36 +02:00
Michael Forney
85827e2232 check that data alignment is in range and a power of two
Otherwise, the alignment gets truncated to fit in char, so
`align 256` is handled as no alignment requirement.
2024-03-28 10:35:11 +01:00
Michael Forney
1b7770e271 Drop quotes around floating point constant labels
This is incompatible with binutils gas older than 2.26.
2024-03-26 09:22:06 +01:00
Nguyễn Gia Phong
be5d46fe7d test/fpcnv: skip of inexactly converted integers
In C, if a floating point cannot be represented exactly as an integer,
conversion from the former to the latter is implementation-defined.
Therefore, it can be flaky to test this against QBE-defined behavior.

This was discovered from (unsigned int) 4294967295.0f being an UB,
because (uint64_t) 4294967295.0f is 4294967296 > UINT_MAX
on amd64 when compiled by either gcc or clang.
2024-03-07 16:52:43 +01:00
Nguyễn Gia Phong
b582e84e10 remove duplicated function declarations
References: 12f9d16c7b ("create cfg.c for cfg-related functions")
2024-03-07 16:46:10 +01:00
Quentin Carbonneaux
9ee57a637a update copyright years 2024-03-07 16:45:22 +01:00
Nguyễn Gia Phong
190fd3fb09 declare check-rv64 as a phony make target
References: 4e93eeaa3b ("add rv64 backend")
2024-03-07 16:44:48 +01:00
Quentin Carbonneaux
bd7a73d0ea fix bug in alias analysis
The handling of phi was incorrect
and we would sometimes miss escapes.
We now handle phis at the very end
of the pass to make sure the defs
for their arguments have all been
processed.
2024-03-07 16:40:51 +01:00
Tobias Heider
2d683e0c53 Print total number of tests run to get a better view of how much is broken. 2024-01-29 10:24:41 +01:00
Quentin Carbonneaux
1f69842fb8 fix link in doc 2024-01-03 12:12:41 +01:00