github.com/consensys/gnark-crypto@v0.14.0/field/generator/asm/amd64/element_reduce.go (about)

     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  
    15  package amd64
    16  
    17  import (
    18  	"github.com/consensys/bavard/amd64"
    19  )
    20  
    21  func (f *FFAmd64) generateReduce() {
    22  	stackSize := f.StackSize(1+f.NbWords*2, 0, 0)
    23  	registers := f.FnHeader("reduce", stackSize, 8)
    24  	defer f.AssertCleanStack(stackSize, 0)
    25  
    26  	// registers
    27  	r := registers.Pop()
    28  	t := registers.PopN(f.NbWords)
    29  
    30  	f.MOVQ("res+0(FP)", r)
    31  	f.Mov(r, t)
    32  	f.Reduce(&registers, t)
    33  	f.Mov(t, r)
    34  	f.RET()
    35  }
    36  
    37  // Reduce scratch can be on the stack or a set of registers.
    38  func (f *FFAmd64) Reduce(registers *amd64.Registers, t []amd64.Register) {
    39  	scratch := f.PopN(registers)
    40  	f.ReduceElement(t, scratch)
    41  	f.Push(registers, scratch...)
    42  }