Commit graph

2663 commits

Author SHA1 Message Date
George Koehler f6a1e08218 Test long long division and remainder; fix i386.
My i386 code from 893df4b gave the wrong sign to some 8-byte
remainders.  Fix by splitting .dvi8 and .rmi8 so each has its own code
to pick the sign.  They and .dvu8 and .rmu8 share a private sub
.divrem8 for unsigned division.

Improve the i386 code by using instructions like _bsr_ and _shrd_.
Change the helpers to yield a quotient in ebx:eax or a remainder in
ecx:edx; this seems more convenient, because _div_ puts its quotient
in eax and remainder in edx.
2019-09-16 20:19:36 -04:00
George Koehler 04427e65dc Add and test rol 8, ror 8 for linux386.
These tests are in core/rotate_e.e with the other rotation tests, and
only run on platforms where _EM_LLSIZE == 8.
2019-09-12 19:47:51 -04:00
George Koehler fb9f5387b5 Add long long comparisons, shifts for linux386.
Add tests for comparisons and shifts.  Also add enough integer
conversions to compile the shift test (llshift_e.c), and disable
some wrong rules for ldc and conversions.
2019-09-07 16:20:33 -04:00
George Koehler 893df4b79b Experiment with 8-byte integers in ncg i386.
This provides adi, sbi, mli, dvi, rmi, ngi, dvu, rmu 8, but is missing
shifts and rotates.  It is also missing conversions between 8-byte
integers and other sizes of integers or floats.  The code might not be
all correct, but works at least some of the time.

I adapted this from how ncg i86 does 4-byte integers, but I use a
different algorithm when dividing by a large value: i86 avoids the div
instruction and uses a shift-and-subtract loop; but I use the div
instruction to estimate a quotient, which is more like how big integer
libraries do division.  My .dvi8 and .dvu8 also set ecx:ebx to the
remainder; this might be a bad idea, because it requires .dvi8 and
.dvu8 to always calculate the remainder, even when the caller only
wants the quotient.

To play with 8-byte integers, I wrote EM procedures like

     mes 2, 4, 4
     exp $ngi
     pro $ngi,0
     ldl 4
     ngi 8
     lol 0
     sti 8
     lol 0
     ret 4
     end
     exp $adi
     pro $adi,0
     ldl 4
     ldl 12
     adi 8
     lol 0
     sti 8
     lol 0
     ret 4
     end

and called them from C like

    typedef struct { int l; int h; } q;
    q ngi(q);
    q adi(q, q);
2019-08-20 13:38:18 -04: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
George Koehler 054b9c87e1 Add .data8 for 8-byte literal integers to the assembler.
This takes literal integers, not expressions, because each machine
defines its own valu_t for expressions, but valu_t can be too narrow
for an 8-byte integer, and I don't want to change all the machines to
use a wider valu_t.  Instead, change how the assembler parses literal
integers.  Remove the NUMBER token and add a NUMBER8 token for an
int64_t.  The new .data8 pseudo emits all 8 bytes of the int64_t;
expressions narrow the int64_t to a valu_t.  Don't add any checks for
integer overflow; expressions and .data* pseudos continue to ignore
overflow when a number is too wide.

This commit requires int64_t and uint64_t in the C compiler to build
the assembler.  The ACK's own C compiler doesn't have these.

For the assembler's temporary file, add NUMBER4 to store 4-byte
integers.  NUMBER4 acts like NUMBER[0-3] and only stores a
non-negative integer.  Each negative integer now takes 8 bytes (up
from 4) in the temporary file.

Move the `\fI` and `\fP` in the uni_ass(6) manual, so the square
brackets in `thing [, thing]*` are not italic.  This looks nicer in my
terminal, where italic text is underlined.
2019-08-13 11:47:44 -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 94867d24b7 Ensure that procedure labels are word aligned (required by the EM spec). 2019-06-17 22:26:31 +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
carl de45c1036d ANSI C conversion 2019-05-11 01:11:54 +08:00
carl 708c1ba1b0 ANSI C conversion 2019-05-11 01:11:26 +08:00
carl e6ba8034f0 ANSI C conversion 2019-05-11 01:11:17 +08:00
carl cefebdb5db ANSI C conversion 2019-05-11 01:11:03 +08:00
carl 628dcb3cbf ANSI C conversion 2019-05-11 01:10:47 +08:00
carl 04cb629159 ANSI C conversion 2019-05-11 01:10:12 +08:00
carl 8d6cfa7701 Fix possible buffer writer overflow 2019-03-31 01:14:49 +08:00
carl 4f2c482416 Buffer overflow memory errors. 2019-03-31 00:52:37 +08:00
carl 41fd51eeea Revert change. 2019-03-25 01:41:04 +08:00
carl efecff78b9 Add function prototypes. 2019-03-25 00:14:38 +08:00
carl 9979fb37d2 Add function prototypes. 2019-03-25 00:14:27 +08:00
carl 82cdc096b0 Add function prototypes. 2019-03-25 00:14:08 +08:00
carl f161a5867d Add function prototypes. 2019-03-25 00:13:56 +08:00
carl a6120c220e Fix buffer overflow issue. 2019-03-25 00:13:42 +08:00
carl dcc2be5e8c Add function prototypes. 2019-03-25 00:12:21 +08:00
carl 5295049b16 Add function prototypes. 2019-03-25 00:12:07 +08:00
carl 1636b9b52d Add function prototypes. 2019-03-25 00:11:55 +08:00
carl 180d3388d6 Add function prototypes. 2019-03-25 00:11:43 +08:00
carl 98c5d1f0ee Add function prototypes. 2019-03-25 00:11:31 +08:00
carl ef3a6b3cc4 Add function prototypes. 2019-03-25 00:11:19 +08:00
carl 053c509fc9 Add function prototypes. 2019-03-25 00:10:58 +08:00
carl 2f84fc92cf Add function prototypes. 2019-03-25 00:10:45 +08:00
carl 2dd0d0f81b Add function prototypes. 2019-03-25 00:10:32 +08:00
carl 143da61d13 Add function prototypes. 2019-03-25 00:10:20 +08:00
carl dac3d0b10c Add function prototypes. 2019-03-25 00:10:10 +08:00
George Koehler bec236c108 Include more headers to declare functions.
This causes clang to give fewer warnings of implicit declarations of
functions.

In mach/pdp/cv/cv.c, rename wr_int2() to cv_int2() because it
conflicts with wr_int2() in <object.h>.

In util/ack, rename F_OK to F_TRANSFORM because it conflicts with F_OK
for access() in <unistd.h>.
2019-03-22 15:59:35 -04: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