## Orc Opcodes

Orc Opcodes — Description of Opcodes

## Orc Opcodes

Opcodes only work with variables of a particular size. In the table below, destination and source indicate the size of the destination and source operands, in bytes. In general, opcodes have a suffix indicating the sizes, "b" for 1-byte operations, "w" for 2-byte operations, and "l" for 4-byte operations. If the source and destination have different sizes, the source size suffix is listed first, then the destination suffix. For example, converting a 1-byte variable to 2-byte can be performed using the "convsbw" opcode.

Signed, unsigned, and saturating operations are indicated by the letters "s", "u", and "s". If signed or unsigned is not indicated, it generally means that the signedness is not relevant to the definition of the opcode, and that the operation on signed or unsigned values will give the same result.

The "select" opcodes divide the bits in the source value into two halves. For "select0", the half that is first in memory order is selected, and the latter half for "select1". In other words, "convwb" is the same as "select0wb" on little-endian systems, and "select1wb" on big-endian systems.

The "merge" opcodes take two values and put them together in memory order.

Accumulating opcodes require an accumulator variable as the destination. Accumulating opcodes start with "acc". These opcodes sum the source values over the entire array, and can be read from the OrcExecutor structure after an execution of an Orc program.

Shift opcodes only work with constants or parameters as the second source value.

For more precise understanding of operations, it is recommended to compile a program for the C target and examine the resulting C source code.

Table 1. Table of Opcodes

opcode | destination | source 1 | source 2 | description | pseudo code
--- | --- | --- | --- | --- | ---
absb | 1 | 1 |  | absolute value | (a < 0) ? -a : a
addb | 1 | 1 | 1 | add | a + b
addssb | 1 | 1 | 1 | add with signed saturate | clamp(a + b)
addusb | 1 | 1 | 1 | add with unsigned saturate | clamp(a + b)
andb | 1 | 1 | 1 | bitwise AND | a & b
andnb | 1 | 1 | 1 | bitwise AND NOT | a & (~b)
avgsb | 1 | 1 | 1 | signed average | (a + b + 1)>>1
avgub | 1 | 1 | 1 | unsigned average | (a + b + 1)>>1
cmpeqb | 1 | 1 | 1 | compare equal | (a == b) ? (~0) : 0
cmpgtsb | 1 | 1 | 1 | compare greater than | (a > b) ? (~0) : 0
copyb | 1 | 1 |  | copy | a
maxsb | 1 | 1 | 1 | signed maximum | (a > b) ? a : b
maxub | 1 | 1 | 1 | unsigned maximum | (a > b) ? a : b
minsb | 1 | 1 | 1 | signed minimum | (a < b) ? a : b
minub | 1 | 1 | 1 | unsigned minimum | (a < b) ? a : b
mullb | 1 | 1 | 1 | low bits of multiply | a * b
mulhsb | 1 | 1 | 1 | high bits of signed multiply | (a * b) >> 8
mulhub | 1 | 1 | 1 | high bits of unsigned multiply | (a * b) >> 8
orb | 1 | 1 | 1 | bitwise or | a | b
shlb | 1 | 1 | 1 | shift left | a << b
shrsb | 1 | 1 | 1 | signed shift right | a >> b
shrub | 1 | 1 | 1 | unsigned shift right | a >> b
signb | 1 | 1 |  | sign | sign(a)
subb | 1 | 1 | 1 | subtract | a - b
subssb | 1 | 1 | 1 | subtract with signed saturate | clamp(a - b)
subusb | 1 | 1 | 1 | subtract with unsigned saturate | clamp(a - b)
xorb | 1 | 1 | 1 | bitwise XOR | a ^ b
absw | 2 | 2 |  | absolute value | (a < 0) ? -a : a
addw | 2 | 2 | 2 | add | a + b
addssw | 2 | 2 | 2 | add with signed saturate | clamp(a + b)
addusw | 2 | 2 | 2 | add with unsigned saturate | clamp(a + b)
andw | 2 | 2 | 2 | bitwise AND | a & b
andnw | 2 | 2 | 2 | bitwise AND NOT | a & (~b)
avgsw | 2 | 2 | 2 | signed average | (a + b + 1)>>1
avguw | 2 | 2 | 2 | unsigned average | (a + b + 1)>>1
cmpeqw | 2 | 2 | 2 | compare equal | (a == b) ? (~0) : 0
cmpgtsw | 2 | 2 | 2 | compare greater than | (a > b) ? (~0) : 0
copyw | 2 | 2 |  | copy | a
maxsw | 2 | 2 | 2 | signed maximum | (a > b) ? a : b
maxuw | 2 | 2 | 2 | unsigned maximum | (a > b) ? a : b
minsw | 2 | 2 | 2 | signed minimum | (a < b) ? a : b
minuw | 2 | 2 | 2 | unsigned minimum | (a < b) ? a : b
mullw | 2 | 2 | 2 | low bits of multiply | a * b
mulhsw | 2 | 2 | 2 | high bits of signed multiply | (a * b) >> 8
mulhuw | 2 | 2 | 2 | high bits of unsigned multiply | (a * b) >> 8
orw | 2 | 2 | 2 | bitwise or | a | b
shlw | 2 | 2 | 2 | shift left | a << b
shrsw | 2 | 2 | 2 | signed shift right | a >> b
shruw | 2 | 2 | 2 | unsigned shift right | a >> b
signw | 2 | 2 |  | sign | sign(a)
subw | 2 | 2 | 2 | subtract | a - b
subssw | 2 | 2 | 2 | subtract with signed saturate | clamp(a - b)
subusw | 2 | 2 | 2 | subtract with unsigned saturate | clamp(a - b)
xorw | 2 | 2 | 2 | bitwise XOR | a ^ b
absl | 4 | 4 |  | absolute value | (a < 0) ? -a : a
addl | 4 | 4 | 4 | add | a + b
addssl | 4 | 4 | 4 | add with signed saturate | clamp(a + b)
addusl | 4 | 4 | 4 | add with unsigned saturate | clamp(a + b)
andl | 4 | 4 | 4 | bitwise AND | a & b
andnl | 4 | 4 | 4 | bitwise AND NOT | a & (~b)
avgsl | 4 | 4 | 4 | signed average | (a + b + 1)>>1
avgul | 4 | 4 | 4 | unsigned average | (a + b + 1)>>1
cmpeql | 4 | 4 | 4 | compare equal | (a == b) ? (~0) : 0
cmpgtsl | 4 | 4 | 4 | compare greater than | (a > b) ? (~0) : 0
copyl | 4 | 4 |  | copy | a
maxsl | 4 | 4 | 4 | signed maximum | (a > b) ? a : b
maxul | 4 | 4 | 4 | unsigned maximum | (a > b) ? a : b
minsl | 4 | 4 | 4 | signed minimum | (a < b) ? a : b
minul | 4 | 4 | 4 | unsigned minimum | (a < b) ? a : b
mulll | 4 | 4 | 4 | low bits of multiply | a * b
mulhsl | 4 | 4 | 4 | high bits of signed multiply | (a * b) >> 8
mulhul | 4 | 4 | 4 | high bits of unsigned multiply | (a * b) >> 8
orl | 4 | 4 | 4 | bitwise or | a | b
shll | 4 | 4 | 4 | shift left | a << b
shrsl | 4 | 4 | 4 | signed shift right | a >> b
shrul | 4 | 4 | 4 | unsigned shift right | a >> b
signl | 4 | 4 |  | sign | sign(a)
subl | 4 | 4 | 4 | subtract | a - b
subssl | 4 | 4 | 4 | subtract with signed saturate | clamp(a - b)
subusl | 4 | 4 | 4 | subtract with unsigned saturate | clamp(a - b)
xorl | 4 | 4 | 4 | bitwise XOR | a ^ b
convsbw | 2 | 1 |  | convert signed | a
convubw | 2 | 1 |  | convert unsigned | a
convswl | 4 | 2 |  | convert signed | a
convuwl | 4 | 2 |  | convert unsigned | a
convwb | 1 | 2 |  | convert | a
convssswb | 1 | 2 |  | convert signed to signed with saturation | clamp(a)
convsuswb | 1 | 2 |  | convert signed to unsigned with saturation | clamp(a)
convusswb | 1 | 2 |  | convert unsigned to signed with saturation | clamp(a)
convuuswb | 1 | 2 |  | convert unsigned to unsigned with saturation | clamp(a)
convlw | 2 | 4 |  | convert | a
convssslw | 2 | 4 |  | convert signed to unsigned with saturation | clamp(a)
convsuslw | 2 | 4 |  | convert signed to signed with saturation | clamp(a)
convusslw | 2 | 4 |  | convert unsigned to unsigned with saturation | clamp(a)
convuuslw | 2 | 4 |  | convert unsigned to signed with saturation | clamp(a)
mulsbw | 2 | 1 | 1 | multiply signed | a * b
mulubw | 2 | 1 | 1 | multiply unsigned | a * b
mulswl | 4 | 2 | 2 | multiply signed | a * b
muluwl | 4 | 2 | 2 | multiply unsigned | a * b
accw | 2 | 2 |  | accumulate | += a
accl | 4 | 4 |  | accumulate | += a
accsadubl | 4 | 1 | 1 | accumulate absolute difference | += abs(a - b)
swapw | 2 | 2 |  | endianness swap | special
swapl | 4 | 4 |  | endianness swap | special
select0wb | 1 | 2 |  | select first half | special
select1wb | 1 | 2 |  | select second half | special
select0lw | 2 | 4 |  | select first half | special
select1lw | 2 | 4 |  | select second half | special
mergewl | 4 | 2 | 2 | merge halves | special
mergebw | 2 | 1 | 1 | merge halves | special
splitlw | 2 | 4 |  |  |
splitwb | 1 | 2 |  |  |
addf | 4 | 4 | 4 |  |
subf | 4 | 4 | 4 |  |
mulf | 4 | 4 | 4 |  |
divf | 4 | 4 | 4 |  |
sqrtf | 4 | 4 |  |  |
maxf | 4 | 4 | 4 |  |
minf | 4 | 4 | 4 |  |
cmpeqf | 4 | 4 | 4 |  |
cmpltf | 4 | 4 | 4 |  |
cmplef | 4 | 4 | 4 |  |
convfl | 4 | 4 |  |  |
convlf | 4 | 4 |  |  |

In the pseudo code of the above table, abs() indicates absolute value, clamp() indicates that any values outside the destination range are set to the nearest value in the destination range, and sign() evaluates to -1 for values less than 0, 1 for values greater than 0, and 0 for 0.

## Rule Coverage

The values for shift operations are not correct in this table.

Table 2. Table of Opcode Rule Coverage

opcode name | sse | mmx | altivec | arm | c64x-c
--- | --- | --- | --- | --- | ---
absb | yes | yes | no | no | yes
addb | yes | yes | yes | no | yes
addssb | yes | yes | yes | no | yes
addusb | yes | yes | yes | no | yes
andb | yes | yes | yes | no | yes
andnb | yes | yes | yes | no | yes
avgsb | yes | yes | yes | no | yes
avgub | yes | yes | yes | no | yes
cmpeqb | yes | yes | yes | no | yes
cmpgtsb | yes | yes | yes | no | yes
copyb | yes | yes | yes | no | yes
maxsb | yes | yes | yes | no | yes
maxub | yes | yes | yes | no | yes
minsb | yes | yes | yes | no | yes
minub | yes | yes | yes | no | yes
mullb | no | no | yes | no | no
mulhsb | no | no | yes | no | no
mulhub | no | no | yes | no | no
orb | yes | yes | yes | no | yes
shlb | no | no | no | no | no
shrsb | no | no | no | no | no
shrub | no | no | no | no | no
signb | yes | yes | yes | no | yes
subb | yes | yes | yes | no | yes
subssb | yes | yes | yes | no | no
subusb | yes | yes | yes | no | no
xorb | yes | yes | yes | no | yes
absw | yes | yes | no | yes | yes
addw | yes | yes | yes | yes | yes
addssw | yes | yes | yes | yes | yes
addusw | yes | yes | yes | yes | yes
andw | yes | yes | yes | yes | yes
andnw | yes | yes | yes | yes | yes
avgsw | yes | yes | yes | yes | yes
avguw | yes | yes | yes | yes | yes
cmpeqw | yes | yes | yes | yes | yes
cmpgtsw | yes | yes | yes | yes | yes
copyw | yes | yes | yes | yes | yes
maxsw | yes | yes | yes | yes | yes
maxuw | yes | yes | yes | yes | yes
minsw | yes | yes | yes | yes | yes
minuw | yes | yes | yes | yes | yes
mullw | yes | yes | yes | yes | yes
mulhsw | yes | yes | yes | yes | yes
mulhuw | yes | yes | yes | yes | yes
orw | yes | yes | yes | yes | yes
shlw | no | no | no | no | yes
shrsw | no | no | no | no | yes
shruw | no | no | no | no | yes
signw | yes | yes | yes | yes | yes
subw | yes | yes | yes | yes | yes
subssw | yes | yes | yes | yes | yes
subusw | yes | yes | yes | yes | yes
xorw | yes | yes | yes | yes | yes
absl | yes | yes | no | no | yes
addl | yes | yes | yes | no | yes
addssl | no | no | yes | no | yes
addusl | no | no | yes | no | yes
andl | yes | yes | yes | no | yes
andnl | yes | yes | yes | no | yes
avgsl | no | no | yes | no | yes
avgul | no | no | yes | no | yes
cmpeql | yes | yes | yes | no | yes
cmpgtsl | yes | yes | yes | no | yes
copyl | yes | yes | yes | no | yes
maxsl | yes | yes | yes | no | yes
maxul | yes | yes | yes | no | yes
minsl | yes | yes | yes | no | yes
minul | yes | yes | yes | no | yes
mulll | no | no | no | no | yes
mulhsl | no | no | no | no | yes
mulhul | no | no | no | no | yes
orl | yes | yes | yes | no | yes
shll | no | no | no | no | yes
shrsl | no | no | no | no | yes
shrul | no | no | no | no | yes
signl | yes | yes | yes | no | yes
subl | yes | yes | yes | no | yes
subssl | no | no | yes | no | yes
subusl | no | no | yes | no | yes
xorl | yes | yes | yes | no | yes
convsbw | yes | yes | yes | no | yes
convubw | yes | yes | yes | no | yes
convswl | yes | yes | yes | yes | yes
convuwl | yes | yes | yes | yes | yes
convwb | yes | yes | yes | yes | yes
convssswb | yes | yes | yes | yes | yes
convsuswb | yes | yes | yes | yes | yes
convusswb | no | no | no | yes | no
convuuswb | no | no | yes | yes | no
convlw | yes | yes | yes | no | yes
convssslw | yes | yes | yes | no | yes
convsuslw | no | no | yes | no | no
convusslw | no | no | no | no | no
convuuslw | no | no | yes | no | no
mulsbw | yes | no | yes | no | yes
mulubw | yes | no | yes | no | yes
mulswl | yes | yes | yes | yes | yes
muluwl | no | no | yes | yes | yes
accw | yes | yes | yes | no | yes
accl | yes | yes | yes | no | yes
accsadubl | yes | yes | yes | no | yes
swapw | yes | yes | no | yes | yes
swapl | yes | yes | no | no | yes
select0wb | yes | yes | yes | yes | yes
select1wb | yes | yes | yes | yes | yes
select0lw | yes | yes | yes | no | yes
select1lw | yes | yes | yes | no | yes
mergewl | yes | yes | yes | yes | yes
mergebw | yes | yes | yes | no | yes
splitlw | yes | no | no | no | no
splitwb | yes | no | no | no | no
addf | yes | no | no | no | yes
subf | yes | no | no | no | yes
mulf | yes | no | no | no | yes
divf | yes | no | no | no | yes
sqrtf | yes | no | no | no | yes
maxf | yes | no | no | no | yes
minf | yes | no | no | no | yes
cmpeqf | yes | no | no | no | yes
cmpltf | yes | no | no | no | yes
cmplef | yes | no | no | no | yes
convfl | yes | no | no | no | yes
convlf | yes | no | no | no | yes