1// Copyright 2020 ConsenSys Software Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package amd64
16
17func (f *FFAmd64) generateDouble() {
18	// func header
19	f.Comment("double(res, x *Element)")
20	stackSize := f.StackSize(f.NbWords*2, 0, 0)
21	registers := f.FnHeader("double", stackSize, 16)
22	defer f.AssertCleanStack(stackSize, 0)
23
24	// registers
25	x := registers.Pop()
26	t := registers.PopN(f.NbWords)
27
28	f.MOVQ("x+8(FP)", x)
29	f.Mov(x, t)
30	registers.Push(x)
31
32	f.Add(t, t)
33	f.Reduce(&registers, t)
34
35	r := registers.Pop()
36	f.MOVQ("res+0(FP)", r)
37	f.Mov(t, r)
38
39	f.RET()
40}
41