annotate PsiCLASS-1.0.2/samtools-0.1.19/bam_endian.h @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 #ifndef BAM_ENDIAN_H
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #define BAM_ENDIAN_H
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4 #include <stdint.h>
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6 static inline int bam_is_big_endian()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 long one= 1;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 return !(*((char *)(&one)));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 static inline uint16_t bam_swap_endian_2(uint16_t v)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 return (uint16_t)(((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8));
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15 static inline void *bam_swap_endian_2p(void *x)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 *(uint16_t*)x = bam_swap_endian_2(*(uint16_t*)x);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 return x;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 static inline uint32_t bam_swap_endian_4(uint32_t v)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 v = ((v & 0x0000FFFFU) << 16) | (v >> 16);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 return ((v & 0x00FF00FFU) << 8) | ((v & 0xFF00FF00U) >> 8);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 static inline void *bam_swap_endian_4p(void *x)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 *(uint32_t*)x = bam_swap_endian_4(*(uint32_t*)x);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 return x;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 static inline uint64_t bam_swap_endian_8(uint64_t v)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 v = ((v & 0x00000000FFFFFFFFLLU) << 32) | (v >> 32);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 v = ((v & 0x0000FFFF0000FFFFLLU) << 16) | ((v & 0xFFFF0000FFFF0000LLU) >> 16);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34 return ((v & 0x00FF00FF00FF00FFLLU) << 8) | ((v & 0xFF00FF00FF00FF00LLU) >> 8);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 static inline void *bam_swap_endian_8p(void *x)
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38 *(uint64_t*)x = bam_swap_endian_8(*(uint64_t*)x);
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 return x;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 #endif