Patrick.Schluter at bbox.fr
Mon Jan 7 20:41:32 UTC 2019
On Monday, 7 January 2019 at 20:28:21 UTC, H. S. Teoh wrote:
> On Mon, Jan 07, 2019 at 08:06:17PM +0000, Patrick Schluter via
> Digitalmars-d-learn wrote:
>> On Monday, 7 January 2019 at 18:56:17 UTC, H. S. Teoh wrote:
>> > On Mon, Jan 07, 2019 at 06:42:13PM +0000, Patrick Schluter
>> > via Digitalmars-d-learn wrote:
>> > > byte b = nibble | ((nibble & 0x40)?0xF0:0);
>> > This is equivalent to doing a bit comparison (implied by the
>> > ? operator). You can do it without a branch:
>> > cast(byte)(nibble << 4) >> 4
>> > will use the natural sign extension of a (signed) byte to
>> > "stretch" the upper bit. It just takes 2-3 CPU instructions.
>> Yeah, my bit-fiddle-fu goes back to pre-barrel-shifter days.
>> Up to 32 bit processors, shifting was more expensive than
> Really? Haha, never knew that, even though I date all the way
> back to writing assembly on 8-bit processors. :-D
Most of my career was programming for 80186. Shifting by one was
2 cycles in register and 15 in memory. Shifting by 4, 9 cycles
for regs/21 for mem. And 80186 was a fast shifter compared to
8088/86 or 68000 (8+2n cycles).
More information about the Digitalmars-d-learn