Complex64 multiplication promotes to double internally?

I wrote some simple code to test out complex arithmetic (curious if Go made the same mistake C99 did wrt default behavior of complex arithmetic):

package main;

import "fmt"
import "math/rand"

func main() {
     r := rand.New(rand.NewSource(0));
     var x complex64 = complex(r.Float32(), r.Float32());
     var y complex64 = complex(r.Float32(), r.Float32());
     var z complex64 = x*y;
     fmt.Println("blah: ", z);

When I examine the assembly relevant to the multiply:

f3 0f 10 4c 24 38       movss  0x38(%rsp),%xmm1
f3 0f 5a c9             cvtss2sd %xmm1,%xmm1
f3 0f 10 54 24 34       movss  0x34(%rsp),%xmm2
f3 0f 5a d2             cvtss2sd %xmm2,%xmm2
0f 10 d9                movups %xmm1,%xmm3
f2 0f 59 ca             mulsd  %xmm2,%xmm1
f3 0f 10 64 24 3c       movss  0x3c(%rsp),%xmm4
f3 0f 5a e4             cvtss2sd %xmm4,%xmm4
f3 0f 5a c0             cvtss2sd %xmm0,%xmm0
0f 10 ec                movups %xmm4,%xmm5
f2 0f 59 e0             mulsd  %xmm0,%xmm4
f2 0f 5c cc             subsd  %xmm4,%xmm1
f2 0f 5a c9             cvtsd2ss %xmm1,%xmm1
f3 0f 11 4c 24 40       movss  %xmm1,0x40(%rsp)
f2 0f 59 d8             mulsd  %xmm0,%xmm3
f2 0f 59 d5             mulsd  %xmm5,%xmm2
f2 0f 58 da             addsd  %xmm2,%xmm3
f2 0f 5a c3             cvtsd2ss %xmm3,%xmm0
f3 0f 11 44 24 44       movss  %xmm0,0x44(%rsp)

It’s converting the single-precision floats to double-precision (cvtss2sd for all the operations, then converting back.). Is this intentional, can it be disabled?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.