Minimum set of primitives?

Kragen kragen@pobox.com
Mon, 30 Mar 1998 12:58:48 -0500 (EST)


On 29 Mar 1998, Laurent Martelli wrote:
> >>>>> "Kragen" == Kragen  <kragen@pobox.com> writes:
> 
>  Kragen> #1 is a little disturbing.  It implies that the "minimal" set
>  Kragen> depends on the machine you're using.  If your machine is an
>  Kragen> i386, it has instructions to do BCD arithmetic, for example.
>  Kragen> Assuming some users of your Lisp have a use for BCD
>  Kragen> arithmetic, you really ought to provide them with access to
>  Kragen> the underlying machine's BCD arithmetic capabilities, instead
>  Kragen> of forcing them to implement their own in Lisp.
> 
> That's why the minimal set should be as hash lvel 

As `hash lvel'?

> as possible, in
> order not to be machine dependent. But one could have different
> implementations of the min-set depending on the machine's CPU and
> other stuff. 

Yes, but the point of a machine-independent minimal set is to ease
porting.  If the `minimal' set changes from machine to machine, it
doesn't ease porting.

In a theoretical sense, you end up having problems defining a `minimal'
set, unless you want to use arithmetic like the stuff I posted.

> On a CPU with no mult instruction, the define that you
> gave would be a good choice. 

NO NO NO NO NO it would NOT!  It's linear-time in the size of one of
the operands (and so is the add I posted, which makes things even
worse).  Look at it in C and see if you can see why this is not a good idea:

int mult (int a, int b) {
	int tmp = 0;
	while (a--) {
		tmp += b;
	}
	return tmp;
}

> But of course if you have a mult on your
> CPU, you'd better take advantage of it.

Yes, and if you have vector multiply, you'd better take advantage of
it.  And if you have a two-word compare-&-swap instruction, you'd
better take advantage of it.  And if you have floating-point
operations, you'd better take advantage of them.  And if you have
special fast instructions for copying known-length strings of
characters, you'd better take advantage of them (REP MOVSB, etc.)  And
if you have special fast instructions for evaluating polynomials, you'd
better take advantage of them.

The trouble is that your `minimal' set ends up including essentially
everything anyone's ever done hardware acceleration for.

> We could extend the idea to non min-set services, so that an OS built
> on top of Unix uses the native FS (possibly to implement an object
> storage), whereas a from scratch version would implement its storage
> with the bare device. I know that you can access raw devices with
> Unix, but then you must have a partition for LispOS. 

With Unix, you could easily write it to take advantage of a bare device
if available, and otherwise use a normal file.  In fact, most Unix
systems do this for swapfiles.

Most of the ideas you describe are good, if obvious.  I've just argued
about the ones that aren't.  :)

Kragen