From 66f1f829431bb6b8b6da47d6bb86c66d9c35b240 Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 20 Jan 2012 15:54:43 +0000 Subject: [PATCH] Masking a bit field is unnecessary if there was no shift operation or if the shift operation shifted just zeroes into the value. git-svn-id: svn://svn.cc65.org/cc65/trunk@5412 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/loadexpr.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc65/loadexpr.c b/src/cc65/loadexpr.c index 4802dbb2b..99c5684d1 100644 --- a/src/cc65/loadexpr.c +++ b/src/cc65/loadexpr.c @@ -162,8 +162,11 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr) unsigned F = CF_INT | CF_UNSIGNED | CF_CONST | (Flags & CF_TEST); /* Shift right by the bit offset */ g_asr (F, Expr->BitOffs); - /* And by the width */ - g_and (F, (0x0001U << Expr->BitWidth) - 1U); + /* And by the width if the field doesn't end on an int boundary */ + if (Expr->BitOffs + Expr->BitWidth != CHAR_BITS && + Expr->BitOffs + Expr->BitWidth != INT_BITS) { + g_and (F, (0x0001U << Expr->BitWidth) - 1U); + } } /* Expression was tested */