ack.git
7 years agoWrite README files for osx386 and osxppc.
George Koehler [Sat, 3 Dec 2016 22:17:44 +0000 (17:17 -0500)]
Write README files for osx386 and osxppc.

7 years agoRemove bad overflow check from plat/osx/libsys/brk.c
George Koehler [Sat, 3 Dec 2016 22:07:51 +0000 (17:07 -0500)]
Remove bad overflow check from plat/osx/libsys/brk.c

If I want to check for overflow, then I should check it before I do
base + incr, not after.

Now that I have no check, I am passing the overflowed base + incr to
brk1(), where it will probably fail the nbreak < segment check.

7 years agoWrite a manual page for cvmach(6).
George Koehler [Fri, 2 Dec 2016 23:04:06 +0000 (18:04 -0500)]
Write a manual page for cvmach(6).

This manual is in the new mdoc(7) format.  All existing ack manuals
use the old man(7) format.  This might be a problem if someone can't
display mdoc(7) files.

The build system doesn't install the cvmach(6) manual; that might
happen later.  The current build system installs manuals in two
different places, and doesn't install some manuals, so I don't know
what to do.

7 years agoWrite a powerpc.descr for ego and use it with osxppc.
George Koehler [Wed, 30 Nov 2016 20:29:19 +0000 (15:29 -0500)]
Write a powerpc.descr for ego and use it with osxppc.

No change to linuxppc and qemuppc.  They continue to run ego without
any descr file.

I copied m68020.descr to powerpc.descr and changed some numbers.  My
numbers are guesses; I know little about PowerPC cycle counts, and
almost nothing about ego.  This powerpc.descr causes most of the
example programs to shrink in size (without descr -> with descr):

  65429 -> 57237  hilo_b.osxppc        -8192
  36516 -> 32420  hilo_c.osxppc        -4096
  55782 -> 51686  hilo_mod.osxppc      -4096
  20096 -> 20096  hilo_p.osxppc            0
   8813 ->  8813  mandelbrot_c.osxppc      0
  93355 -> 89259  paranoia_c.osxppc    -4096
  92751 -> 84559  startrek_c.osxppc    -8192

(Each file has 2 Mach segments, then a symbol table.  Each segment
takes a multiple of 4096 bytes.  When the code shrinks, we lose a
multiple of 4096 bytes.)

I used "ack -mosxppc -O6 -c.so" to examine the assembly code for
hilo.mod and mandelbrot.c, both without and with descr.  This reveals
optimizations made only with descr, from 2 ego phases: SP (stack
pollution) and RA (register allocation).  In hilo.mod, SP deletes some
instructions that remove items from the stack.  These items get
removed when the function returns.  In both hilo.mod and mandelbrot.c,
RA moves some values into local variables, so ncg can make them into
register variables.  This shrinks code size, probably because register
variables get preserved across function calls.  More values stay in
registers, and ncg emits shorter code.

I believe that the ego descr file uses (time,space) tuples but the ncg
table uses (space,time) tuples.  This is confusing.  Perhaps I am
wrong, and some or all tuples are backwards.  My time values are the
cycle counts in latency from the MPC7450 Reference Manual (but not
including complications like "store serialization").

In powerpc.descr, I give the cost for saving and restoring registers
as if I was using chains of stw and lwz instructions.  Actually ncg
uses single stmw and lmw instructions with at least 2 instructions.
The (time,space) for stmw and lmw would be much less than the
(time,space) for chains of stw and lwz.  But this ignores the pipeline
of the MPC7450.  The chains of stw and lwz may run faster than stmw
and lmw in the pipeline, because the throughput may be better than the
latency.  By using the wrong values for (time,space), I'm trying to
tell ego that stmw and lmw are not better than chains of stw and lwz.

7 years agoDeclare raise() for Mac OS X.
George Koehler [Wed, 30 Nov 2016 19:33:40 +0000 (14:33 -0500)]
Declare raise() for Mac OS X.

This prevents the warning, "implicit declaration of function raise",
in programs that call raise().  I forgot to declare it because the
function raise() is in libc but the declaration goes in libsys.

7 years agoEnable top and make other tweaks in plat/osxppc/descr
George Koehler [Tue, 29 Nov 2016 01:58:51 +0000 (20:58 -0500)]
Enable top and make other tweaks in plat/osxppc/descr

David Given made top for PowerPC.  Copy the asopt phase (running top)
from linuxppc to osxppc.

Remove CC_ALIGN=-Vr to become compatible with Apple's gcc.  Apple uses
left adjustment for bitfields; the first bitfield is on the left side
(the big end), not the right side.

Remove unused variables C_LIB and OLD_C_LIB; the file libc-ansi.a
doesn't exist.

Change MACHOPT_F from -m10 to -m3.  This means to use no more than 3
adds and shifts to optimize a multiply by a constant.  I pick -m3
because -m4 can use too many instructions.  At -m4, the compiler
rewrites

    n * 14

as

    s = n << 1
    (s << 3) + (0 - s)

This means (n * 16 - n * 2), but even at ack -O6, the compiler doesn't
rewrite (a + (0 - b)) as (a - b).  The compiler emits 5 instructions:
2 of rlinmw for 2 left shifts, then addi to load 0 in a register, subf
to subtract from that 0, then add.  These 5 instructions cost 5 cycles
on the MPC7450, using the cycle counts from mach/powerpc/ncg/table.

At -m3, (n * 14) becomes 2 instructions: addi to load 14 in a register
and mullw to multiply.  This also costs 5 cycles (because mullw costs
4 cycles), but uses less space.

7 years agoMerge branch 'default' into kernigh-osx
George Koehler [Mon, 28 Nov 2016 21:20:56 +0000 (16:20 -0500)]
Merge branch 'default' into kernigh-osx

This brings in David Given's PowerPC changes, including the addition
of the modern code generator (mcg) for PowerPC.

Resolve minor conflicts in top build.lua and util/led/main.c

7 years agoAdd getdirentries() and stat() for Mac OS X.
George Koehler [Mon, 28 Nov 2016 19:32:49 +0000 (14:32 -0500)]
Add getdirentries() and stat() for Mac OS X.

Also add fstat() and lstat().  I don't #define the constants for
st_mode or d_type, but I provide enough to get the block size of a
file and to list the names in a directory.  Some fields of struct stat
get truncated, see XXX in plat/osx/include/sys/stat.h.

In struct dirent, the inode field might be d_ino or d_fileno.  I
picked d_ino because Apple's sys/dirent.h uses d_ino (but Apple's
manual pages use d_fileno).

7 years agoSuppress spurious message when testdriver probes for a testing method.
David Given [Sat, 26 Nov 2016 20:50:56 +0000 (21:50 +0100)]
Suppress spurious message when testdriver probes for a testing method.

7 years agoUpdated the README.
David Given [Sat, 26 Nov 2016 18:25:02 +0000 (19:25 +0100)]
Updated the README.

7 years agoMerge pull request #17 from davidgiven/dtrg-tests
David Given [Sat, 26 Nov 2016 11:59:13 +0000 (12:59 +0100)]
Merge pull request #17 from davidgiven/dtrg-tests

Refactor the tests so they run for several plats.

7 years agoUse command -v rather than hash to detect commands (command is Posix and works
David Given [Sat, 26 Nov 2016 11:53:36 +0000 (12:53 +0100)]
Use command -v rather than hash to detect commands (command is Posix and works
on OpenBSD).

7 years agoOSX doesn't work; let's not bother building it.
David Given [Sat, 26 Nov 2016 11:52:09 +0000 (12:52 +0100)]
OSX doesn't work; let's not bother building it.

7 years agoPlats which use aelflod need to depend on it.
David Given [Sat, 26 Nov 2016 11:07:08 +0000 (12:07 +0100)]
Plats which use aelflod need to depend on it.

7 years agoqmu-system-x86 isn't in Travis' repository? Let's try qemu-user.
David Given [Sat, 26 Nov 2016 11:00:59 +0000 (12:00 +0100)]
qmu-system-x86 isn't in Travis' repository? Let's try qemu-user.

7 years agoEnable tests for linux386 via qemu-i386.
David Given [Sat, 26 Nov 2016 10:58:02 +0000 (11:58 +0100)]
Enable tests for linux386 via qemu-i386.

7 years agoEnable tests for linuxppc via qemu-ppc.
David Given [Sat, 26 Nov 2016 10:56:17 +0000 (11:56 +0100)]
Enable tests for linuxppc via qemu-ppc.

7 years agoTravis only whitelists the -x86 version of qemu.
David Given [Sat, 26 Nov 2016 10:29:57 +0000 (11:29 +0100)]
Travis only whitelists the -x86 version of qemu.

7 years agoRework the tests to run on pc86; lots of test fixes for the brk() test, which
David Given [Sat, 26 Nov 2016 10:23:25 +0000 (11:23 +0100)]
Rework the tests to run on pc86; lots of test fixes for the brk() test, which
was nearly useless; lots of fixes to qemuppc and pc86 sbrk(), which was broken;
change the pc86 console to echo output to the serial port (needed for running
tests on qemu).

7 years agoRefactored the tests to make the generic across different plats.
David Given [Fri, 25 Nov 2016 20:02:51 +0000 (21:02 +0100)]
Refactored the tests to make the generic across different plats.

7 years agoMake pc86 echo console output to the serial port, so qemu can pipe it to
David Given [Fri, 25 Nov 2016 19:28:41 +0000 (20:28 +0100)]
Make pc86 echo console output to the serial port, so qemu can pipe it to
stdout.

7 years agoAnsify Paranoia, because I was getting annoyed by all the compiler warnings on
David Given [Fri, 25 Nov 2016 19:01:43 +0000 (20:01 +0100)]
Ansify Paranoia, because I was getting annoyed by all the compiler warnings on
every build.

7 years agoMerge pull request #16 from davidgiven/dtrg-pascal-mark-release
David Given [Thu, 24 Nov 2016 19:45:14 +0000 (20:45 +0100)]
Merge pull request #16 from davidgiven/dtrg-pascal-mark-release

Remove the Mark() and Release() procedures from Pascal.

7 years agoRemove the Mark() and Release() procedures from the Pascal compiler and
David Given [Thu, 24 Nov 2016 19:35:26 +0000 (20:35 +0100)]
Remove the Mark() and Release() procedures from the Pascal compiler and
standard library, because they never worked and come from an achingly old
version of the Pascal specification. Fix the implementations of New() and
Dispose() to use the standard C memory allocator rather than rolling their own
(also in C). Write test!

7 years agoForgot to check in the change to qemuppc's brk() to set errno on memory
David Given [Thu, 24 Nov 2016 18:47:11 +0000 (19:47 +0100)]
Forgot to check in the change to qemuppc's brk() to set errno on memory
allocation failure.

7 years agoMerge pull request #15 from davidgiven/dtrg-allocs
David Given [Wed, 23 Nov 2016 21:35:50 +0000 (22:35 +0100)]
Merge pull request #15 from davidgiven/dtrg-allocs

Fix various memory allocation bugs.

7 years agoAdd a test for brk() and sbrk().
David Given [Wed, 23 Nov 2016 21:28:21 +0000 (22:28 +0100)]
Add a test for brk() and sbrk().

7 years agoAdd a test for calloc().
David Given [Wed, 23 Nov 2016 21:22:04 +0000 (22:22 +0100)]
Add a test for calloc().

7 years agoImplement calloc() (accidentally got dropped with the malloc rewrite).
David Given [Wed, 23 Nov 2016 21:16:25 +0000 (22:16 +0100)]
Implement calloc() (accidentally got dropped with the malloc rewrite).

7 years agoChange sbrk() to take an int rather than an intptr_t (following the OpenBSD way
David Given [Wed, 23 Nov 2016 21:06:24 +0000 (22:06 +0100)]
Change sbrk() to take an int rather than an intptr_t (following the OpenBSD way
rather than the Linux way; various non-C bits of the ACK assume it takes an
int, so it's cleaner).

7 years agoCombine brk() with sbrk(); modify brk() to update the sbrk(0) value.
David Given [Wed, 23 Nov 2016 21:04:21 +0000 (22:04 +0100)]
Combine brk() with sbrk(); modify brk() to update the sbrk(0) value.

7 years agoMerge pull request #14 from davidgiven/dtrg-experimental-mcgg
David Given [Wed, 23 Nov 2016 20:58:31 +0000 (21:58 +0100)]
Merge pull request #14 from davidgiven/dtrg-experimental-mcgg

Merge mcg code generator to trunk

7 years agoDon't install qemu-system-ppc until openbios-ppc gets whitelisted by Travis.
David Given [Wed, 23 Nov 2016 20:53:14 +0000 (21:53 +0100)]
Don't install qemu-system-ppc until openbios-ppc gets whitelisted by Travis.

7 years agoMake working gettimeofday() for Mac OS X.
George Koehler [Wed, 23 Nov 2016 18:25:55 +0000 (13:25 -0500)]
Make working gettimeofday() for Mac OS X.

The system call puts the time in a pair of registers, not in the
timeval structure.  Add code to move the time to the structure, so
programs see the correct time, not garbage.  This fixes our example
programs that use the time as a random seed.

7 years agoTeach cvmach to emit the symbol table.
George Koehler [Tue, 22 Nov 2016 22:16:30 +0000 (17:16 -0500)]
Teach cvmach to emit the symbol table.

This preserves the name and value of every symbol.  The type and other
info of a symbol might be lost.  In gdb, one can now "disas main" or
"disas '.ret'" to disassemble functions by name.

Most symbols are in sections, so I also teach cvmach to emit the Mach
section headers.  The entry point in plat/osx*/descr moves down to
make room for the section headers and LC_SYMTAB.

I fix some bugs in calculations of cvmach.  They were wrong if ROM had
a greater alignment than TEXT, or if DATA did not start on a page
boundary.  I introduce machseg[] to simplify the mess of variables in
main().  I declare most functions as static.  Also, cvmach becomes the
first program to #include <object.h>.

7 years agoMake possible to #include <object.h>.
George Koehler [Tue, 22 Nov 2016 16:13:14 +0000 (11:13 -0500)]
Make possible to #include <object.h>.

This header declares functions in libobject.  Our programs never
included object.h, but called functions in libobject without declaring
them.  So, our build system never put object.h in the include path;
any #include <object.h> would fail to find the header.

With this commit, a program may #include <object.h> if it has
modules/src/object+lib in its deps.

Declare structs in object.h so we can use them in prototypes without
gcc warning, "'struct whatever' declared inside parameter list".

Remove inclusion of ansi.h from object.h.  Programs would need to
depend on modules+headers to get ansi.h in the include path.

7 years agoAlso call .trp .trap, for ncg compatibility.
David Given [Sun, 20 Nov 2016 18:39:28 +0000 (19:39 +0100)]
Also call .trp .trap, for ncg compatibility.

7 years agoinn on ncg now passes the CPU tests.
David Given [Sun, 20 Nov 2016 18:35:34 +0000 (19:35 +0100)]
inn on ncg now passes the CPU tests.

7 years agoFinally fix the build system issue where ackprogram would try to explicitly
David Given [Sun, 20 Nov 2016 17:57:44 +0000 (18:57 +0100)]
Finally fix the build system issue where ackprogram would try to explicitly
link all the language libraries.

7 years agoUse uint32_t in util/led/main.c
George Koehler [Sun, 20 Nov 2016 16:38:16 +0000 (11:38 -0500)]
Use uint32_t in util/led/main.c

This uses uint32_t for the base, file offset, and alignment of each
section, to be consistent with the usage of uint32_t in h/out.h

Also declare setbit() as static.

7 years agoinn works now; add a helper for it.
David Given [Sun, 20 Nov 2016 11:53:44 +0000 (12:53 +0100)]
inn works now; add a helper for it.

7 years agolxa now works, I hope; traps are better (and stubbed out on qemuppc).
David Given [Sun, 20 Nov 2016 10:57:21 +0000 (11:57 +0100)]
lxa now works, I hope; traps are better (and stubbed out on qemuppc).

7 years agoBetter handling of float conversions; more tests; converting to unsigned ints
David Given [Sun, 20 Nov 2016 10:27:40 +0000 (11:27 +0100)]
Better handling of float conversions; more tests; converting to unsigned ints
works now.

7 years agoAdd some more tests.
David Given [Sun, 20 Nov 2016 09:46:53 +0000 (10:46 +0100)]
Add some more tests.

7 years agoNo, sudo doesn't get openbios-ppc installed. I added a whitelisting request:
David Given [Sun, 20 Nov 2016 09:36:30 +0000 (10:36 +0100)]
No, sudo doesn't get openbios-ppc installed. I added a whitelisting request:

https://github.com/travis-ci/apt-package-whitelist/issues/3745

7 years agoNeed sudo to install openbios-ppc.
David Given [Sun, 20 Nov 2016 09:09:58 +0000 (10:09 +0100)]
Need sudo to install openbios-ppc.

7 years agoInstall openbios on Travis (needed by qemu-system-ppc).
David Given [Sun, 20 Nov 2016 09:00:59 +0000 (10:00 +0100)]
Install openbios on Travis (needed by qemu-system-ppc).

7 years agoFix my typo to put symbol "begrom" in correct section.
George Koehler [Sun, 20 Nov 2016 00:23:42 +0000 (19:23 -0500)]
Fix my typo to put symbol "begrom" in correct section.

7 years agocif8 and cuf8 work now. More tests.
David Given [Sat, 19 Nov 2016 10:42:30 +0000 (11:42 +0100)]
cif8 and cuf8 work now. More tests.

7 years agoFloats and doubles are now written out correctly.
David Given [Sat, 19 Nov 2016 10:39:13 +0000 (11:39 +0100)]
Floats and doubles are now written out correctly.

7 years agoUse .hol0 as an additional name for hol0; mcg requires it.
David Given [Sat, 19 Nov 2016 10:09:07 +0000 (11:09 +0100)]
Use .hol0 as an additional name for hol0; mcg requires it.

7 years agoMade csa and csb work with mcg; adjust the libem functions and the
David Given [Sat, 19 Nov 2016 09:55:41 +0000 (10:55 +0100)]
Made csa and csb work with mcg; adjust the libem functions and the
corresponding invocation in the ncg table so the same helpers can be used for
both mcg and ncg. Add a new IR opcode, FARJUMP, which jumps to a helper
function but saves volatile registers.

7 years agoYet another OB1 stack format fix.
David Given [Sat, 19 Nov 2016 09:42:22 +0000 (10:42 +0100)]
Yet another OB1 stack format fix.

7 years agoBetterer timeout handling.
David Given [Thu, 17 Nov 2016 21:04:50 +0000 (22:04 +0100)]
Betterer timeout handling.

7 years agoRemember to push the result of lor onto the stack.
David Given [Thu, 17 Nov 2016 21:04:32 +0000 (22:04 +0100)]
Remember to push the result of lor onto the stack.

7 years agoNow _errsym and _erlsym are defined in the standard library, don't define them
David Given [Wed, 16 Nov 2016 20:13:00 +0000 (21:13 +0100)]
Now _errsym and _erlsym are defined in the standard library, don't define them
in the program.

7 years agoTests can now specify (via a hacky filename suffix) which runtime they want.
David Given [Wed, 16 Nov 2016 20:08:03 +0000 (21:08 +0100)]
Tests can now specify (via a hacky filename suffix) which runtime they want.

7 years agoAdd another test.
David Given [Wed, 16 Nov 2016 19:56:45 +0000 (20:56 +0100)]
Add another test.

7 years agoA bb's regsin are no longer the same as those of its first instruction;
David Given [Wed, 16 Nov 2016 19:52:15 +0000 (20:52 +0100)]
A bb's regsin are no longer the same as those of its first instruction;
occasionally the first hop of a block would try to rearrange its registers (due
to evicted throughs), resulting in the phi moves copying values into the wrong
registers.

7 years agoCleanup; the test driver is now way more robust.
David Given [Wed, 16 Nov 2016 19:50:14 +0000 (20:50 +0100)]
Cleanup; the test driver is now way more robust.

7 years agoReenable eviction of corrupted registers, which had been broken by a previous
David Given [Tue, 15 Nov 2016 20:55:10 +0000 (21:55 +0100)]
Reenable eviction of corrupted registers, which had been broken by a previous
change. Change the register move code to get swaps right, or at least righter.

7 years agoPut saved registers in *actually* the write place. I hope.
David Given [Tue, 15 Nov 2016 20:54:15 +0000 (21:54 +0100)]
Put saved registers in *actually* the write place. I hope.

7 years agoGet subtractions the right way round.
David Given [Tue, 15 Nov 2016 19:25:11 +0000 (20:25 +0100)]
Get subtractions the right way round.

7 years agoAdd a basic integer shift test.
David Given [Mon, 14 Nov 2016 21:12:13 +0000 (22:12 +0100)]
Add a basic integer shift test.

7 years agoAdd basic integer comparison test.
David Given [Mon, 14 Nov 2016 21:01:25 +0000 (22:01 +0100)]
Add basic integer comparison test.

7 years agoAllow values left on the stack at the end of the procedure (it's legal!).
David Given [Mon, 14 Nov 2016 20:47:49 +0000 (21:47 +0100)]
Allow values left on the stack at the end of the procedure (it's legal!).

7 years agoaelflod and aslod now default to not showing the memory dump. dtrg-cgen
David Given [Sun, 13 Nov 2016 19:50:23 +0000 (20:50 +0100)]
aelflod and aslod now default to not showing the memory dump.

7 years agoPrecise's qemu package is qemu-system.
David Given [Sun, 13 Nov 2016 13:20:14 +0000 (14:20 +0100)]
Precise's qemu package is qemu-system.

7 years agoTypo fix.
David Given [Sun, 13 Nov 2016 13:17:38 +0000 (14:17 +0100)]
Typo fix.

7 years agoAttempt to enable the qemuppc tests on Travis.
David Given [Sun, 13 Nov 2016 13:10:44 +0000 (14:10 +0100)]
Attempt to enable the qemuppc tests on Travis.

7 years agoFix buffer overrun: if LABEL_STARTER is seen but LABEL_TERMINATOR is not, the
David Given [Sun, 13 Nov 2016 13:04:58 +0000 (14:04 +0100)]
Fix buffer overrun: if LABEL_STARTER is seen but LABEL_TERMINATOR is not, the
label parser will keep going forever looking for the end of the label. It now
stops at the end of the string.

7 years agoAdd a rather bodged test framework for the qemuppc plat, which only runs if the
David Given [Sun, 13 Nov 2016 12:37:22 +0000 (13:37 +0100)]
Add a rather bodged test framework for the qemuppc plat, which only runs if the
qemu-system-ppc emulator is installed.

7 years agoFix (or at least, work around) an issue with library order. Make sure the Basic
David Given [Sun, 13 Nov 2016 12:28:09 +0000 (13:28 +0100)]
Fix (or at least, work around) an issue with library order. Make sure the Basic
error symbols are actually defined.

7 years agoAdd just enough Open Firmware support for an output console.
David Given [Sat, 12 Nov 2016 21:09:54 +0000 (22:09 +0100)]
Add just enough Open Firmware support for an output console.

7 years agoAdd the very experimental qemuppc plat, intended to generate minimal images
David Given [Sat, 12 Nov 2016 18:20:58 +0000 (19:20 +0100)]
Add the very experimental qemuppc plat, intended to generate minimal images
which can be emulated using qemu (for, hopefully, a test suite). Currently it
generates images which won't run because there's no RAM.

7 years agoUpdate the table to return call output values in the right registers. Fix the
David Given [Fri, 11 Nov 2016 20:48:36 +0000 (21:48 +0100)]
Update the table to return call output values in the right registers. Fix the
register allocator so the corrupted registers only apply to throughs
(otherwise, you can't put output registers in corrupted registers).

7 years agoRework the way stack frames are laid out to be simpler and, hopefully, more
David Given [Fri, 11 Nov 2016 20:17:45 +0000 (21:17 +0100)]
Rework the way stack frames are laid out to be simpler and, hopefully, more
correct. Saved registers are now placed in what may be the right place.

7 years agoMerge from default.
David Given [Fri, 11 Nov 2016 19:17:54 +0000 (20:17 +0100)]
Merge from default.

7 years agoRename addr_t to address_t to avoid clashes with the system addr_t.
David Given [Fri, 11 Nov 2016 19:17:10 +0000 (20:17 +0100)]
Rename addr_t to address_t to avoid clashes with the system addr_t.

7 years agoDisable gethostid() in the build system Lua; it's unused and doesn't work on
David Given [Fri, 11 Nov 2016 19:16:43 +0000 (20:16 +0100)]
Disable gethostid() in the build system Lua; it's unused and doesn't work on
Haiku.

7 years agoMerge.
David Given [Thu, 10 Nov 2016 21:06:08 +0000 (22:06 +0100)]
Merge.

7 years agoAdd enough return types to the K&R C that the ACK builds (on Linux) using clang
David Given [Thu, 10 Nov 2016 21:04:18 +0000 (22:04 +0100)]
Add enough return types to the K&R C that the ACK builds (on Linux) using clang
now.

7 years agoRemove sys_time in favour of directly calling time().
David Given [Wed, 9 Nov 2016 20:52:04 +0000 (21:52 +0100)]
Remove sys_time in favour of directly calling time().

7 years agoInstall only 1 copy, not 2 copies, of osx headers.
George Koehler [Tue, 8 Nov 2016 22:13:51 +0000 (17:13 -0500)]
Install only 1 copy, not 2 copies, of osx headers.

Before this commit, the headers in plat/osx/include got installed
twice into PLATIND/osx386/include and PLATIND/osxppc/include.  This
commit installs them once into PLATIND/osx/include and changes both
descr files to find them.

Several rules in lang/ depend on plat/osx386/include+headers or
plat/osxppc/include+headers.  They each become a simplerule that
depends on plat/osx/include+headers.

7 years agoAdd the missing return in plat/osx/libsys/creat.c
George Koehler [Tue, 8 Nov 2016 20:35:02 +0000 (15:35 -0500)]
Add the missing return in plat/osx/libsys/creat.c

Before now, it might have worked by accident if the return value from
open() stayed in the function return area.

7 years agoRemove trailing whitespace in plat/osx*
George Koehler [Tue, 8 Nov 2016 20:22:09 +0000 (15:22 -0500)]
Remove trailing whitespace in plat/osx*

Also fix a comment.

7 years agoMerge branch 'default' into kernigh-osx
George Koehler [Tue, 8 Nov 2016 18:49:16 +0000 (13:49 -0500)]
Merge branch 'default' into kernigh-osx

This brings improvements to PowerPC code generation.

7 years agoMerge pull request #9 from kernigh/fix-flt-trek
David Given [Mon, 7 Nov 2016 19:15:48 +0000 (20:15 +0100)]
Merge pull request #9 from kernigh/fix-flt-trek

fixes for floating point and startrek

7 years agoEdit startrek.c so I can compile it with gcc and OpenBSD libc.
George Koehler [Mon, 7 Nov 2016 01:21:48 +0000 (20:21 -0500)]
Edit startrek.c so I can compile it with gcc and OpenBSD libc.

Rename our getline() to get_line() to prevent a conflict with POSIX
getline() declared in stdio.h.

Remove dangerous call to gets().  OpenBSD does not have gets(), C99
deprecated it and C11 removed it.

Also change spelling "sheild" to "shield".

7 years agoConvert 1 to 1.0, not 0.0, for machines with 64-bit long.
George Koehler [Mon, 7 Nov 2016 00:34:51 +0000 (19:34 -0500)]
Convert 1 to 1.0, not 0.0, for machines with 64-bit long.

This fixes flt_arith2flt() when sizeof(arith) != 4, where arith is
long.  When cemcom.ansi sees an expression like d + 1 (where d is some
double), it calls flt_arith2flt() to convert 1 to floating-point.  On
machines where sizeof(arith) != 4, the code did n >>= 1 when n should
not have been changed.  If n was 1, then n == 0 became true.  This
caused the code to convert 1 or -1 to 0.0.

My fix assumes sizeof(arith) >= 8, so I can use n >> 32.  Machines
with sizeof(arith) of 5 to 7 would need to do (uarith)n >> 32, where
uarith must be an unsigned integer type of same size as arith.

In startrek.c, the Enterprise can now dock with a starbase.  The
compiler no longer translates s1 - 1 to s1 - 0.0 and s1 + 1 to s1 +
0.0, so the game now looks for starbases next to the Enterprise.

7 years agoRemove unused defines from lang/cem/libcc.ansi/math/localmath.h
George Koehler [Sun, 6 Nov 2016 20:49:47 +0000 (15:49 -0500)]
Remove unused defines from lang/cem/libcc.ansi/math/localmath.h

This undoes part of bfeb736, and returns to using DBL_MAX_EXP and
DBL_MIN_EXP from float.h.

Add a dependency on math/localmath.h and other local header files so
libc is rebuilt when those headers change.

7 years agoUndo commit bfeb736 for lang/cem/libcc.ansi/headers/float.h
George Koehler [Sun, 6 Nov 2016 20:01:25 +0000 (15:01 -0500)]
Undo commit bfeb736 for lang/cem/libcc.ansi/headers/float.h

This restores the correct values of DBL_MAX, DBL_MIN_EXP, and related
constants.  This fixes some range checks within libc, causing
atof("-36e90") and atof("1.44e-288") to return the correct values.

7 years agoSimplify flt_arith now that mantissa uses uint32_t.
George Koehler [Sun, 6 Nov 2016 01:29:03 +0000 (21:29 -0400)]
Simplify flt_arith now that mantissa uses uint32_t.

It seems that someone wanted to build flt_arith with a compiler that
had long but not unsigned long.  This required extra code to
accomplish unsigned right shift, unsigned division, and unsigned
comparison using the signed operations.  Now that we use uint32_t, we
can simply use the unsigned operations and remove the ucmp() function.
We have similar code in mach/proto/fp/ and in
lang/cem/libcc.ansi/stdlib/ext_comp.c where we use the unsigned
operations.

Some long variables become uint32_t, and some masks with 0xFFFFFFFF
disappear because uint32_t has only 32 bits.

Update flt_arith.3 to show that mantissa uses uint32_t.

Provide a target to install modules/src/flt_arith/test.c as flt_test
so I can run the tests.

7 years agoSwitch flt_mantissa fields from long to uint32_t.
George Koehler [Sat, 5 Nov 2016 21:00:24 +0000 (17:00 -0400)]
Switch flt_mantissa fields from long to uint32_t.

This seems to fix an error when flt_arith converts a literal
double-precision float to IEEE format.  For example, 0.5 and 0.75 got
converted to slightly below their correct values.

My host gcc for amd64 has 64-bit long, but flt_arith needs only 32
bits.  The code (at least flt_add.c) can make 32-bit overflows.  Such
overflows would set the higher bits of a 64-bit long, which might
cause problems later.

I need to use uint32_t and not int32_t because the code still uses
long, and the sign extension from int32_t to long would cause
problems.  The mantissa represents a value in [0, 2) that can't be
negative, so unsigned type is better.  Also, signed overflow is
undefined behavior in C, so flt_add.c better make overflows with
uint32_t and not int32_t.

This commit doesn't touch lang/cem/libcc.ansi/stdlib/ext_fmt.h which
continues to use unsigned long for its mantissa fields.

7 years agoAssume ANSI C in modules/src/flt_arith
George Koehler [Sat, 5 Nov 2016 20:24:18 +0000 (16:24 -0400)]
Assume ANSI C in modules/src/flt_arith

Remove the #include "ansi.h" and always use the prototypes.

7 years agoEnsure the modules properly depend on their headers.
David Given [Sat, 5 Nov 2016 10:52:54 +0000 (11:52 +0100)]
Ensure the modules properly depend on their headers.

7 years agoMerge from default.
David Given [Sat, 5 Nov 2016 10:47:53 +0000 (11:47 +0100)]
Merge from default.

7 years agoProperly declare the library headers as dependencies.
David Given [Sat, 5 Nov 2016 10:47:36 +0000 (11:47 +0100)]
Properly declare the library headers as dependencies.

7 years agoCorrectly mangle labels used in initialisers.
David Given [Mon, 31 Oct 2016 22:21:33 +0000 (23:21 +0100)]
Correctly mangle labels used in initialisers.

7 years agoTypo fix.
David Given [Mon, 31 Oct 2016 22:16:02 +0000 (23:16 +0100)]
Typo fix.