This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

Re: inline function containing static array omitted from output assembler


Franz Sirl:
> And? Where is the bug? GCC correctly optimizes away the body of a 
> non-terminating loop cause is has no side-effects. Or are you complaining 
> about the body not always being optimized away?

The original loop _did_ terminate. I guess I shouldn't have confused
matters by "simplifying" the code, anyway.

The original code is below. But first see how kfnd_hash() is still
obviously butchered:


	.file	"wake.c"
	.section	.rodata
	.align 32
	.type	table.0,@object
	.size	table.0,1024
table.0:
	[table contents snipped]
	.text
	.align 2
	.p2align 4,,15
globl kfnd_hash
	.type	kfnd_hash,@function
kfnd_hash:
	subl	$28, %esp
	movl	32(%esp), %eax
	movl	$-1453677400, (%esp)
	movl	$-1436835466, 4(%esp)
	leal	1456(%eax), %edx
	movl	$-1410442126, 8(%esp)
	movl	$-1401966499, 12(%esp)
	.p2align 4,,15
L2:
	cmpl	%edx, %eax
	je	.L15
	addl	$16, %eax
	jmp	.L2
L15:
	movl	$2, %eax
	.p2align 4,,15
L11:
	decl	%eax
	cmpl	$-1, %eax
	jne	.L11
	movl	(%esp), %eax
	movl	4(%esp), %edx
	addl	$28, %esp
	ret
Lfe1:
	.size	kfnd_hash,.Lfe1-kfnd_hash
	.ident	"GCC: (GNU) 3.1"

And here's the code:

#define DATALEN	1472
typedef unsigned long long u64;
typedef unsigned int u32;
typedef unsigned char u8;

static inline void round(u32 hash[4], const u32 block[4])
{
	static const u32 table[256] = {
		0x00f81c70, 0x012b5019, 0x022fe071, 0x03490f21, 0x04b66067, 0x055ea005, 0x06a6a3cc, 0x079a590d,
		0x08f96654, 0x095d0937, 0x0af79945, 0x0b6b8139, 0x0cef2ffd, 0x0d0fc3c3, 0x0e458a5a, 0x0f228ea7,
		0x10bf6703, 0x110aa5f6, 0x1247f44d, 0x133fa9a3, 0x146ad815, 0x15ccbf93, 0x1633090d, 0x170b5f9a,
		0x18fd8147, 0x19c67cfc, 0x1a9eb45f, 0x1bb08914, 0x1c976728, 0x1d59e3f4, 0x1e0dd6f1, 0x1f37e181,
		0x20964a18, 0x214c9448, 0x22033126, 0x2368381c, 0x24498c5c, 0x25060c24, 0x26fe2236, 0x27122030,
		0x2891093a, 0x2964cce0, 0x2aa72c51, 0x2b5f4e17, 0x2c063da9, 0x2d5e860f, 0x2e69ed46, 0x2f982750,
		0x30a379fd, 0x31126d0c, 0x3243b438, 0x33e05b85, 0x34dcd0cc, 0x353ce57e, 0x36ded8f5, 0x37bcc897,
		0x38639651, 0x398c689d, 0x3a7966de, 0x3bd36580, 0x3c78030d, 0x3d3248f7, 0x3e143cf1, 0x3fa2ccd8,
		0x40a2a349, 0x415ddfa9, 0x42cb8d8f, 0x430de42d, 0x444014fc, 0x450fcfb6, 0x46e7c867, 0x47f27018,
		0x48bdbe0f, 0x491d836a, 0x4a40b2de, 0x4b3b19cd, 0x4cd354af, 0x4d9b9d08, 0x4e663ed9, 0x4ffe63d1,
		0x50618020, 0x51151958, 0x523344a9, 0x535ec218, 0x5490af7d, 0x55a03de2, 0x56141fec, 0x572fd5bc,
		0x58916e8b, 0x59486808, 0x5aee7f87, 0x5b80f3ae, 0x5cc245cc, 0x5da2c7f3, 0x5e9c7767, 0x5f316dad,
		0x60bec152, 0x61f0b665, 0x629af2b9, 0x6361e47f, 0x64c53307, 0x65771c47, 0x6667dadb, 0x675ef540,
		0x683af629, 0x69b2e9ce, 0x6a2d81ae, 0x6bafd873, 0x6cf712e7, 0x6d59b5b5, 0x6e5a46ac, 0x6fc33ad6,
		0x7054a4ae, 0x71021c77, 0x72259a8d, 0x739dc182, 0x747d0614, 0x755313a3, 0x76dadac0, 0x775183dc,
		0x78e7ea16, 0x7928d46f, 0x7a6dd320, 0x7b673f3d, 0x7c6038d6, 0x7d262d75, 0x7e300371, 0x7fa68722,
		0x80c3c630, 0x8157f86d, 0x827c21ef, 0x832f679b, 0x84e23b7b, 0x858dcaae, 0x86941ee2, 0x879188fb,
		0x88f9c1b3, 0x8945e503, 0x8acd4cf9, 0x8b1dfde8, 0x8c45ec44, 0x8decce1d, 0x8e2f68d2, 0x8f8e9da7,
		0x90a44029, 0x91d16a20, 0x92114a97, 0x93bf5b7c, 0x945df27b, 0x95cc856a, 0x96ba5797, 0x97f58493,
		0x98eed52f, 0x99fdbbec, 0x9a43dbf4, 0x9b68afc3, 0x9c0f33b3, 0x9d666853, 0x9e852ccd, 0x9f780735,
		0xa05fac40, 0xa167a3c8, 0xa2a51095, 0xa38e3545, 0xa4f0c37f, 0xa5db57ab, 0xa6cd7b93, 0xa704441a,
		0xa8bfdcc8, 0xa925b7cd, 0xaa0d0c89, 0xaba6aa05, 0xac9e4866, 0xadeee5c1, 0xaecd44f9, 0xaf3def2f,
		0xb07e67d4, 0xb1e1a860, 0xb2a3c041, 0xb3bef652, 0xb49de7b0, 0xb51d95a9, 0xb6878586, 0xb7a372c2,
		0xb85f353a, 0xb902dea1, 0xba94e751, 0xbb40858f, 0xbcdaaf12, 0xbdf51351, 0xbe913ffb, 0xbf9d82cc,
		0xc06c3177, 0xc1103380, 0xc283b182, 0xc3a9fe79, 0xc43726df, 0xc51d5191, 0xc675ded0, 0xc7f786d7,
		0xc80974c8, 0xc9156928, 0xca90741c, 0xcbc97924, 0xcc87471c, 0xcd1994ba, 0xce46f4e9, 0xcf274185,
		0xd08836bc, 0xd11500d1, 0xd2a3747a, 0xd3e01536, 0xd46491a4, 0xd5ab1d23, 0xd66a9d3b, 0xd71fb7bb,
		0xd8efcf7b, 0xd9a50f58, 0xdafbaaf9, 0xdb67c2b9, 0xdc2ea882, 0xdd205b68, 0xde8090ce, 0xdf8502c0,
		0xe004977d, 0xe12476c0, 0xe2e11ae2, 0xe3029c96, 0xe4e0b47f, 0xe5248cdb, 0xe6c9d640, 0xe7e0a18e,
		0xe8581d4f, 0xe9edbec2, 0xea00dc51, 0xeb107d42, 0xec87fcef, 0xed5b1cc2, 0xee9fd1af, 0xefac7c02,
		0xf0d530d0, 0xf19f3be6, 0xf209c1ae, 0xf3e8effb, 0xf48849de, 0xf5186677, 0xf623435f, 0xf7793b06,
		0xf801680a, 0xf9d06ccf, 0xfad293cd, 0xfb14e1ad, 0xfccdf82a, 0xfd0ad221, 0xfe771f27, 0xff2e2250
	};

	hash[0] = (hash[0] ^ hash[3]) + block[0];
	hash[0] = hash[0] >> 8 ^ table[hash[0] & 0xff];
	hash[1] = (hash[1] ^ hash[0]) + block[1];
	hash[1] = hash[1] >> 8 ^ table[hash[1] & 0xff];
	hash[2] = (hash[2] ^ hash[1]) + block[2];
	hash[2] = hash[2] >> 8 ^ table[hash[2] & 0xff];
	hash[3] = (hash[3] ^ hash[2]) + block[3];
	hash[3] = hash[3] >> 8 ^ table[hash[3] & 0xff];
}

u64 kfnd_hash(const u8 data[DATALEN])
{
	u32 hash[4] = {0xa95aa4a8, 0xaa5ba176, 0xabee5c72, 0xac6fb05d};
	const u8 *p = data + DATALEN - 16;
	for (;; data += 16) {
		round(hash, (u32 *) data);
		if (data == p) {
			int i = 3;
			while (i--)
				round(hash, (u32 *) data);
			return *(u64 *)hash;
		}
	}
}


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