Skip to content

Commit

Permalink
fix unaryop round build with old glibc (#4963)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihui authored Aug 24, 2023
1 parent 7c4969e commit c003281
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/layer/arm/unaryop_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,14 @@ struct unary_op_round
#endif
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand All @@ -431,13 +435,17 @@ struct unary_op_round
#else
float tmp[4];
vst1q_f32(tmp, x);
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
tmp[0] = nearbyintf(tmp[0]);
tmp[1] = nearbyintf(tmp[1]);
tmp[2] = nearbyintf(tmp[2]);
tmp[3] = nearbyintf(tmp[3]);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
float32x4_t y = vld1q_f32(tmp);
return y;
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/layer/arm/unaryop_arm_asimdhp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,14 @@ struct unary_op_round_fp16s
:);
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
__fp16 y = (__fp16)nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/layer/loongarch/unaryop_loongarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,14 @@ struct unary_op_round
:);
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/layer/mips/unaryop_mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,14 @@ struct unary_op_round
:);
return y;
#else
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions src/layer/unaryop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,14 @@ struct unary_op_round
float operator()(const float& x) const
{
// round to nearest even
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
}
};
Expand Down
4 changes: 4 additions & 0 deletions src/layer/x86/unaryop_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,14 @@ struct unary_op_round
{
// round to nearest even
// return (x + 12582912.f) - 12582912.f;
#ifdef FE_TONEAREST
int old_rm = fegetround();
fesetround(FE_TONEAREST);
#endif
float y = nearbyintf(x);
#ifdef FE_TONEAREST
fesetround(old_rm);
#endif
return y;
}
#if __SSE2__
Expand Down

0 comments on commit c003281

Please sign in to comment.