Debian Codegraph @

src/impl_sse/impl_sse.h

raw symbols SCIP
1 /* SSE optimized implementation for Infernal
2 */
3
4 #ifndef CM_IMPL_SSE_INCLUDED
5 #define CM_IMPL_SSE_INCLUDED
6
7 #include <xmmintrin.h>
8 #include <emmintrin.h>
9
10 #include <esl_config.h>
11 #include <p7_config.h>
12 #include "config.h"
13
14 #include "easel.h"
15 #include "esl_hmm.h"
16
17 #include "hmmer.h"
18
19 #include "infernal.h"
20
21 #define BYTEMAX 255
22 #define WORDMAX 0x7fff
23
24 /*****************************************************************
25 * 1. CM_OPTIMIZED: an optimized score profile
26 *****************************************************************/
27
28 typedef struct cm_optimized_s {
29 /* basic model information */
30 int M;
31 char *sttype;
32 int *cfirst;
33 int *cnum;
34 int *plast;
35 int *pnum;
36
37 const ESL_ALPHABET *abc;
38
39 /* epi16-specific information */
40 float scale_w;
41 int16_t **tsc;
42 int16_t **oesc;
43 int16_t *beginsc;
44 int16_t *endsc;
45 int16_t el_selfsc;
46 } CM_OPTIMIZED;
47
48 /*****************************************************************
49 * 2. CCM_BG: a background model (for bias composition correction)
50 *****************************************************************/
51
52 typedef struct ccm_bg_s {
53 float p1; /* null model's self-loop probability */
54 float *f; /* residue frequencies [0..K-1] */
55
56 ESL_HMM *fhmm; /* 2-state HMM filter null model in prefilters */
57 } CCM_BG;
58
59 /*****************************************************************
60 * 3. CM_CONSENSUS: a match-only profile
61 *****************************************************************/
62
63 typedef struct cm_consensus_s {
64 int M;
65 char *sttype;
66 int *next; /* Overloaded: we'll usually fill this in, even
67 though next[i] = i+1 for most cases. For
68 B_st, next will be the _right_ child (and
69 the left will always be i+1 */
70
71 ESL_ALPHABET *abc;
72
73 /* floating point values */
74 float e_fraglen; /* expected length (bases) of model fragments */
75 float p_rfrag; /* probability of a recursive fragment (i.e., proportion of frags that are not E-terminal */
76 float sc_frag; /* log prob for each fragment - LOG(1/#frags) */
77
78 /* Reduced-precision uchar scores */
79 uint8_t tsb_S_Sa, tsb_S_SM, tsb_S_e, tsb_M_S;
80 float scale_b;
81 uint8_t base_b;
82 uint8_t bias_b;
83 uint8_t **oesc;
84
85 /* Matched-composition null model */
86 float *mcompo; /* Residue composition for matches */
87 float *fcompo; /* Total residue composition, including unaligned positions */
88 CCM_BG *bg;
89 } CM_CONSENSUS;
90
91 /*****************************************************************
92 * 4. GammaHitMx_epu8: hit collection for 8-bit scanning models
93 *****************************************************************/
94
95 /* Structure GammaHitMx_epu8: gamma semi-HMM used for optimal hit resolution
96 * of a CM_CONSENSUS scan.
97 */
98 typedef struct gammahitmx_epu8_s {
99 int L; /* length of sequence */
100 int *mx; /* [0..L] SHMM DP matrix for optimum nonoverlap resolution */
101 int *gback; /* [0..L] traceback pointers for SHMM */
102 float *savesc; /* [0..L] saves score of hit added to best parse at j */
103 float cutoff; /* minimum score to report */
104 int i0; /* position of first residue in sequence (gamma->mx[0] corresponds to this residue) */
105 int iamgreedy; /* TRUE to use RSEARCH's greedy overlap resolution alg, FALSE to use optimal alg */
106 } GammaHitMx_epu8;
107
108 /*****************************************************************
109 * 5. Structure for returning hit coordinates for 16-bit models
110 *****************************************************************/
111
112 typedef struct hitcoord_epi16_s {
113 int16_t score;
114 int16_t v;
115 int j;
116 int16_t d;
117 } HitCoord_epi16;
118
119 /*****************************************************************
120 * 5. Declarations of the external API.
121 *****************************************************************/
122
123 /* cm_optimized.c */
124 uint8_t biased_byteify(CM_CONSENSUS *ccm, float sc);
125 uint8_t unbiased_byteify(CM_CONSENSUS *ccm, float sc);
126
127 /* wordify()
128 * Converts log probability score to a rounded signed 16-bit integer cost.
129 * Both emissions and transitions for ViterbiFilter get this treatment.
130 * No bias term needed, because we use signed words.
131 * e.g. a score of +3.2, with scale 500.0, becomes +1600.
132 */
133 static inline int16_t wordify(float scale_w, float sc)
134 {
135 sc = roundf(scale_w * sc);
136 if (sc >= 32767.0) return 32767;
137 else if (sc <= -32768.0) return -32768;
138 else return (int16_t) sc;
139 }
140
141 CM_OPTIMIZED* cm_optimized_Convert(const CM_t *cm);
142 void cm_optimized_Free(CM_OPTIMIZED *ocm);
143
144 CM_CONSENSUS* cm_consensus_Convert(CM_t *cm);
145 void cm_consensus_Free(CM_CONSENSUS *ccm);
146 float ccm_explen(CM_CONSENSUS *ccm, float t1, float t2, float t3);
147 int ccm_SetCompo(CM_CONSENSUS *ccm, float f_S_Sa, float f_S_SM, float f_S_e);
148 CCM_BG* ccm_bg_CreateUniform(CM_CONSENSUS *ccm);
149 void ccm_bg_Destroy(CCM_BG *bg);
150 int ccm_bg_NullOne(const CCM_BG *bg, int L, float *ret_sc);
151 int ccm_bg_SetFilter(CM_CONSENSUS *ccm, float mL, float sL);
152 int ccm_bg_FilterScore(CCM_BG *bg, ESL_DSQ *dsq, int L, float *ret_sc);
153
154 /* sse_cmcons_hitmx.c */
155 GammaHitMx_epu8 *CreateGammaHitMx_epu8(int L, int i0, int be_greedy, int offset_zero, float cutoff, int do_backward);
156 void FreeGammaHitMx_epu8(GammaHitMx_epu8 *gamma);
157 int UpdateGammaHitMx_epu8(CM_CONSENSUS *ccm, char *errbuf, GammaHitMx_epu8 *gamma, int j, __m128i *alpha_row, CM_TOPHITS *hitlist, int W, int sW);
158 void TBackGammaHitMx_epu8 (GammaHitMx_epu8 *gamma, CM_TOPHITS *hitlist, int i0, int j0);
159
160 /* sse_cmcons_mscyk.c */
161 int SSE_MSCYK(CM_CONSENSUS *ccm, char *errbuf, int W, ESL_DSQ *dsq, int i0, int j0, uint8_t cutoff,
162 CM_TOPHITS *hitlist, int do_null3, float **ret_vsc, float *ret_sc);
163 CM_TOPHITS * ResolveMSCYK(CM_TOPHITS *initial, int i0, int j0, int W, float cutoff);
164
165 /* sse_cm_dpsearch.c */
166 int SSE_CYKScan(CM_t *cm, char *errbuf, CM_SCAN_MX *smx, ESL_DSQ *dsq,
167 int i0, int j0, float cutoff, CM_TOPHITS *hitlist,
168 int do_null3, float **ret_vsc, float *ret_sc);
169
170 /* sse_cm_dpsmall.c */
171 float SSE_CYKInside(CM_t *cm, ESL_DSQ *dsq, int L, int r,
172 int i0, int j0, Parsetree_t **ret_tr);
173 float SSE_CYKInsideScore(CM_t *cm, ESL_DSQ *dsq, int L, int r, int i0, int j0);
174 float SSE_CYKDemands(CM_t *cm, int L, int be_quiet);
175 float SSE_CYKDivideAndConquer(CM_t *cm, ESL_DSQ *dsq, int L, int r,
176 int i0, int j0, Parsetree_t **ret_tr);
177 int SSE_CYKFilter_epi16(CM_OPTIMIZED *ocm, ESL_DSQ *dsq, int L, int vroot, int vend, int i0, int j0,
178 int allow_begin, int *ret_b, int *ret_bsc, HitCoord_epi16 *ret_coord);
179
180
181 /* sse_util.c */
182 __m128 alt_rightshift_ps(__m128 a, __m128 b);
183 void vecprint_ps(__m128 a);
184
185 /* Function: sse_setlw_neginfv()
186 * Date: DLK, Tue May 12 2009
187 *
188 * Purpose: Returns a vector containing
189 * <{ -32768 a[1] a[2] a[3] a[4] a[5] a[6] a[7] }>
190 *
191 * This is designed as a limited-use
192 * replacement for the call:
193 * _mm_insert_epi16(a, -32768, 0)
194 * which suffers from a compiler
195 * bug in gcc 3.4.x
196 */
197 static inline __m128i sse_setlw_neginfv(__m128i a)
198 {
199 __m128i mask = _mm_setr_epi16(0x0000,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff);
200 __m128i setv = _mm_setr_epi16(-32768,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000);
201
202 return _mm_or_si128(_mm_and_si128(a,mask),setv);
203 }
204
205 /* Function: sse_select_si128()
206 * Date: DLK, Tue June 9 2009
207 *
208 * Purposes: Bitwise vector select for __m128i
209 */
210 static inline __m128i sse_select_si128(__m128i a, __m128i b, __m128i mask)
211 {
212 b = _mm_and_si128(b, mask);
213 a = _mm_andnot_si128(mask, a);
214 return _mm_or_si128(a, b);
215 }
216
217
218 #endif /* CM_IMPL_SSE_INCLUDED */
219
220