Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!ncar!oddjob!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.arch
Subject: no-branch 68000 signum, min, max
Message-ID: <12212@mimsy.UUCP>
Date: 29 Jun 88 01:16:31 GMT
References: <1941@pt.cs.cmu.edu> <3208@ubc-cs.UUCP> <1986@pt.cs.cmu.edu> <7570@boring.cwi.nl>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 34

In article <7570@boring.cwi.nl> dik@cwi.nl (Dik T. Winter) writes:
>(What is signum?)

It has other names, but I prefer signum to avoid confusion with sine, etc.

		  {  -1		x < 0
	signum(x) {   0		x = 0
		  {   1		x > 0

>Not so surprising for min and max (and minmax).  However, they require a
>sign extending shift, so that implementation is not possible on all
>machines.

No, they use clever tricks with the carry bit (these are for unsigned
values).  Indeed, this implementation is not possible on some machines
(VAXen have subtract-with-carry but have no AND instruction; others have
no subtract-with-carry), which is why you want some automatic way of
converting unsigned-min(x,y) into actual code.

>Also, if a branch takes only one cycle (with delay slot),
>you do not gain anything (in general).

On the 68020 the no-branch versions win in terms of total cycles.
min() looks like this:

	| input:  d0=x, d1=y, both unsigned; d2 is scratch
	| output: d0=min(x, y)

		sub.l	d1,d0	| d0 = x-y
		subx.l	d2,d2	| d2 = 111...111 if x