Skip to contentSkip to conversation

meaningless #ifndef?

IDE Hugh Dickins 2 participants 3 messages Feb 20, 2001 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.21.0102201705280.11260-100000@alloc

#1 lore raw
Quoted 32 lines · Andre Hedrick
Quoted 14 lines · Pozsar Balazs

from drivers/ide/ide-features.c:

/*
* All hosts that use the 80c ribbon mus use!
*/
byte eighty_ninty_three (ide_drive_t *drive)

{
        return ((byte) ((HWIF(drive)->udma_four) &&
#ifndef CONFIG_IDEDMA_IVB
                        (drive->id->hw_config & 0x4000) &&
#endif /* CONFIG_IDEDMA_IVB */
                        (drive->id->hw_config & 0x6000)) ? 1 : 0);
}
Quoted 3 lines

If i see well, then this is always same whether CONFIG_IDEDMA_IVB is defined or not.
What's the clue?

(drive->id->hw_config & 0x4000)

	mask off 0x4000 for presence.
(drive->id->hw_config & 0x6000) 
	mask off 0x2000 ot 0x4000 for presence.

The first is true only if bit 14 is set.
The second is true if either bit 13 or 14 is set.

Togather they test for two bits.
The first test is exclusive to bit 14
The second test is inclusive of bits 13 and 14.

Quoted 7 lines

Because some older drives set only bit 13 for the device side cable-detect, then newer drives than these did a supported mode bit 14 and no bits 13, then others do both.

So in order to have a test that supports ATA-4/5/6 you have to allow users the option to disable the newer sense code that is only valid for ATA-5/6. It will get messier still.

Andre, please read through that code again, and through your reply. It seems to me that Poszar is absolutely right, and your reply is (once again) just saying "there's lots of confusion out there, so my code has to be confused too". Or do your &s and &&s behave differently from ours?

Hugh

#2 lore raw
In reply to a message not in the archive
Quoted 26 lines · Hugh Dickins
Quoted 19 lines
Quoted 15 lines

from drivers/ide/ide-features.c:

/*
* All hosts that use the 80c ribbon mus use!
*/
byte eighty_ninty_three (ide_drive_t *drive)

{
        return ((byte) ((HWIF(drive)->udma_four) &&
#ifndef CONFIG_IDEDMA_IVB
                        (drive->id->hw_config & 0x4000) &&
#endif /* CONFIG_IDEDMA_IVB */
                        (drive->id->hw_config & 0x6000)) ? 1 : 0);
}
Quoted 3 lines

If i see well, then this is always same whether CONFIG_IDEDMA_IVB is defined or not.
What's the clue?

Quoted 6 lines

The first is true only if bit 14 is set. The second is true if either bit 13 or 14 is set.

Togather they test for two bits.
The first test is exclusive to bit 14 The second test is inclusive of bits 13 and 14.

Quoted 5 lines

Andre, please read through that code again, and through your reply. It seems to me that Poszar is absolutely right, and your reply is (once again) just saying "there's lots of confusion out there, so my code has to be confused too". Or do your &s and &&s behave differently from ours?

Well, the code looks weird. However, it doesn't behave the same when CONFIG_IDEDMA_IVB is enabled or not. If it is not, normal case, it's just:

(drive->id->hw_config & 0x6000)

If CONFIG_IDEDMA_IVB is enabled, it boils down to:

(drive->id->hw_config & 0x4000)

because the second bit test includes the earlier test already only loosening it. Because of that, it's superfluous. And the code relies on the compiler to optimize it out.

If written like:

#ifndef CONFIG_IDEDMA_IVB
#define IDE_UDMA_MASK 0x4000
#else
#define IDE_UDMA_MASK 0x6000
#endif /* CONFIG_IDEDMA_IVB */

byte eighty_ninty_three (ide_drive_t *drive)

{       
        return HWIF(drive)->udma_four &&
		(drive->id->hw_config & IDE_UDMA_MASK);
}

it'd be probably somewhat clearer.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs
#3 lore raw
Quoted 16 lines · Vojtech Pavlik
Quoted 8 lines · Hugh Dickins
Quoted 8 lines
Quoted 8 lines

byte eighty_ninty_three (ide_drive_t *drive)

{
        return ((byte) ((HWIF(drive)->udma_four) &&
#ifndef CONFIG_IDEDMA_IVB
                        (drive->id->hw_config & 0x4000) &&
#endif /* CONFIG_IDEDMA_IVB */
                        (drive->id->hw_config & 0x6000)) ? 1 : 0);
}

Well, the code looks weird. However, it doesn't behave the same when CONFIG_IDEDMA_IVB is enabled or not. If it is not, normal case, it's just:

(drive->id->hw_config & 0x6000)

Quoted 7 lines

If CONFIG_IDEDMA_IVB is enabled, it boils down to:

(drive->id->hw_config & 0x4000)

because the second bit test includes the earlier test already only loosening it. Because of that, it's superfluous. And the code relies on the compiler to optimize it out.

Thank you for re-explaining this to me. Yes, you are right, I was wrong, I now admit my &s and &&s behave like yours, and I apologize to Andre!

Quoted 8 lines

If written like:

#ifndef CONFIG_IDEDMA_IVB
#define IDE_UDMA_MASK 0x4000
#else
#define IDE_UDMA_MASK 0x6000
#endif /* CONFIG_IDEDMA_IVB */

Quoted 7 lines

byte eighty_ninty_three (ide_drive_t *drive)

{       
        return HWIF(drive)->udma_four &&
		(drive->id->hw_config & IDE_UDMA_MASK);
}

it'd be probably somewhat clearer.

That would certainly have helped us!

Hugh