View Single Post
Old 15 March 2015, 15:39   #125
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 2,483
Not a bug report, but... in ide.cpp you have functions adide_encode_word() and adide_decode_word().
Code:
uae_u16 adide_decode_word(uae_u16 w)
{
	uae_u16 o = 0;

	if (w & 0x8000)
		o |= 0x0001;
	if (w & 0x0001)
		o |= 0x0002;

	if (w & 0x4000)
		o |= 0x0004;
	if (w & 0x0002)
		o |= 0x0008;

	if (w & 0x2000)
		o |= 0x0010;
	if (w & 0x0004)
		o |= 0x0020;

	if (w & 0x1000)
		o |= 0x0040;
	if (w & 0x0008)
		o |= 0x0080;

	if (w & 0x0800)
		o |= 0x0100;
	if (w & 0x0010)
		o |= 0x0200;

	if (w & 0x0400)
		o |= 0x0400;
	if (w & 0x0020)
		o |= 0x0800;

	if (w & 0x0200)
		o |= 0x1000;
	if (w & 0x0040)
		o |= 0x2000;

	if (w & 0x0100)
		o |= 0x4000;
	if (w & 0x0080)
		o |= 0x8000;

	return o;
}
That's fairly clear, but unless the compiler is very clever, having 16 if statements probably isn't the fastest way to do it (branch misprediction?). How about something like this as an alternative?
Code:
uae_u16 adide_decode_word(uae_u16 w)
{
    uae_u16 o = 0;
    for (uae_u8 i = 0; i < 8; i++) {
        o |= (w & 1<<i) << i+1;                // bit n -> bit 2n+1 for n=0..7
        o |= ((w & 1<<i+8) >> i+8) << 14-2*i;  // bit n -> bit 30-2n for n=8..15
    }
    return o;
}
mark_k is offline  
 
Page generated in 0.04706 seconds with 9 queries