compiler: implement negate for complex numbers

This commit is contained in:
Ayke van Laethem
2020-10-28 00:49:13 +01:00
committed by Ron Evans
parent ffeff55706
commit 3e40b08ba0
3 changed files with 15 additions and 1 deletions
+10
View File
@@ -2581,6 +2581,16 @@ func (b *builder) createUnOp(unop *ssa.UnOp) (llvm.Value, error) {
return b.CreateSub(llvm.ConstInt(x.Type(), 0, false), x, ""), nil
} else if typ.Info()&types.IsFloat != 0 {
return b.CreateFNeg(x, ""), nil
} else if typ.Info()&types.IsComplex != 0 {
// Negate both components of the complex number.
r := b.CreateExtractValue(x, 0, "r")
i := b.CreateExtractValue(x, 1, "i")
r = b.CreateFNeg(r, "")
i = b.CreateFNeg(i, "")
cplx := llvm.Undef(x.Type())
cplx = b.CreateInsertValue(cplx, r, 0, "")
cplx = b.CreateInsertValue(cplx, i, 1, "")
return cplx, nil
} else {
return llvm.Value{}, b.makeError(unop.Pos(), "todo: unknown basic type for negate: "+typ.String())
}