mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add truncation op
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
d5524fc57b
commit
fb95e90f7f
@@ -196,12 +196,7 @@ struct packet_traits<float> : default_packet_traits {
|
||||
HasConj = 1,
|
||||
HasSetLinear = 1,
|
||||
HasBlend = 0,
|
||||
|
||||
HasDiv = 1,
|
||||
HasFloor = 1,
|
||||
HasCeil = 1,
|
||||
HasRint = 1,
|
||||
|
||||
HasSin = EIGEN_FAST_MATH,
|
||||
HasCos = EIGEN_FAST_MATH,
|
||||
HasACos = 1,
|
||||
@@ -4470,76 +4465,25 @@ EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) {
|
||||
return vrndpq_f32(a);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4f print(const Packet4f& a) {
|
||||
// Adds and subtracts signum(a) * 2^23 to force rounding.
|
||||
const Packet4f limit = pset1<Packet4f>(static_cast<float>(1 << 23));
|
||||
const Packet4f abs_a = pabs(a);
|
||||
Packet4f r = padd(abs_a, limit);
|
||||
// Don't compile-away addition and subtraction.
|
||||
EIGEN_OPTIMIZATION_BARRIER(r);
|
||||
r = psub(r, limit);
|
||||
// If greater than limit, simply return a. Otherwise, account for sign.
|
||||
r = pselect(pcmp_lt(abs_a, limit), pselect(pcmp_lt(a, pzero(a)), pnegate(r), r), a);
|
||||
return r;
|
||||
EIGEN_STRONG_INLINE Packet2f pround<Packet2f>(const Packet2f& a) {
|
||||
return vrnda_f32(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet2f print(const Packet2f& a) {
|
||||
// Adds and subtracts signum(a) * 2^23 to force rounding.
|
||||
const Packet2f limit = pset1<Packet2f>(static_cast<float>(1 << 23));
|
||||
const Packet2f abs_a = pabs(a);
|
||||
Packet2f r = padd(abs_a, limit);
|
||||
// Don't compile-away addition and subtraction.
|
||||
EIGEN_OPTIMIZATION_BARRIER(r);
|
||||
r = psub(r, limit);
|
||||
// If greater than limit, simply return a. Otherwise, account for sign.
|
||||
r = pselect(pcmp_lt(abs_a, limit), pselect(pcmp_lt(a, pzero(a)), pnegate(r), r), a);
|
||||
return r;
|
||||
EIGEN_STRONG_INLINE Packet4f pround<Packet4f>(const Packet4f& a) {
|
||||
return vrndaq_f32(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4f pfloor<Packet4f>(const Packet4f& a) {
|
||||
const Packet4f cst_1 = pset1<Packet4f>(1.0f);
|
||||
Packet4f tmp = print<Packet4f>(a);
|
||||
// If greater, subtract one.
|
||||
Packet4f mask = pcmp_lt(a, tmp);
|
||||
mask = pand(mask, cst_1);
|
||||
return psub(tmp, mask);
|
||||
EIGEN_STRONG_INLINE Packet2f ptrunc<Packet2f>(const Packet2f& a) {
|
||||
return vrnd_f32(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet2f pfloor<Packet2f>(const Packet2f& a) {
|
||||
const Packet2f cst_1 = pset1<Packet2f>(1.0f);
|
||||
Packet2f tmp = print<Packet2f>(a);
|
||||
// If greater, subtract one.
|
||||
Packet2f mask = pcmp_lt(a, tmp);
|
||||
mask = pand(mask, cst_1);
|
||||
return psub(tmp, mask);
|
||||
EIGEN_STRONG_INLINE Packet4f ptrunc<Packet4f>(const Packet4f& a) {
|
||||
return vrndq_f32(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4f pceil<Packet4f>(const Packet4f& a) {
|
||||
const Packet4f cst_1 = pset1<Packet4f>(1.0f);
|
||||
Packet4f tmp = print<Packet4f>(a);
|
||||
// If smaller, add one.
|
||||
Packet4f mask = pcmp_lt(tmp, a);
|
||||
mask = pand(mask, cst_1);
|
||||
return padd(tmp, mask);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet2f pceil<Packet2f>(const Packet2f& a) {
|
||||
const Packet2f cst_1 = pset1<Packet2f>(1.0);
|
||||
Packet2f tmp = print<Packet2f>(a);
|
||||
// If smaller, add one.
|
||||
Packet2f mask = pcmp_lt(tmp, a);
|
||||
mask = pand(mask, cst_1);
|
||||
return padd(tmp, mask);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -4800,10 +4744,6 @@ struct packet_traits<bfloat16> : default_packet_traits {
|
||||
HasSetLinear = 1,
|
||||
HasBlend = 0,
|
||||
HasDiv = 1,
|
||||
HasFloor = 1,
|
||||
HasCeil = 1,
|
||||
HasRint = 1,
|
||||
|
||||
HasSin = EIGEN_FAST_MATH,
|
||||
HasCos = EIGEN_FAST_MATH,
|
||||
HasLog = 1,
|
||||
@@ -4983,6 +4923,16 @@ EIGEN_STRONG_INLINE Packet4bf pceil<Packet4bf>(const Packet4bf& a) {
|
||||
return F32ToBf16(pceil<Packet4f>(Bf16ToF32(a)));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4bf pround<Packet4bf>(const Packet4bf& a) {
|
||||
return F32ToBf16(pround<Packet4f>(Bf16ToF32(a)));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4bf ptrunc<Packet4bf>(const Packet4bf& a) {
|
||||
return F32ToBf16(ptrunc<Packet4f>(Bf16ToF32(a)));
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4bf pconj(const Packet4bf& a) {
|
||||
return a;
|
||||
@@ -5168,9 +5118,6 @@ struct packet_traits<double> : default_packet_traits {
|
||||
HasBlend = 0,
|
||||
|
||||
HasDiv = 1,
|
||||
HasFloor = 1,
|
||||
HasCeil = 1,
|
||||
HasRint = 1,
|
||||
|
||||
#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
|
||||
HasExp = 1,
|
||||
@@ -5460,6 +5407,16 @@ EIGEN_STRONG_INLINE Packet2d pceil<Packet2d>(const Packet2d& a) {
|
||||
return vrndpq_f64(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet2d pround<Packet2d>(const Packet2d& a) {
|
||||
return vrndaq_f64(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet2d ptrunc<Packet2d>(const Packet2d& a) {
|
||||
return vrndq_f64(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet2d pldexp<Packet2d>(const Packet2d& a, const Packet2d& exponent) {
|
||||
return pldexp_generic(a, exponent);
|
||||
@@ -5521,9 +5478,6 @@ struct packet_traits<Eigen::half> : default_packet_traits {
|
||||
HasInsert = 1,
|
||||
HasReduxp = 1,
|
||||
HasDiv = 1,
|
||||
HasFloor = 1,
|
||||
HasCeil = 1,
|
||||
HasRint = 1,
|
||||
HasSin = 0,
|
||||
HasCos = 0,
|
||||
HasLog = 0,
|
||||
@@ -5791,6 +5745,26 @@ EIGEN_STRONG_INLINE Packet4hf pceil<Packet4hf>(const Packet4hf& a) {
|
||||
return vrndp_f16(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet8hf pround<Packet8hf>(const Packet8hf& a) {
|
||||
return vrndaq_f16(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4hf pround<Packet4hf>(const Packet4hf& a) {
|
||||
return vrnda_f16(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet8hf ptrunc<Packet8hf>(const Packet8hf& a) {
|
||||
return vrndq_f16(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet4hf ptrunc<Packet4hf>(const Packet4hf& a) {
|
||||
return vrnd_f16(a);
|
||||
}
|
||||
|
||||
template <>
|
||||
EIGEN_STRONG_INLINE Packet8hf psqrt<Packet8hf>(const Packet8hf& a) {
|
||||
return vsqrtq_f16(a);
|
||||
|
||||
Reference in New Issue
Block a user