This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

i386 notice_update_cc belt and suspenders patch


Tracing the operation of NOTICE_UPDATE_CC when compiling
the following snippet of code on i386 seems to show up a
weakness in notice_update_cc:

  int a = 1;

  int c = 1;
  int d = 0;

  main ()
    {
    int e;
    int f;
  
    e = c + d;
    f = ffs(a);

    if ( f )
      printf("e = %d  f = %d\n", e, f);

    exit(0);
    }

The relevant assembler is:

	movl _d,%eax
	movl _c,%edx
	addl %eax,%edx	; cc_status.value1 = %eax + %edx
			; cc_status.value2 = %edx

	bsfl _a,%eax	; cc_status.value1 = mem _a
			; cc_status.value2 = %edx

	jne L2
	movl $-1,%eax	; CC_INIT
L2:
	incl %eax

The only flag defined after executing bsf is Z which contains the
result from bsf.  I believe that cc_status.value2 should be cleared
in order to be technically correct.

ChangeLog:

Sat Jun  6 16:36:11 EDT 1998  John Wehle  (john@feith.com)

	* i386.c (notice_update_cc): Clear cc_status.value2 in the
	case of UNSPEC 5 (bsf).

Enjoy!

-- John Wehle
------------------8<------------------------8<------------------------
*** gcc/config/i386/i386.c.ORIGINAL	Thu May 21 15:12:19 1998
--- gcc/config/i386/i386.c	Sat Jun  6 16:22:33 1998
***************
*** 3667,3672 ****
--- 3667,3673 ----
  		cc_status.flags
  		  = CC_NOT_POSITIVE | CC_NOT_NEGATIVE | CC_NO_OVERFLOW;
  		cc_status.value1 = XVECEXP (SET_SRC (exp), 0, 0);
+ 		cc_status.value2 = 0;
  		break;
  	      }
  	    /* FALLTHRU */
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]