Skip to content

Commit

Permalink
disable cast-function-type warning of g++-8
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Jan 12, 2019
1 parent d8975a2 commit eb31510
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
10 changes: 5 additions & 5 deletions include/mcl/fp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ class FpT : public fp::Serializable<FpT<tag, maxBitSize>,
}
inv(inv2_, 2);
#ifdef MCL_XBYAK_DIRECT_CALL
add = (void (*)(FpT& z, const FpT& x, const FpT& y))op_.fp_addA_;
add = fp::func_ptr_cast<void (*)(FpT& z, const FpT& x, const FpT& y)>(op_.fp_addA_);
if (add == 0) add = addC;
sub = (void (*)(FpT& z, const FpT& x, const FpT& y))op_.fp_subA_;
sub = fp::func_ptr_cast<void (*)(FpT& z, const FpT& x, const FpT& y)>(op_.fp_subA_);
if (sub == 0) sub = subC;
neg = (void (*)(FpT& y, const FpT& x))op_.fp_negA_;
neg = fp::func_ptr_cast<void (*)(FpT& y, const FpT& x)>(op_.fp_negA_);
if (neg == 0) neg = negC;
mul = (void (*)(FpT& z, const FpT& x, const FpT& y))op_.fp_mulA_;
mul = fp::func_ptr_cast<void (*)(FpT& z, const FpT& x, const FpT& y)>(op_.fp_mulA_);
if (mul == 0) mul = mulC;
sqr = (void (*)(FpT& y, const FpT& x))op_.fp_sqrA_;
sqr = fp::func_ptr_cast<void (*)(FpT& y, const FpT& x)>(op_.fp_sqrA_);
if (sqr == 0) sqr = sqrC;
#endif
*pb = true;
Expand Down
30 changes: 15 additions & 15 deletions include/mcl/fp_tower.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,24 @@ class FpDblT : public fp::Serializable<FpDblT<Fp> > {
{
const mcl::fp::Op& op = Fp::getOp();
#ifdef MCL_XBYAK_DIRECT_CALL
add = (void (*)(FpDblT&, const FpDblT&, const FpDblT&))op.fpDbl_addA_;
add = fp::func_ptr_cast<void (*)(FpDblT&, const FpDblT&, const FpDblT&)>(op.fpDbl_addA_);
if (add == 0) add = addC;
sub = (void (*)(FpDblT&, const FpDblT&, const FpDblT&))op.fpDbl_subA_;
sub = fp::func_ptr_cast<void (*)(FpDblT&, const FpDblT&, const FpDblT&)>(op.fpDbl_subA_);
if (sub == 0) sub = subC;
mod = (void (*)(Fp&, const FpDblT&))op.fpDbl_modA_;
mod = fp::func_ptr_cast<void (*)(Fp&, const FpDblT&)>(op.fpDbl_modA_);
if (mod == 0) mod = modC;
addPre = (void (*)(FpDblT&, const FpDblT&, const FpDblT&))op.fpDbl_addPre;
addPre = fp::func_ptr_cast<void (*)(FpDblT&, const FpDblT&, const FpDblT&)>(op.fpDbl_addPre);
if (addPre == 0) addPre = addPreC;
subPre = (void (*)(FpDblT&, const FpDblT&, const FpDblT&))op.fpDbl_subPre;
subPre = fp::func_ptr_cast<void (*)(FpDblT&, const FpDblT&, const FpDblT&)>(op.fpDbl_subPre);
if (subPre == 0) subPre = subPreC;
#endif
if (op.fpDbl_mulPreA_) {
mulPre = (void (*)(FpDblT&, const Fp&, const Fp&))op.fpDbl_mulPreA_;
mulPre = fp::func_ptr_cast<void (*)(FpDblT&, const Fp&, const Fp&)>(op.fpDbl_mulPreA_);
} else {
mulPre = mulPreC;
}
if (op.fpDbl_sqrPreA_) {
sqrPre = (void (*)(FpDblT&, const Fp&))op.fpDbl_sqrPreA_;
sqrPre = fp::func_ptr_cast<void (*)(FpDblT&, const Fp&)>(op.fpDbl_sqrPreA_);
} else {
sqrPre = sqrPreC;
}
Expand Down Expand Up @@ -387,19 +387,19 @@ class Fp2T : public fp::Serializable<Fp2T<_Fp>,
mcl::fp::Op& op = Fp::op_;
assert(op.xi_a);
#ifdef MCL_XBYAK_DIRECT_CALL
add = (void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y))op.fp2_addA_;
add = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_addA_);
if (add == 0) add = addC;
sub = (void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y))op.fp2_subA_;
sub = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_subA_);
if (sub == 0) sub = subC;
neg = (void (*)(Fp2T& y, const Fp2T& x))op.fp2_negA_;
neg = fp::func_ptr_cast<void (*)(Fp2T& y, const Fp2T& x)>(op.fp2_negA_);
if (neg == 0) neg = negC;
mul = (void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y))op.fp2_mulA_;
mul = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_mulA_);
if (mul == 0) mul = mulC;
sqr = (void (*)(Fp2T& y, const Fp2T& x))op.fp2_sqrA_;
sqr = fp::func_ptr_cast<void (*)(Fp2T& y, const Fp2T& x)>(op.fp2_sqrA_);
if (sqr == 0) sqr = sqrC;
mul_xi = fp::func_ptr_cast<void (*)(Fp2T&, const Fp2T&)>(op.fp2_mul_xiA_);
#endif
op.fp2_inv = fp2_invW;
mul_xi = (void (*)(Fp2T&, const Fp2T&))op.fp2_mul_xiA_;
if (mul_xi == 0) {
if (op.xi_a == 1) {
mul_xi = fp2_mul_xi_1_1iC;
Expand Down Expand Up @@ -688,7 +688,7 @@ struct Fp2DblT {
{
const mcl::fp::Op& op = Fp::getOp();
if (op.fp2Dbl_mulPreA_) {
mulPre = (void (*)(Fp2DblT&, const Fp2&, const Fp2&))op.fp2Dbl_mulPreA_;
mulPre = fp::func_ptr_cast<void (*)(Fp2DblT&, const Fp2&, const Fp2&)>(op.fp2Dbl_mulPreA_);
} else {
if (op.isFullBit) {
mulPre = fp2Dbl_mulPreW<true>;
Expand All @@ -697,7 +697,7 @@ struct Fp2DblT {
}
}
if (op.fp2Dbl_sqrPreA_) {
sqrPre = (void (*)(Fp2DblT&, const Fp2&))op.fp2Dbl_sqrPreA_;
sqrPre = fp::func_ptr_cast<void (*)(Fp2DblT&, const Fp2&)>(op.fp2Dbl_sqrPreA_);
} else {
if (op.isFullBit) {
sqrPre = fp2Dbl_sqrPreW<true>;
Expand Down
9 changes: 9 additions & 0 deletions include/mcl/op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ typedef int (*int2u)(Unit*, const Unit*);
typedef Unit (*u1uII)(Unit*, Unit, Unit);
typedef Unit (*u3u)(Unit*, const Unit*, const Unit*);

/*
disable -Wcast-function-type
the number of arguments of some JIT functions is smaller than that of T
*/
template<class T, class S>
T func_ptr_cast(S func)
{
return reinterpret_cast<T>(reinterpret_cast<void*>(func));
}
struct Block {
const Unit *p; // pointer to original FpT.v_
size_t n;
Expand Down
2 changes: 1 addition & 1 deletion src/fp_generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
op.fp_mulA_ = gen_mul();
prof_.set("Fp_mul", getCurr());
if (op.fp_mulA_) {
op.fp_mul = reinterpret_cast<void4u>(op.fp_mulA_); // used in toMont/fromMont
op.fp_mul = fp::func_ptr_cast<void4u>(op.fp_mulA_); // used in toMont/fromMont
}
op.fp_sqrA_ = gen_sqr();
prof_.set("Fp_sqr", getCurr());
Expand Down

0 comments on commit eb31510

Please sign in to comment.