代码拉取完成,页面将自动刷新
同步操作将从 zhanyuan/arm64_asm 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include <stddef.h>
#include <stdint.h>
#include <limits.h>
const uint64_t dSignMask = 1ull << 63;
const uint64_t dExponentMask = 0x7ffull << 52;
const uint64_t dFractionMask = (1ull << 52) - 1;
const int dExponentBias = 1022;
const int dMantissaBits = 52;
const int dInfiniteExponent = 0x7ff;
const double dNormalizer = 0x1p54;
const int dNormalizerBias = 54;
const int iMantissaBits = 31;
void QuantizeMultiplier(double double_multiplier, int *quantized_multiplier, int *shift) {
if (quantized_multiplier == NULL || shift == NULL) {
return;
}
// we split a floating number into two parts: exponent and fraction
// since fraction is stored as int32, only 31 bits of mantissa is remained
union {
double d;
uint64_t ul;
} dul;
dul.d = double_multiplier;
if (!(dul.ul & (~dSignMask))) {
// multiplier is 0
*quantized_multiplier = 0;
*shift = 0;
return;
}
int exponent = (int)((dul.ul & dExponentMask) >> dMantissaBits);
if (exponent == dInfiniteExponent) {
// multiplier is inf or NaN
*shift = 0;
if (!(dul.ul & dFractionMask)) {
// inf
*quantized_multiplier = (dul.ul & dSignMask) ? INT_MIN : INT_MAX;
} else {
// NaN
*quantized_multiplier = 0;
}
return;
}
if (exponent == 0) {
// multiplier is a subnormal number
dul.d *= dNormalizer;
exponent = (int)((dul.ul & dExponentMask) >> dMantissaBits);
*shift = exponent - dExponentBias - dNormalizerBias;
} else {
*shift = exponent - dExponentBias;
}
uint64_t fraction = dul.ul & dFractionMask;
fraction += (1ull << dMantissaBits);
uint64_t rounded = ((fraction >> (dMantissaBits - iMantissaBits)) + 1ull) >> 1;
// we get 31 rounded bits now
if (rounded == (1ull << iMantissaBits)) {
// rounding may cause a carry
rounded >>= 1;
++*shift;
}
*quantized_multiplier = (dul.ul & dSignMask) ? (-(int32_t)(rounded)) : (int32_t)(rounded);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。