🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.bugs
Article #439

8086 family CPU bug

#439
From: Hugh Redelmeier
Date: Fri, 05 Jul 1985 12:34
31 lines
1921 bytes
All 8086 manuals I have read say that shift instructions set
the flags to reflect the value of the result.  All the chips
that I have tested (8086, 8088, 80186) do not set the flags
if the shift count is zero.  I discovered this when the following
C code gave the wrong answer (under XENIX 2.1 -- not their
fault though) (this code is from memory, so it may be slightly
inaccurate):

main() {
	register int i, j;
	i = 0;
	j = 1; j += 1;	/* clear Z flag */
	if (i << i) /* shift of 0 by 0 should set Z flag, but doesn't */
		printf("WRONG!\n");
	}

[Even if the predicate is written more cleanly as (i<<i != 0), the
compiler is smart enough to generate the same code.  The use of i
instead of the literal 0 is to prevent compile-time evaluation.]

At the machine language level what is going on?  The key
instruction is a shift with its count in a register.  This
count is 0.  The shift does not change the flags from their
previous value.

Cure(idealistic): INTEL et al should fix the chips (and give users new ones!)
Cure(imaginable): INTEL et al should revise the manuals; every compiler that
	is affected should be updated (and users given new ones); every
	program compiled using the previous compiler should be re-compiled;
	every assembler program should be combed for this problem.
unCure(sad but true): users should be aware of this problem
Technical Details
Message-ID: <1190@hcrvx1.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!hcrvax!hcrvx1!hugh

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site hcrvx1.UUCP
Path: arc1-ca.pugleaf.net!utzoo!hcrvax!hcrvx1!hugh
From: hugh@hcrvx1.UUCP (Hugh Redelmeier)
Newsgroups: net.bugs,net.micro,net.micro.pc
Subject: 8086 family CPU bug
Message-ID: <1190@hcrvx1.UUCP>
Date: Fri, 5-Jul-85 08:34:56 EDT
Article-I.D.: hcrvx1.1190
Posted: Fri Jul  5 08:34:56 1985
Date-Received: Sat, 6-Jul-85 04:11:14 EDT
Organization: Human Computing Resources, Toronto
Lines: 31
Summary: shift by zero does not set flags