--
--	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
--

--{{{  #options and #comments
#OPTION "E V"  -- no compiler libs, no vector space
#COMMENT "TA compiler library, V1.2 24/02/92"
#COMMENT "(c) Copyright INMOS Limited 1988"
--}}}

#PRAGMA TRANSLATE BITCOUNT "BITCOUNT%O"

--{{{  BITCOUNT in occam
INT FUNCTION BITCOUNT (VAL INT Word, CountIn)

  -- CountOut := CountIn + (Number of bits set in Word)
  --{{{  history
  -- V1.1, 21/02/89
  -- Moved position of definition of Myword.  V1.2, 24/02/92, SRH
  --}}}

  INT CountOut :
  VALOF
    --{{{  
    INT MyWord :
    SEQ
      MyWord := Word
      CountOut := CountIn
      WHILE MyWord <> 0
        SEQ
          -- This resets the bottom bit which is set:
          MyWord   := MyWord /\ (MyWord MINUS 1)
          CountOut := CountOut + 1
    --}}}
    RESULT CountOut
:
--}}}
