gonzui


Format: Advanced Search

tkernel_2/lib/libsys/src/bitsset.cbare sourcepermlink (0.03 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2014/09/10.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      bitsset.c (libsys)
   18:  */
   19: 
   20: #include <sys/bitop.h>
   21: #include <libstr.h>
   22: 
   23: /*
   24:  * Set the bit string.
   25:  *      Set the width bits from the position of specified bit.
   26:  */
   27: EXPORT void BitsSet( void *base, W offset, W width )
   28: {
   29:         UB     *bp;
   30:         INT    n;
   31: 
   32:         n = offset / 8;
   33:         bp = (UB*)base + n;
   34: 
   35:         n = (W)((UW)offset & 7U);
   36:         if ( n > 0 ) {
   37:                 for ( ; n < 8; ++n ) {
   38:                         if ( --width < 0 ) {
   39:                                 return;
   40:                         }
   41:                         BitSet(bp, (UW)n);
   42:                 }
   43:                 bp++;
   44:         }
   45: 
   46:         n = width / 8;
   47:         if ( n > 0 ) {
   48:                 MEMSET(bp, 0xffU, (size_t)n);
   49:         }
   50:         bp += n;
   51:         width -= n * 8;
   52: 
   53:         for ( n = 0; n < width; ++n ) {
   54:                 BitSet(bp, (UW)n);
   55:         }
   56: }