--
--      Inmos Libraries
--      Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--      This library is free software; you can redistribute it and/or
--      modify it under the terms of the GNU Lesser General Public
--      License as published by the Free Software Foundation; either
--      version 2 of the License, or (at your option) any later version.
--
--      This library is distributed in the hope that it will be useful,
--      but WITHOUT ANY WARRANTY; without even the implied warranty of
--      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--      Lesser General Public License for more details.
--
--      You should have received a copy of the GNU Lesser General Public
--      License along with this library; if not, write to the Free Software
--      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module forall

#IF (TARGET.BITS.PER.WORD = 16)

--{{{  #options and #comments
#OPTION "E V"  -- no compiler libs, no vector space
#COMMENT "Support routines library, V1.1 21/02/89"
#COMMENT "(c) Copyright INMOS Limited 1988"
--}}}

#PRAGMA TRANSLATE QRealIMul "QRealIMul%CHK"

#INCLUDE "realvals.inc"

--{{{  QRealIMul -- T2
PROC QRealIMul ([4]INT U, INT Guard, VAL INT V3, V2, V1, V0)

  -- Function version (10 Jun 87)

  -- Quad Length unsigned multiply
  -- Returns Top 4 words of result plus guard word which is the next word
  -- with its bottom bit used as a sticky bit to hold OR all the other bits.

  [9] INT W :
  PLACE W IN WORKSPACE :
  [4] INT C :
  PLACE C IN WORKSPACE :
  INT Carry :
  SEQ
    Carry,  W[0] := LONGPROD ( U[0],  V0,  0)
    Carry,  W[1] := LONGPROD ( U[1],  V0,  Carry)
    Carry,  W[2] := LONGPROD ( U[2],  V0,  Carry)
    W[4],   W[3] := LONGPROD ( U[3],  V0,  Carry)
    C[0],   W[1] := LONGPROD ( U[0],  V1,  W[1])
    C[1],   W[2] := LONGPROD ( U[1],  V1,  W[2])
    C[2],   W[3] := LONGPROD ( U[2],  V1,  W[3])
    C[3],   W[4] := LONGPROD ( U[3],  V1,  W[4])
    Carry,  W[2] := LONGSUM ( C[0],  W[2],  0)
    Carry,  W[3] := LONGSUM ( C[1],  W[3],  Carry)
    Carry,  W[4] := LONGSUM ( C[2],  W[4],  Carry)
    W[6],   W[5] := LONGSUM ( C[3],  0,  Carry)
    C[0],   W[2] := LONGPROD ( U[0],  V2,  W[2])
    C[1],   W[3] := LONGPROD ( U[1],  V2,  W[3])
    C[2],   W[4] := LONGPROD ( U[2],  V2,  W[4])
    C[3],   W[5] := LONGPROD ( U[3],  V2,  W[5])
    Carry,  W[3] := LONGSUM ( C[0],  W[3],  0)
    Carry,  W[4] := LONGSUM ( C[1],  W[4],  Carry)
    Carry,  W[5] := LONGSUM ( C[2],  W[5],  Carry)
    W[7],   W[6] := LONGSUM ( C[3],  0,  Carry)
    C[0],   W[3] := LONGPROD ( U[0],  V3,  W[3])
    C[1],   W[4] := LONGPROD ( U[1],  V3,  W[4])
    C[2],   W[5] := LONGPROD ( U[2],  V3,  W[5])
    C[3],   W[6] := LONGPROD ( U[3],  V3,  W[6])
    Carry,  W[4] := LONGSUM ( C[0],  W[4],  0)
    Carry,  W[5] := LONGSUM ( C[1],  W[5],  Carry)
    Carry,  W[6] := LONGSUM ( C[2],  W[6],  Carry)
    W[8],   W[7] := LONGSUM ( C[3],  0,  Carry)
    U[0] := W[4]
    U[1] := W[5]
    U[2] := W[6]
    U[3] := W[7]
    Guard := W[3]
    IF
      ((W[2] \/ W[1]) \/ W[0]) <> 0 -- if bottom three words not all zero set
        Guard := Guard \/ 1         -- sticky bit
      TRUE
        SKIP
:
--}}}

#ENDIF
