|
|
Subscribe / Log in / New account

Undefined behaviour

Undefined behaviour

Posted Sep 10, 2018 18:14 UTC (Mon) by Wol (subscriber, #4433)
In reply to: Undefined behaviour by jem
Parent article: C considered dangerous

As I heard it, it was undocumented BECAUSE it didn't work.

You mention SRA and SRL. Therefore you should have a matching SLA and SLL. The story as I heard it was that some programmers used that exact logic, worked out what the opcode for SLL should be, and discovered what I called "shift left and increment".

In other words, a perusal of the documentation led to people deducing a "missing" opcode, and when they tried it, it ALMOST did what was expected.

Cheers,
Wol


to post comments

Undefined behaviour

Posted Sep 10, 2018 19:17 UTC (Mon) by mgb (guest, #3226) [Link]

> You mention SRA and SRL. Therefore you should have a matching SLA and SLL.

How would you have expected the functionality of these hypothetical SLA and SLL to have differed?

Undefined behaviour

Posted Sep 10, 2018 22:28 UTC (Mon) by anselm (subscriber, #2796) [Link]

The main difference between an arithmetic shift to the right and a logical shift to the right is that the logical shift will make the MSB zero while the arithmetic shift will keep the MSB (the sign of a signed number) whatever it was before the shift. This doesn't make a huge amount of sense when shifting to the left, because the LSB in a signed number isn't special, so processor makers often didn't bother with arithmetic shifts to the left (especially with the simpler late-20th-century-vintage CPUs).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds