LCOV - code coverage report
Current view: top level - metalib_isl - isl_blk.c (source / functions) Hit Total Coverage
Test: 2018-11-01_10-31_merged3.lcov Lines: 55 67 82.1 %
Date: 2018-11-01 12:23:03 Functions: 8 10 80.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright 2008-2009 Katholieke Universiteit Leuven
       3             :  *
       4             :  * Use of this software is governed by the MIT license
       5             :  *
       6             :  * Written by Sven Verdoolaege, K.U.Leuven, Departement
       7             :  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
       8             :  */
       9             : 
      10             : #include <isl_blk.h>
      11             : #include <isl_ctx_private.h>
      12             : 
      13             : /* The maximal number of cache misses before first element is evicted */
      14             : #define ISL_BLK_MAX_MISS        100
      15             : 
      16 >19265*10^7 : struct isl_blk isl_blk_empty()
      17             : {
      18             :         struct isl_blk block;
      19 >19265*10^7 :         block.size = 0;
      20 >19265*10^7 :         block.data = NULL;
      21 >19265*10^7 :         return block;
      22             : }
      23             : 
      24 >15922*10^7 : static int isl_blk_is_empty(struct isl_blk block)
      25             : {
      26 >15922*10^7 :         return block.size == 0 && block.data == NULL;
      27             : }
      28             : 
      29           0 : static struct isl_blk isl_blk_error()
      30             : {
      31             :         struct isl_blk block;
      32           0 :         block.size = -1;
      33           0 :         block.data = NULL;
      34           0 :         return block;
      35             : }
      36             : 
      37 >20576*10^7 : int isl_blk_is_error(struct isl_blk block)
      38             : {
      39 >20576*10^7 :         return block.size == -1 && block.data == NULL;
      40             : }
      41             : 
      42  1756081311 : static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
      43             : {
      44             :         int i;
      45             : 
      46 93617968857 :         for (i = 0; i < block.size; ++i)
      47 91861887546 :                 isl_int_clear(block.data[i]);
      48  1756081311 :         free(block.data);
      49  1756081311 : }
      50             : 
      51 >11452*10^7 : static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
      52             :                                 size_t new_n)
      53             : {
      54             :         int i;
      55             :         isl_int *p;
      56             : 
      57 >11452*10^7 :         if (block.size >= new_n)
      58 >11233*10^7 :                 return block;
      59             : 
      60  2189727182 :         p = isl_realloc_array(ctx, block.data, isl_int, new_n);
      61  2189727182 :         if (!p) {
      62           0 :                 isl_blk_free_force(ctx, block);
      63           0 :                 return isl_blk_error();
      64             :         }
      65  2189727182 :         block.data = p;
      66             : 
      67 94351010103 :         for (i = block.size; i < new_n; ++i)
      68 92161282921 :                 isl_int_init(block.data[i]);
      69  2189727182 :         block.size = new_n;
      70             : 
      71  2189727182 :         return block;
      72             : }
      73             : 
      74 >11442*10^7 : struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
      75             : {
      76             :         int i;
      77             :         struct isl_blk block;
      78             : 
      79 >11442*10^7 :         block = isl_blk_empty();
      80 >11442*10^7 :         if (n && ctx->n_cached) {
      81 90985909050 :                 int best = 0;
      82 >90163*10^7 :                 for (i = 1; ctx->cache[best].size != n && i < ctx->n_cached; ++i) {
      83 >81064*10^7 :                         if (ctx->cache[best].size < n) {
      84 74781781086 :                                 if (ctx->cache[i].size > ctx->cache[best].size)
      85 43483332088 :                                         best = i;
      86 >12734*10^8 :                         } else if (ctx->cache[i].size >= n &&
      87 >53756*10^7 :                                    ctx->cache[i].size < ctx->cache[best].size)
      88 >17057*10^7 :                                         best = i;
      89             :                 }
      90 90985909050 :                 if (ctx->cache[best].size < 2 * n + 100) {
      91 89478421747 :                         block = ctx->cache[best];
      92 89478421747 :                         if (--ctx->n_cached != best)
      93 63415008702 :                                 ctx->cache[best] = ctx->cache[ctx->n_cached];
      94 89478421747 :                         if (best == 0)
      95  9198468917 :                                 ctx->n_miss = 0;
      96  1507487303 :                 } else if (ctx->n_miss++ >= ISL_BLK_MAX_MISS) {
      97     2359264 :                         isl_blk_free_force(ctx, ctx->cache[0]);
      98     2359264 :                         if (--ctx->n_cached != 0)
      99     2358098 :                                 ctx->cache[0] = ctx->cache[ctx->n_cached];
     100     2359264 :                         ctx->n_miss = 0;
     101             :                 }
     102             :         }
     103             : 
     104 >11442*10^7 :         return extend(ctx, block, n);
     105             : }
     106             : 
     107   102172371 : struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
     108             :                                 size_t new_n)
     109             : {
     110   102172371 :         if (isl_blk_is_empty(block))
     111           0 :                 return isl_blk_alloc(ctx, new_n);
     112             : 
     113   102172371 :         return extend(ctx, block, new_n);
     114             : }
     115             : 
     116 >15912*10^7 : void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
     117             : {
     118 >15912*10^7 :         if (isl_blk_is_empty(block) || isl_blk_is_error(block))
     119 67886504984 :                 return;
     120             : 
     121 91236240414 :         if (ctx->n_cached < ISL_BLK_CACHE_SIZE)
     122 89482518367 :                 ctx->cache[ctx->n_cached++] = block;
     123             :         else
     124  1753722047 :                 isl_blk_free_force(ctx, block);
     125             : }
     126             : 
     127           0 : void isl_blk_clear_cache(struct isl_ctx *ctx)
     128             : {
     129             :         int i;
     130             : 
     131           0 :         for (i = 0; i < ctx->n_cached; ++i)
     132           0 :                 isl_blk_free_force(ctx, ctx->cache[i]);
     133           0 :         ctx->n_cached = 0;
     134           0 : }

Generated by: LCOV version 1.12