Skip to content

Commit e7722c4

Browse files
committed
2x faster P and NPN canonization by forcing inlining
1 parent 4fe7141 commit e7722c4

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/canonization.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub fn generate_swaps(num_vars: usize, rollback: bool) -> Vec<u8> {
150150
}
151151

152152
/// Run all swaps on the P canonization, and return the index of the best result
153+
#[inline(always)]
153154
pub fn p_canonization_ind(
154155
num_vars: usize,
155156
table: &mut [u64],
@@ -186,6 +187,7 @@ pub fn is_p_canonical_helper(
186187
}
187188

188189
/// Run all flips on the N canonization, and return the index of the best result
190+
#[inline(always)]
189191
pub fn n_canonization_ind(
190192
num_vars: usize,
191193
table: &mut [u64],
@@ -231,6 +233,7 @@ pub fn is_n_canonical_helper(
231233

232234
/// Run all swaps on the P canonization and all flips on the N canonization,
233235
/// and return the index of the best result
236+
#[inline(always)]
234237
pub fn npn_canonization_ind(
235238
num_vars: usize,
236239
table: &mut [u64],
@@ -283,6 +286,7 @@ pub fn is_npn_canonical_helper(
283286
}
284287

285288
/// Find the corresponding permutation given the index of the best result
289+
#[inline(always)]
286290
pub fn p_canonization_res(num_vars: usize, res_perm: &mut [u8], all_swaps: &[u8], best_ind: usize) {
287291
debug_assert!(best_ind == usize::MAX || best_ind < all_swaps.len());
288292
debug_assert_eq!(res_perm.len(), num_vars);
@@ -304,6 +308,7 @@ pub fn p_canonization_res(num_vars: usize, res_perm: &mut [u8], all_swaps: &[u8]
304308
}
305309

306310
/// Find the corresponding complementation given the index of the best result
311+
#[inline(always)]
307312
pub fn n_canonization_res(num_vars: usize, all_flips: &[u8], best_ind: usize) -> u32 {
308313
let mut ind = 0;
309314
let mut cur_flip = 0;
@@ -325,6 +330,7 @@ pub fn n_canonization_res(num_vars: usize, all_flips: &[u8], best_ind: usize) ->
325330
}
326331

327332
/// Find the corresponding permutation and complementation given the index of the best result
333+
#[inline(always)]
328334
pub fn npn_canonization_res(
329335
num_vars: usize,
330336
res_perm: &mut [u8],

src/operations.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub fn count_zeros(num_vars: usize, table: &[u64]) -> usize {
204204
}
205205

206206
/// Logical not computation
207+
#[inline(always)]
207208
pub fn not_inplace(num_vars: usize, table: &mut [u64]) {
208209
let mask = num_vars_mask(num_vars);
209210
for t in table {
@@ -370,6 +371,7 @@ pub fn fill_bin(num_vars: usize, table: &mut [u64], s: &str) -> Result<(), Parse
370371
}
371372

372373
/// Swap two variables in the LUT
374+
#[inline(always)]
373375
pub fn swap_inplace(num_vars: usize, table: &mut [u64], ind1: usize, ind2: usize) {
374376
debug_assert_eq!(table.len(), table_size(num_vars));
375377
debug_assert!(ind1 < num_vars);
@@ -416,6 +418,7 @@ pub fn swap_inplace(num_vars: usize, table: &mut [u64], ind1: usize, ind2: usize
416418
}
417419

418420
/// Swap two adjacent variables in the LUT
421+
#[inline(always)]
419422
pub fn swap_adjacent_inplace(num_vars: usize, table: &mut [u64], ind: usize) {
420423
swap_inplace(num_vars, table, ind, ind + 1);
421424
}
@@ -437,6 +440,7 @@ pub fn permute_inplace(num_vars: usize, table: &mut [u64], perm: &[u8]) {
437440
debug_assert_eq!(order, perm);
438441
}
439442

443+
#[inline(always)]
440444
pub fn flip_inplace(num_vars: usize, table: &mut [u64], ind: usize) {
441445
debug_assert_eq!(table.len(), table_size(num_vars));
442446
debug_assert!(ind < num_vars);
@@ -457,6 +461,7 @@ pub fn flip_inplace(num_vars: usize, table: &mut [u64], ind: usize) {
457461
}
458462
}
459463

464+
#[inline(always)]
460465
pub fn flip_n_inplace(num_vars: usize, table: &mut [u64], mask: u32) {
461466
for i in 0..num_vars {
462467
if ((mask >> i) & 1) != 0 {
@@ -468,6 +473,7 @@ pub fn flip_n_inplace(num_vars: usize, table: &mut [u64], mask: u32) {
468473
}
469474
}
470475

476+
#[inline(always)]
471477
pub fn cofactor0_inplace(num_vars: usize, table: &mut [u64], ind: usize) {
472478
debug_assert_eq!(table.len(), table_size(num_vars));
473479
debug_assert!(ind < num_vars);
@@ -487,6 +493,7 @@ pub fn cofactor0_inplace(num_vars: usize, table: &mut [u64], ind: usize) {
487493
}
488494
}
489495

496+
#[inline(always)]
490497
pub fn cofactor1_inplace(num_vars: usize, table: &mut [u64], ind: usize) {
491498
debug_assert_eq!(table.len(), table_size(num_vars));
492499
debug_assert!(ind < num_vars);

0 commit comments

Comments
 (0)