move mcl_fp_add*L to gen.cpp

dev
MITSUNARI Shigeo 9 years ago
parent e62b019cb9
commit 73943fda79
  1. 38
      src/gen.cpp
  2. 33
      src/long.txt

@ -321,6 +321,39 @@ struct Code : public mcl::Generator {
ret(Void);
endFunc();
}
void gen_mcl_fp_addL()
{
resetGlobalIdx();
Operand pz(IntPtr, bit);
Operand px(IntPtr, bit);
Operand py(IntPtr, bit);
Operand pp(IntPtr, bit);
std::string name = "mcl_fp_add" + cybozu::itoa(bit) + "L";
mcl_fp_addM[bit] = Function(name, Void, pz, px, py, pp);
beginFunc(mcl_fp_addM[bit]);
Operand x = load(px);
Operand y = load(py);
Operand p = load(pp);
x = zext(x, bit + unit);
y = zext(y, bit + unit);
p = zext(p, bit + unit);
Operand t0 = add(x, y);
Operand t1 = trunc(t0, bit);
store(t1, pz);
Operand vc = sub(t0, p);
Operand c = lshr(vc, bit + unit - 1);
c = trunc(c, 1);
Label carry("carry");
Label nocarry("nocarry");
br(c, carry, nocarry);
putLabel(nocarry);
Operand v = trunc(vc, bit);
store(v, pz);
ret(Void);
putLabel(carry);
ret(Void);
endFunc();
}
void gen_mcl_fp_subS()
{
resetGlobalIdx();
@ -427,6 +460,10 @@ struct Code : public mcl::Generator {
gen_mcl_fpDbl_add();
gen_mcl_fpDbl_sub();
}
void gen_long()
{
gen_mcl_fp_addL();
}
void setBit(uint32_t bit)
{
this->bit = bit;
@ -446,6 +483,7 @@ struct Code : public mcl::Generator {
setBit(i);
gen_all();
gen_short();
gen_long();
}
}
};

@ -1,36 +1,3 @@
define void @mcl_fp_add$(bit)L(i$(bit)* %pz, i$(bit)* %px, i$(bit)* %py, i$(bit)* %pp) {
%x = load i$(bit)* %px
%y = load i$(bit)* %py
%p = load i$(bit)* %pp
%x1 = zext i$(bit) %x to i$(bit+unit)
%y1 = zext i$(bit) %y to i$(bit+unit)
%p1 = zext i$(bit) %p to i$(bit+unit)
%t0 = add i$(bit+unit) %x1, %y1 ; x + y
%t1 = trunc i$(bit+unit) %t0 to i$(bit)
store i$(bit) %t1, i$(bit)* %pz
%vc = sub i$(bit+unit) %t0, %p1
%c = lshr i$(bit+unit) %vc, $(bit+unit-1)
%c1 = trunc i$(bit+unit) %c to i1
br i1 %c1, label %carry, label %nocarry
nocarry:
%v = trunc i$(bit+unit) %vc to i$(bit)
store i$(bit) %v, i$(bit)* %pz
ret void
carry:
ret void
}
define internal { i$(bit), i$(unit) } @local_sbb$(bit)(i$(bit) %x, i$(bit) %y) {
%x1 = zext i$(bit) %x to i$(bit+unit)
%y1 = zext i$(bit) %y to i$(bit+unit)
%v1 = sub i$(bit+unit) %x1, %y1
%v = trunc i$(bit+unit) %v1 to i$(bit)
%c = lshr i$(bit+unit) %v1, $(bit)
%c1 = trunc i$(bit+unit) %c to i$(unit)
%r1 = insertvalue { i$(bit), i$(unit) } undef, i$(bit) %v, 0
%r2 = insertvalue { i$(bit), i$(unit) } %r1, i$(unit) %c1, 1
ret { i$(bit), i$(unit) } %r2
}
define void @mcl_fp_sub$(bit)L(i$(bit)* %pz, i$(bit)* %px, i$(bit)* %py, i$(bit)* %pp) {
%x = load i$(bit)* %px

Loading…
Cancel
Save