From ff6bcecd9fafa0907acb263406d935e03c3d8d85 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Thu, 13 Feb 2025 11:33:16 +0000 Subject: [PATCH] DBResidueMask() cleanup Reorder things in this function. Adding 'const' in key places to provide the compiler the extra hint for the purpose of this computation we don't change the value and the value never changes externally even across function calls. I'm sure the compiler (due to macro implementation of TTMaskXxxxx() calls and visibility of data being changes) will optimise the function in exactly the way of the reorder. This also should have the side-effect of making clearer more auto vectorization possibilities to the compiler or potentially replacing the loop with (tail-call or inline) to : simd_TTMaskSetMask_residues(lmask, rmask, TT_TECHDEPBASE, DBNumUserLayers); Which would be a hand optimized form, that probably has an 'l_residues' layout that favours SIMD use (2nd order copy from source of truth just in a different data layout, such as contiguous array of TileTypeBitMask indexed from 0, with the TileType as the index). --- database/DBtcontact.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/database/DBtcontact.c b/database/DBtcontact.c index 3a6b1fb0..9a6ef3eb 100644 --- a/database/DBtcontact.c +++ b/database/DBtcontact.c @@ -953,24 +953,22 @@ DBFullResidueMask(type, rmask) TileType type; TileTypeBitMask *rmask; { - TileType t; - TileTypeBitMask *lmask; - LayerInfo *li, *lr; - - li = &dbLayerInfo[type]; - lmask = &li->l_residues; - TTMaskZero(rmask); + LayerInfo *li = &dbLayerInfo[type]; + const TileTypeBitMask *lmask = &li->l_residues; if (type < DBNumUserLayers) { - TTMaskSetMask(rmask, &li->l_residues); + TTMaskCopy(rmask, lmask); } else { - for (t = TT_TECHDEPBASE; t < DBNumUserLayers; t++) + TileType t; + const int tt_last = DBNumUserLayers; + TTMaskZero(rmask); + for (t = TT_TECHDEPBASE; t < tt_last; t++) if (TTMaskHasType(lmask, t)) { - lr = &dbLayerInfo[t]; + LayerInfo *lr = &dbLayerInfo[t]; TTMaskSetMask(rmask, &lr->l_residues); } }