Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/klib/blob/master/kbit.h # klib [Ported from github.com/attractivechaos/klib] added block arena Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `klib / kbit.h` 30 lines ยท 1087 bytes Raw Blame History 1 #ifndef KBIT_H 2 #define KBIT_H 3 4 #include 5 6 static inline uint64_t kbi_popcount64(uint64_t y) // standard popcount; from wikipedia 7 { 8 y -= ((y >> 1) & 0x5555555555555555ull); 9 y = (y & 0x3333333333333333ull) + (y >> 2 & 0x3333333333333333ull); 10 return ((y + (y >> 4)) & 0xf0f0f0f0f0f0f0full) * 0x101010101010101ull >> 56; 11 } 12 13 static inline uint64_t kbi_DNAcount64(uint64_t y, int c) // count #A/C/G/T from a 2-bit encoded integer; from BWA 14 { 15 // reduce nucleotide counting to bits counting 16 y = ((c&2)? y : ~y) >> 1 & ((c&1)? y : ~y) & 0x5555555555555555ull; 17 // count the number of 1s in y 18 y = (y & 0x3333333333333333ull) + (y >> 2 & 0x3333333333333333ull); 19 return ((y + (y >> 4)) & 0xf0f0f0f0f0f0f0full) * 0x101010101010101ull >> 56; 20 } 21 22 #ifndef kroundup32 // round a 32-bit integer to the next closet integer; from "bit twiddling hacks" 23 #define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x)) 24 #endif 25 26 #ifndef kbi_swap 27 #define kbi_swap(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) // from "bit twiddling hacks" 28 #endif 29 30 #endif