[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

3-way arithmetic IF



    Date: Thu, 1 Aug 1991 02:19 EDT
    From: kddlab!atr-la.atr.co.jp!myers@uunet.UU.NET (John K. Myers)

    I need to compare two integers x and y, and perform routine 1
    if x<y, routine 2 if x=y, and routine 3 if x>y.  X and Y are
    bignums on the order of six words long.  The operation must be
    as fast as possible.
      Testing x<y takes about 85-95 microseconds;
      testing x=y takes about 79-83 microseconds;
      total worst-case time of about 178 microseconds.

      Evaluating (signum (- x y)) takes about 175 microseconds.

    Question:  Is there a low-level arithmetic IF somewhere down in
    the guts of the machine, that supports a single </=/> comparison
    between two numbers and then switches control three ways accordingly?

If there were, I think they would have used it in the implementation of
SIGNUM, but it mostly consists of a bunch of

      (COND ((PLUSP NUMBER) 1)
	    ((MINUSP NUMBER) -1)
	    (T NUMBER))

forms (different ones for different argument data types, since the value
type is supposed to be the same as the argument type).

The only three-way conditional instruction I can think of is
BRANCH-NOT-ENDP.  It branches if the argument is a cons, falls through
if it's NIL, and generates a WRONG-TYPE-ARGUMENT-TRAP otherwise.

                                                barmar