On ARM it’s ldrb (load register byte), and on RISC-V it’s lb (load byte).
Every decent compiler will turn booleans into words.
No compiler I know of does this. I think you might be getting confused because they’re loaded into registers which are machine-word sized. But in memory a bool is always one byte.
Internally it will still read a whole word. Because the CPU cannot read less than a word. And if you read the ARM article you linked, it literally says so.
Thus any compiler worth their salt will align all byte variables to words for faster memory access. Unless you specifically disable such behaviour. So yeah, RTFM :)
lol what. You can absolutely read one byte: https://godbolt.org/z/TeTch8Yhd
On ARM it’s
ldrb
(load register byte), and on RISC-V it’slb
(load byte).No compiler I know of does this. I think you might be getting confused because they’re loaded into registers which are machine-word sized. But in memory a
bool
is always one byte.Sorry, but you’re very confused here.
You said you can’t read one byte. I showed that you can. Where’s the confusion?
Internally it will still read a whole word. Because the CPU cannot read less than a word. And if you read the ARM article you linked, it literally says so.
Thus any compiler worth their salt will align all byte variables to words for faster memory access. Unless you specifically disable such behaviour. So yeah, RTFM :)
Wrong again. It depends on the CPU. They can absolutely read a single byte and they will do if you’re reading from non-idempotent memory.
If you’re reading from idempotent memory they won’t read a byte or a word. They’ll likely read a whole cache line (usually 64 bytes).
Where?
No they won’t because it isn’t faster. The CPU will read the whole cache line that contains the byte.
Well, I would but no manual says that because it’s wrong!