магический код
Jun. 3rd, 2003 03:30 amЗабавный комментарий в одном из файлов исходников пакета Judy:
// Test if Word has any of the 4 bytes == '\0':
//
// This arcane code takes advantage of the CPU having a fast barrel shifter and
// a carry bit. Doug stole this code from elsewhere, and we know it works, but
// we really can't explain why.
#define NOZEROBYTE(Word) \
((((((Word) - 0x01010101) | (Word)) ^ (Word)) & 0x80808080) ? 0 : 1)
Кто возьмётся объяснить? ;) У меня глаза слипаются и думать совершенно нет сил, я отправляюсь спать.
Update: Всё-таки подумал. Просто на самом деле. Но красиво.
// Test if Word has any of the 4 bytes == '\0':
//
// This arcane code takes advantage of the CPU having a fast barrel shifter and
// a carry bit. Doug stole this code from elsewhere, and we know it works, but
// we really can't explain why.
#define NOZEROBYTE(Word) \
((((((Word) - 0x01010101) | (Word)) ^ (Word)) & 0x80808080) ? 0 : 1)
Кто возьмётся объяснить? ;) У меня глаза слипаются и думать совершенно нет сил, я отправляюсь спать.
Update: Всё-таки подумал. Просто на самом деле. Но красиво.
no subject
Date: 2003-06-03 02:02 pm (UTC)if ( LEAST_BIT(x) > LEAST_BIT(y) )
//bla-bla-bla
no subject
Date: 2003-06-03 10:05 pm (UTC)