Annotation of nono/lib/bitops.h, revision 1.1.1.1

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #include "header.h"
                     10: 
                     11: extern const uint8 bitrev_table[256];
                     12: 
                     13: // 8ビットを左右反転する (定数用)
                     14: static constexpr uint8 _rev8(uint8 x)
                     15: {
                     16:        x = ((x & 0x0f) << 4) | ((x >> 4) & 0x0f);
                     17:        x = ((x & 0x33) << 2) | ((x >> 2) & 0x33);
                     18:        x = ((x & 0x55) << 1) | ((x >> 1) & 0x55);
                     19:        return x;
                     20: }
                     21: 
                     22: // 8ビットを左右反転する (実行時用)
                     23: static inline uint8
                     24: bitrev(uint8 x)
                     25: {
                     26:        return bitrev_table[x];
                     27: }
                     28: 
                     29: // mask で指定したいずれかのビットが 0 -> 1 に変化したら true
                     30: static constexpr bool
                     31: bit_rising(uint before, uint after, uint mask)
                     32: {
                     33:        // before が 0 で mask が 1 のビットだけを立てる
                     34:        // それが 1 で after が 1 なら立ち上がり
                     35:        return (~before & mask) & after;
                     36: }
                     37: 
                     38: // mask で指定したいずれかのビットが 1 -> 0 に変化したら true
                     39: static constexpr bool
                     40: bit_falling(uint before, uint after, uint mask)
                     41: {
                     42:        // before が 1 で mask が 1 のビットだけを立てる
                     43:        // それが 1 で after が 0 なら立ち下がり
                     44:        return (before & mask) & ~after;
                     45: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.