Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsh!gls From: gls@cbnewsh.att.com (Col. G. L. Sicherman) Newsgroups: comp.bugs.sys5 Subject: Re: crufty memcmp on 386 Message-ID: <1990Nov15.163550.27015@cbnewsh.att.com> Date: 15 Nov 90 16:35:50 GMT References: <1990Nov12.173812.3227@cbnewsh.att.com> <1990Nov13.182133.27748@loft386.uucp> Distribution: na Organization: AT&T Bell Laboratories Lines: 48 In <1990Nov13.182133.27748@loft386.uucp>, dpi@loft386.uucp writes: > > I can't make the original fail. Could you provide a short code segment > that will display the claimed behavior? If you can make AT&T's fail, > I would like to know if mine fails also. Sure. Here are my test program and what came out of it: REPEAT BY: Compile this with cc and run it. main() { long a[4]; int i, j; int memcmp(); a[0] = 0x10000000; a[1] = 0x50000000; a[2] = 0x90000000; a[3] = 0xd0000000; for (i=0; i<4; i++) for (j=0; j<4; j++) if (i!=j) printf("memcmp(%lx,%lx,4) is %lx\n", a[i], a[j], memcmp(a+i,a+j, 4)); } THE DAMNING EVIDENCE: memcmp(10000000,50000000,4) is ffff8720 memcmp(10000000,90000000,4) is ffff8320 memcmp(10000000,d0000000,4) is 320 memcmp(50000000,10000000,4) is 224 memcmp(50000000,90000000,4) is ffff8724 memcmp(50000000,d0000000,4) is ffff8324 memcmp(90000000,10000000,4) is ffff8228 memcmp(90000000,50000000,4) is 228 memcmp(90000000,d0000000,4) is ffff8728 memcmp(d0000000,10000000,4) is ffff862c memcmp(d0000000,50000000,4) is ffff822c memcmp(d0000000,90000000,4) is 22c This gives 0x10 < 0x90 < 0x10, and 0x10 < 0x50 < 0x90 < 0xd0 < 0x10. Since you too use LAHF and CWTL, your code makes the same mistake -- it uses the SF bit instead of the CF bit. How did you test it? -- G. L. Sicherman gls@odyssey.att.COM