annotate pyPRADA_1.2/tools/samtools-0.1.16/bam_endian.h @ 0:acc2ca1a3ba4

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