| 1 |
|
|---|
| 2 | Some notes on implementing bit-wise operations in CIVL:
|
|---|
| 3 |
|
|---|
| 4 | Read C11 6.2.6 on Representation of Types, esp. integer types.
|
|---|
| 5 |
|
|---|
| 6 | 6.5.7 Bitwise shift operators
|
|---|
| 7 |
|
|---|
| 8 | The integer promotions are performed on each of the operands.
|
|---|
| 9 | The type of the result is that of the promoted left operand.
|
|---|
| 10 | If the value of the right operand is negative or is
|
|---|
| 11 | greater than or equal to the width of the promoted left operand,
|
|---|
| 12 | the behavior is undefined.
|
|---|
| 13 |
|
|---|
| 14 | The result of E1 << E2 is E1 left-shifted E2 bit positions;
|
|---|
| 15 | vacated bits are filled with zeros. If E1 has an unsigned type,
|
|---|
| 16 | the value of the result is E1 * 2^E2, reduced modulo one more
|
|---|
| 17 | than the maximum value representable in the result type.
|
|---|
| 18 | If E1 has a signed type and nonnegative value, and E1 * 2^E2
|
|---|
| 19 | is representable in the result type, then that is the resulting
|
|---|
| 20 | value; otherwise, the behavior is undefined.
|
|---|
| 21 |
|
|---|
| 22 | The result of E1 >> E2 is E1 right-shifted E2 bit positions.
|
|---|
| 23 | If E1 has an unsigned type or if E1 has a signed type and a
|
|---|
| 24 | nonnegative value, the value of the result is the integral
|
|---|
| 25 | part of the quotient of E1 / 2E2. If E1 has a signed type
|
|---|
| 26 | and a negative value, the resulting value is
|
|---|
| 27 | implementation-defined.
|
|---|
| 28 |
|
|---|
| 29 | See 6.5.10--12 for the bit-wise and, inclusive or, exclusive or
|
|---|
| 30 | operations. But all it says is that these are the bit-wise
|
|---|
| 31 | operations.
|
|---|