making the compiler emit FMA instructions
Signed-off-by: Jakub Doka <jakub.doka2@gmail.com>
This commit is contained in:
parent
8138d6664f
commit
ef36e21475
|
@ -413,8 +413,15 @@ impl Nodes {
|
||||||
&& self.is_const(self[o].inputs[2])
|
&& self.is_const(self[o].inputs[2])
|
||||||
&& op.cond_op(self[o].ty).is_none())
|
&& op.cond_op(self[o].ty).is_none())
|
||||||
}),
|
}),
|
||||||
|
Kind::BinOp { op: TokenKind::Mul } if node.ty.is_float() => {
|
||||||
|
false
|
||||||
|
&& node.outputs.iter().all(|&n| {
|
||||||
|
self[n].kind == Kind::BinOp { op: TokenKind::Add }
|
||||||
|
&& self[n].inputs[1] == nid
|
||||||
|
})
|
||||||
|
}
|
||||||
Kind::BinOp { op: TokenKind::Add | TokenKind::Sub } => {
|
Kind::BinOp { op: TokenKind::Add | TokenKind::Sub } => {
|
||||||
self.is_locked(node.inputs[1])
|
(self.is_locked(node.inputs[1]) && !self[node.inputs[1]].ty.is_float())
|
||||||
|| (self.is_const(node.inputs[2])
|
|| (self.is_const(node.inputs[2])
|
||||||
&& node.outputs.iter().all(|&n| self.uses_direct_offset_of(n, nid, tys)))
|
&& node.outputs.iter().all(|&n| self.uses_direct_offset_of(n, nid, tys)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -348,6 +348,18 @@ impl HbvmBackend {
|
||||||
&& let Some(op) = op.imm_binop(node.ty)
|
&& let Some(op) = op.imm_binop(node.ty)
|
||||||
{
|
{
|
||||||
self.emit(op(atr(nid), atr(lhs), value as _));
|
self.emit(op(atr(nid), atr(lhs), value as _));
|
||||||
|
} else if node.kind == (Kind::BinOp { op: TokenKind::Add })
|
||||||
|
&& node.ty.is_float()
|
||||||
|
&& nodes.is_locked(lhs)
|
||||||
|
{
|
||||||
|
let fma = [instrs::fma32, instrs::fma64]
|
||||||
|
[node.ty.simple_size().unwrap().ilog2() as usize - 2];
|
||||||
|
self.emit(fma(
|
||||||
|
atr(nid),
|
||||||
|
atr(nodes[lhs].inputs[1]),
|
||||||
|
atr(nodes[lhs].inputs[2]),
|
||||||
|
atr(rhs),
|
||||||
|
));
|
||||||
} else if let Some(against) = op.cmp_against() {
|
} else if let Some(against) = op.cmp_against() {
|
||||||
let op_ty = nodes[rhs].ty;
|
let op_ty = nodes[rhs].ty;
|
||||||
let [dst, lhs, rhs] = [atr(nid), atr(lhs), atr(rhs)];
|
let [dst, lhs, rhs] = [atr(nid), atr(lhs), atr(rhs)];
|
||||||
|
|
Loading…
Reference in a new issue