| Type | Size (Bytes) |
|---|---|
| char | 1 |
| short | 2 |
| int | 4 |
| long | 8 |
| long long | 8 |
| void * | 8 |
| float | 4 |
| double | 8 |
| long double | 16 |
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/40cb2678-1f52-4b34-a97d-8eff74846c47%40groups.riscv.org.
> On 26 Jul 2017, at 10:11 AM, Cesar Eduardo Barros <ces...@cesarb.eti.br> wrote:
>
> Em 25-07-2017 17:44, Michael Clark escreveu:
>> Hi Rogier,
>>
>> What is interesting, in addition to the storage being equal to char and
>> the value being 0 or 1, it appears that on x86-64 ABI that bits[63:8] of
>> the register are undefined, as the _Bool test is just for non-zero byte,
>> ignoring the upper bits in the register. On x86 SETcc only sets the low
>> 8-bits, so the rest of the register may have contents from another
>> operation:
>
> On RISC-V, SLT/SLTU/SLTI/SLTIU/LB/LBU all set the whole register, so it makes sense and is simpler to require the whole register to be defined when used to store a _Bool. That is: a _Bool in a register is whatever SLT/SLTU/SLTI/SLTIU would set it to. A _Bool in memory is the lowest byte of a _Bool in a register. Any other value is invalid.
Agree. I was mostly pointing out how _Bool values in registers are implementation defined, and thus should be defined in the ABI doc, given Rogier spotted its absence.
>> Note: while true is defined to be 1 (rewriting other values to 1), the
>> code is guarded and tends to test either zero or not zero, so a
>> non-canonical true (not 0 and not 1) could be true.
>
> A "non-canonical true" could also be false.
Or worse, it could make the program jump into nowhere (for instance, if used to index into a jump table). There’s a reason the compiler converts a cast to _Bool into a "snez" (sltu with x0) instruction.
On 27 Jul 2017, at 8:42 PM, Rogier Brussee <rogier....@gmail.com> wrote:
Op woensdag 26 juli 2017 01:23:29 UTC+2 schreef michaeljclark:
> On 26 Jul 2017, at 10:11 AM, Cesar Eduardo Barros <ces...@cesarb.eti.br> wrote:
>
> Em 25-07-2017 17:44, Michael Clark escreveu:
>> Hi Rogier,
>>
>> What is interesting, in addition to the storage being equal to char and
>> the value being 0 or 1, it appears that on x86-64 ABI that bits[63:8] of
>> the register are undefined, as the _Bool test is just for non-zero byte,
>> ignoring the upper bits in the register. On x86 SETcc only sets the low
>> 8-bits, so the rest of the register may have contents from another
>> operation:
>
> On RISC-V, SLT/SLTU/SLTI/SLTIU/LB/LBU all set the whole register, so it makes sense and is simpler to require the whole register to be defined when used to store a _Bool. That is: a _Bool in a register is whatever SLT/SLTU/SLTI/SLTIU would set it to. A _Bool in memory is the lowest byte of a _Bool in a register. Any other value is invalid.
Agree. I was mostly pointing out how _Bool values in registers are implementation defined, and thus should be defined in the ABI doc, given Rogier spotted its absence.Not just in registers: the ABI COULD define that any nonzero byte stored in a _Bool should be interpreted as true (I am not arguing to do that just pointing out that this is also a possibility)In registers it is not even clear if the MSB of the register should be zeroThe typical example is_Bool is_nullptr(const void* p){return p;}should that compile toretorsnez a0 a0ret
and a related question is how to compile_Bool are_nullptrs(const void* p. const void* q){_Bool a = is_nullptr(p);_Bool b = is_nullptr(q);return a && b;}Should that bejal is_nullptrmv a5, a0mv a0, a1jal is_nullptrand a0 a0 a5retorjal is_nullptrsnez a5, a0mv a0, a1jal is_nullptrsnez a0 a0and a0 a0 a5ret
[snip]>> Note: while true is defined to be 1 (rewriting other values to 1), the
>> code is guarded and tends to test either zero or not zero, so a
>> non-canonical true (not 0 and not 1) could be true.
>
> A "non-canonical true" could also be false.?????Or worse, it could make the program jump into nowhere (for instance, if used to index into a jump table). There’s a reason the compiler converts a cast to _Bool into a "snez" (sltu with x0) instruction.
So It seems that the compiler normalises a _Bool to 0 or 1 (which is what the comparison instructions give) but optimises the normalisation away if the compiler can prove it is superfluous because it is only used to test for nonzero-ness in a branch instruction. FWIW that seems sane to me, and might as well be documented.What the C standard says and what implementations define are different things. On X86 0x1 through 0xff are true. i.e. all non-zero char values. 0x100 might not be safe on x86.
> Yeah, most of the time you'll be comparing a _Bool with zero, but that's only because it's so convenient due to the x0 register. Don't count on it.
On RISC-V I believe we can count on non-zero being true, based on what has just been stated. The only completely safe thing for the compiler to emit snez, which is what it does. GCC and LLVM seem to be consistent in this regard as they test for non zero on other architectures (however with 8-bit width on x86).
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/2a3cdace-d5d1-4230-8bee-3873b04719b7%40groups.riscv.org.
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/2a3cdace-d5d1-4230-8bee-3873b04719b7%40groups.riscv.org.
--
You received this message because you are subscribed to the Google Groups "RISC-V ISA Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+unsubscribe@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/89F4AC37-70B4-4975-AF45-7751D478F93F%40mac.com.
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/1A5BF383-C210-4D84-9B94-A0DE07C61379%40mac.com.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/182F65BE-157E-4F5B-8533-CAB8F7A758CD%40mac.com.
On 28 Jul 2017, at 9:33 AM, Michael Clark <michae...@mac.com> wrote:
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/182F65BE-157E-4F5B-8533-CAB8F7A758CD%40mac.com.
The problem with this is that the user-level ISA is already stabilized with SLT[I][U] setting the destination register to 1 or 0. As a result, using anything other than 1 as the canonical true seems very suboptimal.
If people need to turn a boolean into a bitmask, then they can use NEG.
> > email to isa-dev+u...@groups.riscv.org.
> > To post to this group, send email to isa...@groups.riscv.org.
> > Visit this group at https://groups.google.com/a/
> > groups.riscv.org/group/isa-dev/.
> > To view this discussion on the web visit https://groups.google.com/a/
> > groups.riscv.org/d/msgid/isa-dev/89F4AC37-70B4-4975-AF45-
> > 7751D478F93F%40mac.com
> > <https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/89F4AC37-70B
> > 4-4975-AF45-7751D478F93F%40mac.com?utm_medium=email&utm_source=footer> .
To unsubscribe from this group and stop receiving emails from it, send an email to isa-dev+u...@groups.riscv.org.
To post to this group, send email to isa...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/isa-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/89F4AC37-70B4-4975-AF45-7751D478F93F%40mac.com.
On 31 Jul 2017, at 9:44 PM, Rogier Brussee <rogier....@gmail.com> wrote:
Op donderdag 27 juli 2017 23:33:28 UTC+2 schreef michaeljclark:The functions select_1() and select_2 contain a bug.long select_1(long c, long y, long z){{long x = -(c > 0);return (-x&y) | ((~x)&z);}e.g select_1 that should belong x = -(c > 0);return (x&y) | ((~x)&z);i.e. there is a minus sign to much.The compiler explorer is great though! with the minus sign fixed we get
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/isa-dev/fb0c387a-7bb2-4288-9579-97125ac44b0b%40groups.riscv.org.