Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/Binary/EqualsBin.gc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module NHC.Binary
  ( equalsBin
  ) where

import NHC.GreenCard
import BinPtr
import BinHandle

%-#include "cLowBinary.h"
 
%fun equalsBin :: Int -> BinHandle -> BinPtr -> BinHandle -> BinPtr -> Bool
%call (int size) (binHandle bhx) (binPtr x) (binHandle bhy) (binPtr y)
%code
%  /* size of x and y are not necessarily byte-aligned */
%  /* but bits of x and y are guaranteed byte-aligned at both ends */
%  unsigned int bytes = (size%8 ? size/8+1 : size/8);
%  int xptr, yptr;
%  xptr = (x - forceCacheTo(bhx,x)) / 8;
%  yptr = (y - forceCacheTo(bhy,y)) / 8;
%  retval = 1;
%  while (bytes--) {
%    if (bhx->cache[xptr] != bhy->cache[yptr]) {
%      retval = 0;
%      break;
%    }
%    xptr++; yptr++;
%    if (xptr==CACHESIZE) nextcache(bhx);
%    if (yptr==CACHESIZE) nextcache(bhy);
%  }
%result (bool retval)


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.