Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: Karlos on August 28, 2004, 06:17:11 PM

Title: Best compiler warning ever!
Post by: Karlos on August 28, 2004, 06:17:11 PM
Hi,

I'm just working on some strain test code in vbcc and I ran into what I have to say is the funniest warning I ever saw.

Warning 175 in function "memset64" this code is weird.

It must be the time of day or something but that had me rolling :lol:
Title: Re: Best compiler warning ever!
Post by: Thomas on August 28, 2004, 11:40:01 PM
Quote

this code is weird


 :roflmao:  :roflmao:  :roflmao:  :roflmao:
Title: Re: Best compiler warning ever!
Post by: EdKing on August 29, 2004, 12:57:55 PM
Quote

Warning 175 in function "memset64" this code is weird.



I got a chuckle out of that one.

 :lol:

Ed King
Title: Re: Best compiler warning ever!
Post by: Karlos on August 29, 2004, 01:13:55 PM
For the curious, the code in question was a duff's device style memset() implementation that writes 64-bit aligned data as doubles (on PPC this is achievable):

Code: [Select]
[size=small]
void memset64(void* p, int c, size_t len)
{
/* convert c to 32-bit repeated value */
c &= 0x000000FF;
c |= c<<8;
c |= c<<16;

/*
Don't bother going into the duff loop unless we have
at least 32 bytes to set
*/
if (len>32)
{
union {
float64 f;
uint32 u[2];
} data64;

/*
Our code only wants to write 64-bit data to 64-bit
aligned addresses. If we aren't on such a boundary,
bytecopy up to the next one.
*/

uint32 bytesBefore = 8-(((uint32)p)&7UL);
if (bytesBefore<8) {
/* seems vbcc doesn't like *((uint8*)p)++ = x; */
register uint8* pC = (uint8*)p;
bytesBefore = 1 + (bytesBefore & 7UL);
while (--bytesBefore) {
*pC++ = c;
}
p = pC;
}

/*
Now we make a 64-bit value that we can copy to a
register (a float register on PPC) and write out
to the aligned area in our duff loop.
*/

data64.u[1] = data64.u[0] = c;
{
/* seems vbcc doesn't like *((float64*)p)++ = x; */
register float64* pF = (float64*)p;
register float64 f = data64.f;
register uint32 b = (len+127)>>7; /* number of blocks */
switch((len>>3)&15UL) {
case 0: do { *pF++ = f;
case 15: *pF++ = f;
case 14: *pF++ = f;
case 13: *pF++ = f;
case 12: *pF++ = f;
case 11: *pF++ = f;
case 10: *pF++ = f;
case 9: *pF++ = f;
case 8: *pF++ = f;
case 7: *pF++ = f;
case 6: *pF++ = f;
case 5: *pF++ = f;
case 4: *pF++ = f;
case 3: *pF++ = f;
case 2: *pF++ = f;
case 1: *pF++ = f;
} while (--b);
}
p = pF;
}

/* adjust length for any trailing bytes after the aligned area */
len &= 7UL;
}

/* handle any trailing bytes (or the entire thing if len was < 32) */
{
/* seems vbcc doesn't like *((uint8*)p)++ = x; */
register uint8* pC = (uint8*)p;
len++;
while(--len)
{
*pC++ = c;
}
}
}

[/size]
Title: Re: Best compiler warning ever!
Post by: Karlos on August 29, 2004, 01:23:14 PM
@self

I mean apart from defining blocks of code that aren't part of an if/else/loop structure - which I only do to keep variable scoping as tight as possible - it's not that weird, is it?