chiark / gitweb /
safety: movpos: break out UnkMap bit shift operations into functions for less confusi...
[trains.git] / hostside / movpos.c
index 6388d5316e9a16c44d1c7e598e6e82f0e073d272..a31e507b8f806cb84f57655898ecbcda3734f0be 100644 (file)
@@ -108,6 +108,9 @@ struct Method {
 
 /*========== general utility functions ==========*/
 
+static UnkMap unkfeatbit(int featix) { return (UnkMap)1 << featix; }
+static UnkMap unkallfeatbits(int nfeats) { return ~(~(UnkMap)0 << nfeats); }
+
 const char *movpos_pname(const Segment *move, MovPosComb poscomb) {
   return !SOMEP(poscomb) ? "?" : move->i->poscombs[poscomb].pname;
 }
@@ -709,7 +712,7 @@ static void method_update_feature(Method *m, MovPosChange *indep,
   ouposn_feat(indep->move, mo->i, mo->posn, m);
   indep->actualpos=
     movposcomb_update_feature(indep->actualpos, mo->i, mo->posn);
-  indep->actualunk &= (~(UnkMap)1 << featix);
+  indep->actualunk &= ~unkfeatbit(featix);
   ouposn_moving(indep);
 }
 
@@ -760,7 +763,7 @@ static int change_needed(int featix, const MovFeatInfo *feati,
                         MovPosComb target) {
   int r;
 
-  r= (startpointunk & ((UnkMap)1 << featix)) ||
+  r= (startpointunk & unkfeatbit(featix)) ||
     (target / feati->weight) % feati->posns -
     (startpointpos / feati->weight) % feati->posns;
 
@@ -824,7 +827,7 @@ static ErrorCode indep_prepare(Segment *move, MovPosComb target,
       startpointunk= 0;
     } else {
       startpointpos= 0;
-      startpointunk= ((UnkMap)1 << move->i->n_movfeats) - 1;
+      startpointunk= unkallfeatbits(move->i->n_movfeats);
     }
     DPRINTF2(" actual <-%s&%"PRunkx, movpos_pname(move,startpointpos),
             startpointunk);