From d88accfec332940000f3f0341fa51b99739823d3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 19 Feb 2011 12:11:29 +0000 Subject: [PATCH] safety: movpos: break out UnkMap bit shift operations into functions for less confusion, and fix a bug in that area --- hostside/movpos.c | 9 ++++++--- hostside/x.gdb | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hostside/movpos.c b/hostside/movpos.c index 6388d53..a31e507 100644 --- a/hostside/movpos.c +++ b/hostside/movpos.c @@ -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); diff --git a/hostside/x.gdb b/hostside/x.gdb index 79496fa..21e7ef3 100644 --- a/hostside/x.gdb +++ b/hostside/x.gdb @@ -3,6 +3,8 @@ break die set args -Dmovpos+eval+intern+fsq -R -s/dev/ttyUSB0 -S+realtime.log shinkansen.speeds.record santafe.speeds.record bavarian.speeds.record homes.record +break method_update_feature if indep->move == &segments[4] + #break point_move if mfi->boob[posn]==3 #break movpos_reportall -- 2.30.2