Ternary move instructions
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Ternary move instructions
Is anyone aware of any ISA that implements the ternary conditional operator as an instruction? Basically, this would be a three operand instruction:
MOVcc x, y, z
That tests some condition, and moves x to z if the condition is true, and y to z if the condition is false?
Of course, conditional branches could be regarded as a special case of this:
jne offset
could be regarded as equivalent to something like the following in an ISA with a ternary move:
movne IP+offset, IP, IP
But I'm not aware of any ISA that has a more general implementation of this concept.
MOVcc x, y, z
That tests some condition, and moves x to z if the condition is true, and y to z if the condition is false?
Of course, conditional branches could be regarded as a special case of this:
jne offset
could be regarded as equivalent to something like the following in an ISA with a ternary move:
movne IP+offset, IP, IP
But I'm not aware of any ISA that has a more general implementation of this concept.
Re: Ternary move instructions
So my first thought was "if any, it would be ARM". Not quite, but ARM has a two-operand move instruction and allows you to put conditions on all instructions, so you could
where cc and ncc are opposite conditions.
Come to think of it, you could do the same with CMOV in x86 as well.
Code: Select all
MOVScc Rx, Ry
MOVSncc Rx, Rz
Come to think of it, you could do the same with CMOV in x86 as well.
Carpe diem!
-
- Member
- Posts: 5512
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Ternary move instructions
Do AVX V(P)BLEND instructions count?
Re: Ternary move instructions
The traditional MIPS ISA has a few conditional moves:
MIPS Release 6 has these instead:
- MOVN rd, rs, rt # if (rt != 0) rd = rs;
- MOVZ rd, rs, rt # if (rt == 0) rd = rs;
- MOVN.fmt fd, fs, rt # if (rt != 0) fd = fs;
- MOVZ.fmt fd, fs, rt # if (rt == 0) fd = fs;
- MOVT.fmt fd, fs, cc # if (FCC[cc] != 0) fd = fs;
- MOVF.fmt fd, fs, cc # if (FCC[cc] == 0) fd = fs;
MIPS Release 6 has these instead:
- SELNEZ rd, rs, rt # rd = rt ? rs : 0;
- SELEQZ rd, rs, rt # rd = rt ? 0 : rs;
- SEL.fmt fd, fs, ft # fd = fd.bit0 ? ft : fs;
Re: Ternary move instructions
ARMv8 A64's CSEL does pretty much exactly that:
CSEL Rdest, Rtrue, Rfalse, cond
CSEL Rdest, Rtrue, Rfalse, cond
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: Ternary move instructions
I'm specifically looking for ISAs that have a single instruction directly equivalent to the ternary operator. Mostly just out of curiousity.nullplan wrote:So my first thought was "if any, it would be ARM". Not quite, but ARM has a two-operand move instruction and allows you to put conditions on all instructions, so you couldwhere cc and ncc are opposite conditions.Code: Select all
MOVScc Rx, Ry MOVSncc Rx, Rz
Come to think of it, you could do the same with CMOV in x86 as well.
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: Ternary move instructions
They are very much (in a bitwise fashion) in the same spirit as the type of instruction I'm looking for, but what I'm specifically looking for is instructions that test a one-bit condition and move one of two values to a destination based on that condition.Octocontrabass wrote:Do AVX V(P)BLEND instructions count?
-
- Member
- Posts: 510
- Joined: Wed Mar 09, 2011 3:55 am
Re: Ternary move instructions
SEL.fmt appears to be exactly the kind of instruction I'm looking for.alexfru wrote:The traditional MIPS ISA has a few conditional moves:EDIT to add:
- MOVN rd, rs, rt # if (rt != 0) rd = rs;
- MOVZ rd, rs, rt # if (rt == 0) rd = rs;
- MOVN.fmt fd, fs, rt # if (rt != 0) fd = fs;
- MOVZ.fmt fd, fs, rt # if (rt == 0) fd = fs;
- MOVT.fmt fd, fs, cc # if (FCC[cc] != 0) fd = fs;
- MOVF.fmt fd, fs, cc # if (FCC[cc] == 0) fd = fs;
MIPS Release 6 has these instead:
- SELNEZ rd, rs, rt # rd = rt ? rs : 0;
- SELEQZ rd, rs, rt # rd = rt ? 0 : rs;
- SEL.fmt fd, fs, ft # fd = fd.bit0 ? ft : fs;
Re: Ternary move instructions
Well, the only other thing I remember that sort-of fits is PowerPC's fsel instructionlinguofreak wrote:I'm specifically looking for ISAs that have a single instruction directly equivalent to the ternary operator. Mostly just out of curiousity.
Code: Select all
fsel fd,ft,fa,fb
which does:
fd = ft >= 0? fa : fb
Carpe diem!