LCOV - code coverage report
Current view: directory - src/trusted/validator_ragel - bitmap.h (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 17 17 100.0 %
Date: 2014-09-25 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright (c) 2012 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : /*
       8                 :  * This file contains bitmap array manipulation functions.
       9                 :  */
      10                 : 
      11                 : #ifndef NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_BITMAP_H_
      12                 : #define NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_BITMAP_H_
      13                 : 
      14                 : #include "native_client/src/include/nacl_macros.h"
      15                 : #include "native_client/src/include/portability.h"
      16                 : 
      17                 : #if NACL_WINDOWS
      18                 : # define FORCEINLINE __forceinline
      19                 : #else
      20                 : # define FORCEINLINE __inline __attribute__ ((always_inline))
      21                 : #endif
      22                 : 
      23                 : typedef NACL_CONCAT(NACL_CONCAT(uint, NACL_HOST_WORDSIZE), _t) bitmap_word;
      24                 : 
      25               2 : static INLINE bitmap_word *BitmapAllocate(size_t indexes) {
      26               2 :   size_t word_count = ((indexes + NACL_HOST_WORDSIZE - 1) / NACL_HOST_WORDSIZE);
      27               2 :   NACL_COMPILE_TIME_ASSERT((NACL_HOST_WORDSIZE / 8) == sizeof(bitmap_word));
      28               2 :   return calloc(word_count, sizeof(bitmap_word));
      29               2 : }
      30                 : 
      31               2 : static FORCEINLINE int BitmapIsBitSet(bitmap_word *bitmap, size_t index) {
      32                 :   return (bitmap[index / NACL_HOST_WORDSIZE] &
      33               2 :                        (((bitmap_word)1) << (index % NACL_HOST_WORDSIZE))) != 0;
      34               2 : }
      35                 : 
      36               2 : static FORCEINLINE void BitmapSetBit(bitmap_word *bitmap, size_t index) {
      37                 :   bitmap[index / NACL_HOST_WORDSIZE] |=
      38               2 :                                ((bitmap_word)1) << (index % NACL_HOST_WORDSIZE);
      39               2 : }
      40                 : 
      41               1 : static FORCEINLINE void BitmapClearBit(bitmap_word *bitmap, size_t index) {
      42                 :   bitmap[index / NACL_HOST_WORDSIZE] &=
      43               1 :                             ~(((bitmap_word)1) << (index % NACL_HOST_WORDSIZE));
      44               1 : }
      45                 : 
      46                 : /* All the bits must be in a single 32-bit bundle.  */
      47                 : static FORCEINLINE int BitmapIsAnyBitSet(bitmap_word *bitmap,
      48                 :                                          size_t index, size_t bits) {
      49                 :   return (bitmap[index / NACL_HOST_WORDSIZE] &
      50                 :        (((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE))) != 0;
      51                 : }
      52                 : 
      53                 : /* All the bits must be in a single 32-bit bundle. */
      54                 : static FORCEINLINE void BitmapSetBits(bitmap_word *bitmap,
      55                 :                                       size_t index,
      56                 :                                       size_t bits) {
      57                 :   bitmap[index / NACL_HOST_WORDSIZE] |=
      58                 :                ((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE);
      59                 : }
      60                 : 
      61                 : /* All the bits must be in a single 32-bit bundle. */
      62                 : static FORCEINLINE void BitmapClearBits(bitmap_word *bitmap,
      63               1 :                                         size_t index, size_t bits) {
      64                 :   bitmap[index / NACL_HOST_WORDSIZE] &=
      65               1 :             ~(((((bitmap_word)1) << bits) - 1) << (index % NACL_HOST_WORDSIZE));
      66               1 : }
      67                 : 
      68                 : #endif  /* NATIVE_CLIENT_SRC_TRUSTED_VALIDATOR_RAGEL_VALIDATOR_INTERNAL_H_ */

Generated by: LCOV version 1.7