ARM `CSET` condition encoding (as vs docu)

Viewed 241

TL;DR cset code generated by assembler uses different condition codes than ARM manual.


I do not understand how the conditions are encoded for the cset instruction.

I have troubles understanding why the assembler generates different binary code than what I would expect after looking at the ARM Architecture Reference Manual - ARMv8.

The GNU assembler on my pi3 generates following code for different cset checks (I confirmed that the code works as expected):

9a 9f 17 e0        cset    x0, eq  // eq = none
9a 9f 07 e0        cset    x0, ne  // ne = any
9a 9f b7 e0        cset    x0, ge  // ge = tcont
9a 9f a7 e0        cset    x0, lt  // lt = tstop
9a 9f d7 e0        cset    x0, gt
9a 9f c7 e0        cset    x0, le

The interesting part here are bit 12-15 (the 5th nibble from the left) it encodes the condition (cond), as shown in the manual:

CSET documentation from the ARM Architecture manual

Using the cset documentation and the assembler output one can extract following table:

+------+----------+
| cond | mnemonic |
|------+----------|
| 0001 | EQ       |
| 0000 | NE       |
| 1011 | GE       |
| 1010 | LT       |
| 1101 | GT       |
| 1100 | LE       |
+------+----------+

The confusion now starts when one looks at the condition codes in the ARM manual:

Condition encoding as stated in the ARM Architecture manual

They are the opposite!

+-----------------+----------+
|    ASSEMBLER    |  MANUAL  |
+------+----------+----------+
| cond | mnemonic | mnemonic |
|------+----------+----------|
| 0001 | EQ       | NE       |
| 0000 | NE       | EQ       |
| 1011 | GE       | LT       |
| 1010 | LT       | GE       |
| 1101 | GT       | LE       |
| 1100 | LE       | GT       |
+------+----------+----------+

Could someone please point out to me the 'obvious' error I am making?

0 Answers
Related