github.com/consensys/gnark-crypto@v0.14.0/field/generator/asm/amd64/element_mul_constants.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 func (f *FFAmd64) generateMulBy3() { 18 f.Comment("MulBy3(x *Element)") 19 stackSize := f.StackSize(1+f.NbWords*2, 0, 0) 20 registers := f.FnHeader("MulBy3", stackSize, 8) 21 defer f.AssertCleanStack(stackSize, 0) 22 // registers 23 x := registers.Pop() 24 t := registers.PopN(f.NbWords) 25 26 f.MOVQ("x+0(FP)", x) 27 28 f.Mov(x, t) 29 f.Add(t, t) 30 31 f.Reduce(®isters, t) 32 f.Add(x, t) 33 f.Reduce(®isters, t) 34 f.Mov(t, x) 35 36 f.RET() 37 } 38 39 func (f *FFAmd64) generateMulBy5() { 40 f.Comment("MulBy5(x *Element)") 41 stackSize := f.StackSize(1+f.NbWords*2, 0, 0) 42 registers := f.FnHeader("MulBy5", stackSize, 8) 43 defer f.AssertCleanStack(stackSize, 0) 44 45 // registers 46 x := registers.Pop() 47 t := registers.PopN(f.NbWords) 48 49 f.MOVQ("x+0(FP)", x) 50 51 f.Mov(x, t) 52 f.Add(t, t) 53 f.Reduce(®isters, t) 54 f.Add(t, t) 55 f.Reduce(®isters, t) 56 f.Add(x, t) 57 f.Reduce(®isters, t) 58 59 f.Mov(t, x) 60 f.RET() 61 } 62 63 func (f *FFAmd64) generateMulBy13() { 64 f.Comment("MulBy13(x *Element)") 65 stackSize := f.StackSize(1+f.NbWords*3, 0, 0) 66 registers := f.FnHeader("MulBy13", stackSize, 8) 67 defer f.AssertCleanStack(stackSize, 0) 68 69 // registers 70 x := f.Pop(®isters) 71 t := f.PopN(®isters) 72 s := f.PopN(®isters) 73 u := f.PopN(®isters) 74 75 f.MOVQ("x+0(FP)", x) 76 77 f.Mov(x, t) 78 79 f.Add(t, t) 80 f.ReduceElement(t, s) 81 f.Add(t, t) 82 f.ReduceElement(t, u) 83 84 f.Mov(t, u) // u == 4 85 86 f.Add(t, t) // t == 8 87 f.ReduceElement(t, s) 88 89 f.Add(u, t) // t == 12 90 f.ReduceElement(t, s) 91 92 f.Add(x, t) // t == 13 93 f.ReduceElement(t, s) 94 95 f.Mov(t, x) 96 f.RET() 97 98 f.Push(®isters, x) 99 f.Push(®isters, t...) 100 f.Push(®isters, u...) 101 f.Push(®isters, s...) 102 }