Jump to content
Sign in to follow this  
djulien

Extraneous Instructions With Chained Bit Set

Recommended Posts

Bug description:

Unneeded extra instructions and a temp are being generated for a chained bit set. See sample code below.

 

#include <system.h>

#define TRUE  1

volatile unsigned char var1, var2;
#define bit1  var2.1
#define bit2  var2.2

inline void test(void)
{
if (var1 == 0xaa) bit1 = bit2 = TRUE;
}

void main(void)
{
test();
}

 

code generated for test():

MOVF gbl_var1, W
XORLW 0xAA
BTFSS STATUS,Z ;//this compare is correct
RETURN
;//okay until here

CLRF CompTempVar560
INCF CompTempVar560, F  ;//this temp is not needed
BSF gbl_var2,2 ;//this instruction is correct
BTFSC CompTempVar560,0 ;//this bit test is not needed; RHS was a const
BSF gbl_var2,1  ;//this instruction is correct
BTFSS CompTempVar560,0 ;//this bit test is also not needed
BCF gbl_var2,1;  //this instruction not needed
RETURN

The temp is not needed because the RHS was a const.

The first bit test on the temp is not needed.

The second bit test is alse inefficient; rather than "btfsc, bsf, btfss, bcf" it should have been "bsf, btfss, bcf" (if it had been needed at all).

 

Expected behaviour:

1. Don't use a temp.

2. Eliminate (or at least reduce) the number of bit tests (none were needed in this case).

 

Is the problem 100% reproduceable:

yes

 

Compiler:

BoostC

 

Compiler version:

7.10 (I didn't test prior to that)

 

Target device:

PIC16F1827, '1823, '688, etc.

 

OS:

Windows XP

 

don

Edited by djulien

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×