@@ -121,16 +121,19 @@ void banded_matrix_allocate(
121121 const int64_t k_end = ABS (((int64_t )text_length ) - (int64_t )(pattern_length )) + 1 ;
122122 banded_matrix -> cutoff_score = MAX (MAX (k_end , cutoff_score ), 65 );
123123 banded_matrix -> sequence_length_diff = pattern_length - text_length ;
124- banded_matrix -> relative_cutoff_score = DIV_CEIL ((banded_matrix -> cutoff_score - ABS (banded_matrix -> sequence_length_diff )), 2 );
124+ banded_matrix -> relative_cutoff_score = (banded_matrix -> cutoff_score - ABS (banded_matrix -> sequence_length_diff )) == 0LL ? 0LL :
125+ DIV_CEIL ((banded_matrix -> cutoff_score - ABS (banded_matrix -> sequence_length_diff )), 2 );
126+ const int64_t relative_cutoff_score_blocks = banded_matrix -> relative_cutoff_score == 0LL ? 0LL : DIV_CEIL (banded_matrix -> relative_cutoff_score , BPM_W64_LENGTH );
125127 if (banded_matrix -> sequence_length_diff >= 0 )
126128 {
127- banded_matrix -> prolog_column_blocks = DIV_CEIL ( banded_matrix -> relative_cutoff_score , BPM_W64_LENGTH ) ;
129+ banded_matrix -> prolog_column_blocks = relative_cutoff_score_blocks ;
128130 banded_matrix -> effective_bandwidth_blocks = DIV_CEIL (banded_matrix -> relative_cutoff_score + banded_matrix -> sequence_length_diff , BPM_W64_LENGTH ) + 1 + banded_matrix -> prolog_column_blocks ;
129131 }
130132 else
131133 {
132- banded_matrix -> prolog_column_blocks = DIV_CEIL (banded_matrix -> relative_cutoff_score - banded_matrix -> sequence_length_diff , BPM_W64_LENGTH );
133- banded_matrix -> effective_bandwidth_blocks = DIV_CEIL (banded_matrix -> relative_cutoff_score , BPM_W64_LENGTH ) + 1 + banded_matrix -> prolog_column_blocks ;
134+ banded_matrix -> prolog_column_blocks = banded_matrix -> relative_cutoff_score - banded_matrix -> sequence_length_diff == 0LL ? 0LL :
135+ DIV_CEIL (banded_matrix -> relative_cutoff_score - banded_matrix -> sequence_length_diff , BPM_W64_LENGTH );
136+ banded_matrix -> effective_bandwidth_blocks = relative_cutoff_score_blocks + 1 + banded_matrix -> prolog_column_blocks ;
134137 }
135138 banded_matrix -> effective_bandwidth = banded_matrix -> cutoff_score ;
136139
@@ -157,7 +160,7 @@ void banded_matrix_allocate(
157160 Pv = (uint64_t * )mm_allocator_malloc (mm_allocator , aux_matrix_size );
158161 Mv = (uint64_t * )mm_allocator_malloc (mm_allocator , aux_matrix_size );
159162 }
160- int64_t * const scores = (int64_t * )mm_allocator_malloc (mm_allocator , ( DIV_CEIL (pattern_length , BPM_W64_LENGTH ) + num_words64 / 2 ) * UINT64_SIZE );
163+ int64_t * const scores = (int64_t * )mm_allocator_malloc (mm_allocator , MAX (( DIV_CEIL (pattern_length , BPM_W64_LENGTH ) + num_words64 / 2 ), banded_matrix -> effective_bandwidth_blocks ) * UINT64_SIZE );
161164 banded_matrix -> Mv = Mv ;
162165 banded_matrix -> Pv = Pv ;
163166 banded_matrix -> scores = scores ;
0 commit comments