You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the logical shift left operator on the ULP coprocessor with a shift value (imm or Rsrc2) of more than 15, the shift suddenly becomes circular, even though a shift of 15 wasn't circular.
Here is the output from a quick MWE I wrote:
I (1821) lsh-test: [app_main]: bits: 0000001000100110
I (1821) lsh-test: [app_main]: Left shift << 8: 0010011000000000
I (1821) lsh-test: [app_main]: Left shift << 15: 0000000000000000
I (1821) lsh-test: [app_main]: Left shift << 16: 0000001000100110
I (1831) lsh-test: [app_main]: Left shift << 17: 0000010001001100
I (1841) lsh-test: [app_main]: Left shift << 32: 0000001000100110
The documentation also doesn't mention the circularity of the shift operand anywhere, so I'd assumed it works the same that it does in C or C++ (non-circular). So this behavior is strange and undocumented.
Expected Behavior
Logical shift operator should be either circular, or not (preferably non-circular), so that the output above would look like this:
I (1821) lsh-test: [app_main]: bits: 0000001000100110
I (1821) lsh-test: [app_main]: Left shift << 8: 0010011000000000
I (1821) lsh-test: [app_main]: Left shift << 15: 0000000000000000
I (1821) lsh-test: [app_main]: Left shift << 16: 0000000000000000
I (1831) lsh-test: [app_main]: Left shift << 17: 0000000000000000
I (1841) lsh-test: [app_main]: Left shift << 32: 0000000000000000
Actual Behavior
The left shift operator acts as if once the value 16 is reached, it resorts to not shifting at all, as if some kind of modulo 16 (%16) operation was taking place in the background.
github-actionsbot
changed the title
ULP bitshift operator starts being circular, when shifting by more than 16 bits
ULP bitshift operator starts being circular, when shifting by more than 16 bits (IDFGH-7237)
Apr 25, 2022
Hi @niraami,
Thank you for pointing this out. We will update the documentation to mention this behavior!
The documentation also doesn't mention the circularity of the shift operand anywhere, so I'd assumed it works the same that it does in C or C++ (non-circular). So this behavior is strange and undocumented.
For what it's worth, neither C nor C++ standards guarantee any defined behavior when doing a left shift by an amount larger than the width of the type.
The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined
Environment
Problem Description
When using the logical shift left operator on the ULP coprocessor with a shift value (imm or Rsrc2) of more than 15, the shift suddenly becomes circular, even though a shift of 15 wasn't circular.
Here is the output from a quick MWE I wrote:
The documentation also doesn't mention the circularity of the shift operand anywhere, so I'd assumed it works the same that it does in C or C++ (non-circular). So this behavior is strange and undocumented.
Expected Behavior
Logical shift operator should be either circular, or not (preferably non-circular), so that the output above would look like this:
Actual Behavior
The left shift operator acts as if once the value 16 is reached, it resorts to not shifting at all, as if some kind of modulo 16 (
%16
) operation was taking place in the background.Steps to reproduce
I've created a repository with an MWE that you can just clone and run here: https://github.com/niraami/esp32-lsh-bug
Code to reproduce this issue
https://gist.github.com/niraami/30b5cb6782acd4ca86f903570d133d58
Debug Logs
Log attached above in Problem Description
Other items if possible
sdkconfig.txt
elf.zip
The text was updated successfully, but these errors were encountered: