1

I observe that ARM v6 and later is bi-endian. Does the setend instruction (link) change the byte-order, the bit-order, or both?

I'm working on a Pixel C, and I have input data that is bitwise little-endian and bytewise big-endian, and I'd like to just be able to work with that directly, but I don't suppose it's possible. I guess that the ARM CPU defaults to little-endian for both bit-order and byte-order. Is that correct?

TMI:

I'm pulling an audio stream from a USB device. It arrives as 16-bit values, with bits in the order 89abcdef01234567 (8 most significant bits, followed by 8 least significant bits). If I try to do any arithmetic on these shorts, the CPU interprets the values incorrectly; it is using the bit order 01234556789abcdef.

To be clear, I do not want to change the bit order; I do want to change the byte order.

JellicleCat
  • 28,480
  • 24
  • 109
  • 162
  • In what instructions do you specify a bit number? – Jonathon Reinhart Feb 23 '17 at 23:23
  • 1
    There is no such thing as "bitwise endianness". – EOF Feb 23 '17 at 23:34
  • ARM has been bi-endian since ARMv4 at least not something that started armv6. Armv4 and 5 are BE-32, word invariant. armv6 and newer are BE-8 byte invariant. So for BE32 if you do a 32 bit access you get the same bits big or little. for BE8 if you do a byte read of a specific address you get the same byte big or little (which implies that halfwords and words byte swap). – old_timer Feb 24 '17 at 00:54
  • bi-endian is this horrible marketing term everyone is using, doesnt mean anything useful. there is the native endianness for a platform and the strange one and sometimes you can get the strange one to work or in the case of arm you can switch do something then switch back if you want to avoid a single byteswap instruction. three instructions instead of two. – old_timer Feb 24 '17 at 00:56
  • ARM is by default little endian and bit 0 is the least significant bit. – old_timer Feb 24 '17 at 00:56
  • 1
    there is bitwise endianness in the sense that some processors define bit 0 as the most significant bit (ethernet does this too as well as byte 0 being the most significant byte) and some bit 0 is the least significant bit. I dont know of a processor that does both, but if you buy a xilinx chip with the PPC inside you have this bit endianness nightmare to deal with as everything else bit 0 is the least significant, and/or the languages define it that way (VHDL/Verilog). – old_timer Feb 24 '17 at 00:59
  • If your bit-banging your input one bit at a time then you just need to put in the least-significant bit of the input into the least-significant bit of each byte and so on for the rest of the bits. If some device is assembling the input bits into bytes then it needs to put bits in the right order and chances are it will if it's designed to work with ARM CPUs. In any case SETEND isn't going to help you with this. You also shouldn't use it: http://stackoverflow.com/questions/28725421/is-it-possible-to-change-endianness-mid-execution-on-arm-android-linux – Ross Ridge Feb 24 '17 at 02:30
  • @old_timer : Thanks. I'm not trying to perform bitwise operations. I've updated my question. I don't want to change the order of bits, just the order of bytes. – JellicleCat Feb 28 '17 at 18:53
  • @RossRidge : Thanks. I'm not bit-banging; I'm using tinyalsa. I've updated my question. Does `setend` apply to my problem, then? – JellicleCat Feb 28 '17 at 18:55
  • the armv6 is be-8 so if you swich to big endian (setend) do the load, and switch back it will byte swap. I think you can just do a load and then use the byteswap instruction and save an instruction. – old_timer Feb 28 '17 at 19:31
  • the instruction in question is rev so like a function rev r0,r0; bx lr will byteswap what you feed it or ldr r0,[r0]; rev r0,r0; bx lr can use it in front of store. – old_timer Feb 28 '17 at 19:34
  • the arm arm has an aserisk on armv6* but not on 7 so not sure what that means is that all the armv6's or all but some go figure out what we mean...easier to just experiment and see if it works or gets an undefined instruction. – old_timer Feb 28 '17 at 19:35

0 Answers0