Changeset a35b458 in mainline for kernel/generic/src/adt/bitmap.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/adt/bitmap.c

    r3061bc1 ra35b458  
    6262        size_t byte = element / BITMAP_ELEMENT;
    6363        uint8_t mask = 1 << (element & BITMAP_REMAINER);
    64        
     64
    6565        return !!((bitmap->bits)[byte] & mask);
    6666}
     
    7878{
    7979        size_t size = elements / BITMAP_ELEMENT;
    80        
     80
    8181        if ((elements % BITMAP_ELEMENT) != 0)
    8282                size++;
    83        
     83
    8484        return size;
    8585}
     
    113113{
    114114        assert(start + count <= bitmap->elements);
    115        
     115
    116116        if (count == 0)
    117117                return;
    118        
     118
    119119        size_t start_byte = start / BITMAP_ELEMENT;
    120120        size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT);
    121        
     121
    122122        /* Leading unaligned bits */
    123123        size_t lub = min(aligned_start - start, count);
    124        
     124
    125125        /* Aligned middle bits */
    126126        size_t amb = (count > lub) ? (count - lub) : 0;
    127        
     127
    128128        /* Trailing aligned bits */
    129129        size_t tab = amb % BITMAP_ELEMENT;
    130        
     130
    131131        if (start + count < aligned_start) {
    132132                /* Set bits in the middle of byte. */
     
    135135                return;
    136136        }
    137        
     137
    138138        if (lub) {
    139139                /* Make sure to set any leading unaligned bits. */
     
    141141                    ~((1 << (BITMAP_ELEMENT - lub)) - 1);
    142142        }
    143        
     143
    144144        size_t i;
    145        
     145
    146146        for (i = 0; i < amb / BITMAP_ELEMENT; i++) {
    147147                /* The middle bits can be set byte by byte. */
     
    149149                    ALL_ONES;
    150150        }
    151        
     151
    152152        if (tab) {
    153153                /* Make sure to set any trailing aligned bits. */
     
    167167{
    168168        assert(start + count <= bitmap->elements);
    169        
     169
    170170        if (count == 0)
    171171                return;
    172        
     172
    173173        size_t start_byte = start / BITMAP_ELEMENT;
    174174        size_t aligned_start = ALIGN_UP(start, BITMAP_ELEMENT);
    175        
     175
    176176        /* Leading unaligned bits */
    177177        size_t lub = min(aligned_start - start, count);
    178        
     178
    179179        /* Aligned middle bits */
    180180        size_t amb = (count > lub) ? (count - lub) : 0;
    181        
     181
    182182        /* Trailing aligned bits */
    183183        size_t tab = amb % BITMAP_ELEMENT;
    184        
     184
    185185        if (start + count < aligned_start) {
    186186                /* Set bits in the middle of byte */
     
    189189                return;
    190190        }
    191        
     191
    192192        if (lub) {
    193193                /* Make sure to clear any leading unaligned bits. */
     
    195195                    (1 << (BITMAP_ELEMENT - lub)) - 1;
    196196        }
    197        
     197
    198198        size_t i;
    199        
     199
    200200        for (i = 0; i < amb / BITMAP_ELEMENT; i++) {
    201201                /* The middle bits can be cleared byte by byte. */
     
    203203                    ALL_ZEROES;
    204204        }
    205        
     205
    206206        if (tab) {
    207207                /* Make sure to clear any trailing aligned bits. */
     
    209209                    ~((1 << tab) - 1);
    210210        }
    211        
     211
    212212        bitmap->next_fit = start_byte;
    213213}
     
    224224        assert(count <= dst->elements);
    225225        assert(count <= src->elements);
    226        
     226
    227227        size_t i;
    228        
     228
    229229        for (i = 0; i < count / BITMAP_ELEMENT; i++)
    230230                dst->bits[i] = src->bits[i];
    231        
     231
    232232        if (count % BITMAP_ELEMENT) {
    233233                bitmap_clear_range(dst, i * BITMAP_ELEMENT,
     
    274274        if (count == 0)
    275275                return false;
    276        
     276
    277277        size_t size = bitmap_size(bitmap->elements);
    278278        size_t next_fit = bitmap->next_fit;
    279        
     279
    280280        /*
    281281         * Adjust the next-fit value according to the address
     
    284284        if ((prefered > base) && (prefered < base + bitmap->elements)) {
    285285                size_t prefered_fit = (prefered - base) / BITMAP_ELEMENT;
    286                
     286
    287287                if (prefered_fit > next_fit)
    288288                        next_fit = prefered_fit;
    289289        }
    290        
     290
    291291        for (size_t pos = 0; pos < size; pos++) {
    292292                size_t byte = (next_fit + pos) % size;
    293                
     293
    294294                /* Skip if the current byte has all bits set */
    295295                if (bitmap->bits[byte] == ALL_ONES)
    296296                        continue;
    297                
     297
    298298                size_t byte_bit = byte * BITMAP_ELEMENT;
    299                
     299
    300300                for (size_t bit = 0; bit < BITMAP_ELEMENT; bit++) {
    301301                        size_t i = byte_bit + bit;
    302                        
     302
    303303                        if (i >= bitmap->elements)
    304304                                break;
    305                        
     305
    306306                        if (!constraint_satisfy(i, base, constraint))
    307307                                continue;
    308                        
     308
    309309                        if (!bitmap_get_fast(bitmap, i)) {
    310310                                size_t continuous = 1;
    311                                
     311
    312312                                for (size_t j = 1; j < count; j++) {
    313313                                        if ((i + j < bitmap->elements) &&
     
    317317                                                break;
    318318                                }
    319                                
     319
    320320                                if (continuous == count) {
    321321                                        if (index != NULL) {
     
    324324                                                *index = i;
    325325                                        }
    326                                        
     326
    327327                                        return true;
    328328                                } else
     
    331331                }
    332332        }
    333        
     333
    334334        return false;
    335335}
Note: See TracChangeset for help on using the changeset viewer.