Is it a bug? control flow instruction of PRU does not make right comparison with negative number

I am trying to use QBLT to compare two numbers and found out when one number is negative, the QBLT logic does not seem make right comparison. In the following code, before QBLT, r3 =1-4 = -3, and r2 = 10, so r3 < r2, then the code should execute MOV r3, -1. However, when I run this macro, r3 is set to 1.
Anyone notices this issue? Any idea how to fix it?

.macro LOGTEST
MOV r7, 1
MOV r8, 4
SUB r3, r7, r8
MOV r2, 10
QBLT LESS, r2, r3
MOV r3, 10
JMP XXX
LESS:
MOV r3, -1
XXX:
.endm

I am trying to use QBLT to compare two numbers and found out when one number is negative, the QBLT logic does not seem make right comparison. In the following code, before QBLT, r3 =1-4 = -3, and r2 = 10, so r3 < r2, then the code should execute MOV r3, -1. However, when I run this macro, r3 is set to 1.

Anyone notices this issue? Any idea how to fix it?

I looked at the description and couldn’t find the specification, but perhaps the comparison treats the numbers as unsigned; the bit pattern of negative 2-complement number, interpreted as unsigned results in large numbers, so the comparison would come out the way you observe.

This is a known issue, the PRU supports *ONLY* unsigned integers.

Write your code properly for unsigned data types and you will not have
any problems.

Thank you Charles. Is it a known issue only for control flow logic? When I use MOV command to save a negative number (MOV r1, -1), then save r1 into shared RAM, then into a txt file, I do see -1 is saved into the txt file correctly.

Thank you Charles. Is it a known issue only for control flow logic? When I
use MOV command to save a negative number (MOV r1, -1), then save r1 into
shared RAM, then into a txt file, I do see -1 is saved into the txt file
correctly.

This always works but has nothing to do with the PRU.

You can substract a larger value from an unsigned value, which then
gets wrapped around; you can then _interpret_ the bit-pattern as a
signed value in two-complement and get the expected negative number.
This is what you did in this case.
This is just a property of how the two-complement encoding works.

-h

Thank you Henner. Since we can only interpret the subtraction result correctly when we know its sign, we always need first compare a and b (assuming a and b are positive and we do a-b) to know which is greater before we do a subtraction.

lingwei