Commit graph

163 commits

Author SHA1 Message Date
David Given 25b6712e63 Rework all the ackbuilder scripts not to use wildcards, because we can't expand
them without luaposix, which isn't available (easily) on OSX or Windows.
2022-07-14 23:57:54 +02:00
George Koehler 1faff418ec Teach some ncg machines to use .data8
This turns EM `con 5000000000I8` into assembly `.data8 5000000000` for
machines i386, i80, i86, m68020, powerpc, vc4.  These are the only ncg
machines in our build.

i80 and i86 get con_mult(sz) for sz == 4 and sz == 8.  The other
machines only get sz == 8, because they have 4-byte words, and ncg
only calls con_mult(sz) when sz is greater than the word size.  The
tab "\t" after .data4 or .data8 is like the tabs in the con_*() macros
of mach/*/ncg/mach.h.

i86 now uses .data4, like i80.  Also, i86 and i386 now use the numeric
string without converting it to an integer and back to a string.
2019-08-13 15:37:05 -04:00
David Given 97e6baa052 Fix register corruption when incrementing locals; attempt to solve the
alignment issue.
2019-06-17 23:31:54 +02:00
David Given 3798673afe
Merge pull request #186 from ccodere/carl-ansi-part1
Carl ansi part1
2019-06-15 12:09:41 +02:00
David Given 3feb79ad0c Simplify the .trp API to make it a bit smaller. 2019-06-11 20:02:03 +02:00
carl 9bb69bbb98 Fix several compiler warnings by adding braces 2019-05-14 23:21:19 +08:00
David Given 88fd7b3cdc Add a 'kill' pseudoinstruction to the 8080 assembler, which marks when the code
generator is finished with a register; use this to create some more effective
peephole optimiser rules.
2019-03-08 23:06:34 +01:00
David Given 12a0421988 Minor improvements to the way types are expanded (should avoid embarassing ands
with 0xff).
2019-02-17 10:09:22 +01:00
David Given 61d623c4d6 Add a few minor top optimisations. 2019-02-16 01:18:31 +01:00
David Given 6a8b298861 Fix typo where I was confusing sbi and sui, with hilarious results. 2019-02-16 01:18:21 +01:00
David Given 4474d6433a Loading large constants now computes the stack offset correctly. 2019-02-15 23:03:01 +01:00
David Given 34c67698ef Generate the proper function prologues for big stack frames. 2019-02-15 23:01:33 +01:00
David Given 8ca4d6ea1e Cleanup. 2019-02-15 22:26:14 +01:00
David Given c9467b683a Add rules for converting smallnconst2 and smallpconst2 to registers, to stop
the conversion from happening via the stack. Star Trek goes from 39450 to 39384
bytes.
2019-02-15 22:20:07 +01:00
David Given afd45acb89 Using regpair instead of hl_or_de is not, in fact, safe until we've stopped
using bc.
2019-02-15 21:38:17 +01:00
David Given d63a359a49 Fix nearly all the comparisons, a lot of which were broken. Using a rst for
unsigned comparisons is surprisingly not that useful due to marshalling
overhead; it's only four bytes to do inline (plus jc), or six for a constant.
Also add some useful top optimisations.  Star Trek goes from 39890 to 39450
bytes.
2019-02-15 21:30:27 +01:00
David Given 91c75f81b5 Call cmps rather than cmpu for bge... make cmps and cmpu rsts. Apply various
other tiny optimisations.
2019-02-15 00:38:39 +01:00
David Given 2924ce8ffa Use nicely optimised helper tools to do signed comparisons of words. Star Trek
goes from 40452 to 39890 bytes.
2019-02-14 23:57:55 +01:00
David Given 3c3d2a4520 Fix bad helper tool invocation for inl with faddrn. 2019-02-14 23:21:47 +01:00
David Given 8eaa11ac72 Turns out that every time the compiler tried to do a stack retraction with asp,
it would flush registers onto the stack. This stops it doing this. Star Trek
goes from 40779 to 40452 bytes.
2019-02-14 00:05:08 +01:00
David Given 6e3ba8e9a0 Merge from default. 2019-02-13 22:46:00 +01:00
David Given 79a38ecc08 Instead of using parameterised rsts for stack access, add a huge swathe of
automatically built helper tools. Star Trek goes up from 40243 to 40779 bytes,
but should be a lot faster.
2019-02-13 22:45:22 +01:00
David Given 8200f041c2 Fix issue with logical operations and small signed constants which turned out
to affect multiple platforms.
2019-02-13 20:56:10 +01:00
David Given f4b45f1ed7 Fix bad code generation due to not correctly flushing the stack before
comparisons.
2019-02-12 22:19:07 +01:00
David Given 360e1525ae Replace the non-working Z80 style signed comparison sign adjustment with
something which actually works on the 8080. Sadly, Star Trek is up to
40243 bytes again.
2019-02-12 11:57:37 +01:00
David Given e8994afdf0 Apply Alan Cox's patch to add the 8085 extended instructions to the i80
assembler.
2019-02-11 21:14:35 +01:00
David Given f1b128baeb Signed comparisons now work correctly; sadly, Star Trek increases from 39656 to
39726 bytes. Note that the emulator doesn't set P/V correctly and all the tests
fail. Testing in z80ex works fine.
2019-02-11 20:46:06 +01:00
David Given fca54ccc1b Improve subtractions, using dad and inline constants where possible. Shrinks
Star Trek from 39740 to 39656 bytes.
2019-02-10 19:40:48 +01:00
David Given 7d34cd7407 Simplify simple comparisons and use inlie constants where possible. Reduces
Star Trek from 39771 to 39740 bytes.
2019-02-10 19:22:43 +01:00
David Given 35d1f36ca4 Use pop rather than inx;inx to retract the stack; consumes a register but
halves the number of calls. Reduces Star Trek from 39976 to 39771 bytes.
2019-02-10 18:57:20 +01:00
David Given b34ff2bdec Teach the i80 code generator how to do left shifts by using dad hl; prevents it
from calling out to .sli2 for simple shifts. Shrinks Star Trek from 40055 bytes
to 39976.
2019-02-10 18:44:47 +01:00
David Given 10b509d6b6 Add rst 3 to get the address of a frame variable; lots of rule overhaulage.
Reduces Star Trek from 41821 to 41055 bytes.
2019-02-09 13:29:41 +01:00
David Given 0de5001f82 Make sign extension much less horrible. 2019-02-08 23:16:57 +01:00
David Given 0ac145a0d1 Add tests for simple and, or, and xor; drastically improve the i80 code
generation for these.
2019-02-08 22:38:07 +01:00
David Given a91ab5c599 Somehow the implementation of rst 2 got lost, with hilarious results. Also fix
some register corruption issues (I hope).
2019-02-08 21:35:14 +01:00
David Given d319c7d679 Fix swapped bytes in probyte which was causing junk stack frames. 2019-02-08 08:09:55 +01:00
David Given a5bf2932c8 Add rst 1 to store frame variables. Reduces Star Trek from 42339 to 41821
bytes.
2019-02-07 09:31:38 +01:00
David Given 67a9be26d1 Fix warnings. 2019-02-07 09:09:31 +01:00
David Given 9d8ea79c7f rst 1 now takes an eight-bit parameter, not a 16 bit one. Reduces Star Trek
again from 43205 to 42339 bytes.
2019-02-07 08:45:20 +01:00
David Given 5ac280026e Experimentally use rst 1 to optimise frame variable loads. Reduces Star Trek
from 43892 to 43205 bytes.
2019-02-07 00:06:32 +01:00
David Given 08b92153a0 Use a helper function for cai --- only saves two bytes per invocation, but is
much less embarassing.
2019-02-06 20:36:23 +01:00
David Given 2b0629f87f Common out boilerplate function prologue code; shrinks Star Trek from 44256 to
43892 bytes.
2019-02-06 16:06:07 +01:00
David Given b77f616598 Run through clang-format before editing. 2019-02-06 11:50:05 +01:00
David Given 02779325ab Move the standard ret boilerplate into a helper procedure, to save a little
space.
2019-02-06 08:08:11 +01:00
George Koehler 93e01eb5d1 Teach i80 ncg to use libfp. Enable ack -mcpm -fp.
Old .o files stop working if they use floating point.  One must
recompile those files.  Old files don't call libfp in the correct way,
and may use symbols that I removed from libem.  I don't keep old
symbols in libem/flp.s, because a program that pulls both libfp and
flp.s would get "multiply defined" errors in the linker.

I teach mach/i80/ncg/table to use libfp by copying or adapting the
patterns from mach/i86/ncg/table.  I did not test all the patterns,
but I did use `ack -mcpm -fp -O4` to compile examples/mandelbrot.c,
then I ran it in the emulator YAZE-AG.  It worked, but it was slow.
2018-04-25 16:09:56 -04:00
George Koehler a1d1f38691 Add test for EM rol, ror. Fix i80, i86, powerpc.
EM instructions _rol_ and _ror_ do rotate an integer left or right.
Our compilers and optimizers never emit _rol_ nor _ror_, but I might
want to use them in the future.

Add _rol_ and _ror_ to powerpc.  Fix `rol 4` and `ror 4` in both i80
and i86, where the rules for `rol 4` and `ror 4` seem to have never
been tested until now.
2017-12-07 17:16:21 -05:00
George Koehler c95bcac91d Correct the stack pointer when i80 shrinks an integer.
The code used `sphl` to set the stack pointer, but the correct value
was in de, not hl.  Fix by swapping the values of de and hl, so `sphl`
is now correct.  When we shrink an integer from 4 to 2 bytes, both
registers de and hl point to copies of the result, but only one
register preserves the stack below the result.

This fixes writehex() in tests/plat/lib/test.c, when I compile it with
ack -mcpm, so it preserves the pointer to "0123456789abcdef", so it
writes hexadecimal digits and not garbage.

This bug goes back to commit 157b243 of Mar 18, 1985, so the bug is
32 years old, and probably the oldest bug that I ever fixed.
2017-12-07 15:39:41 -05:00
George Koehler 34cf0c8b63 Kill registers a, de, when i80 ncg does Call libem.
I compiled tests/plat/lib/test.c with ack -mcpm, but i80 ncg did emit
wrong code in writehex(uint32_t) for

    "0123456789abcdef"[code & 0xf]

The code called '.and' to evaluate `code & 0xf`, then tried to call
'.cii' to narrow the result from 4 to 2 bytes, but it passed garbage
instead of 4 to '.cii'.  The rule for '.and' was

    pat and defined($1)
    kills ALL
    uses dereg={const2,$1}
    gen Call {label,".and"}

This failed to kill register de={const2,4}, so ncg pushed de,
expecting to push 4, but actually pushing garbage.

Fix such rules using `mvi a,...` or `lxi de,...` so ncg doesn't track
the token in the register.  This is like the i86 table.  A different
fix would use a dummy instruction `killreg a` or `killreg de` like the
m68020 table.

Also correct 1 to $1 when calling '.exg'.
2017-12-06 22:14:00 -05:00
George Koehler 5301cceee3 Declare machine-dependent functions in mach/proto/ncg
This breaks all machines because the declared return type void
disagrees with the implicit return type int (when I compile mach.c
with clang).  Unbreak i386, i80, i86, m68020, powerpc, vc4 by adding
the return types to mach.c.  We don't build any other machines; they
are broken since commit a46ee91 (May 19, 2013) declared void prolog()
and commit fd91851 (Nov 10, 2016) declared void mes(), with both
declarations in mach/proto/ncg/fillem.c.

Also fix mach/vc4/ncg/mach.c where type full is long, so fprintf()
must use "%ld" not "%d" to print full nlocals.
2017-11-13 14:23:44 -05:00
David Given e3f8fb84dc Change the i80 assembler to be three-pass, which allows forward references;
required for assembling B.
2016-12-29 17:08:53 +00:00