📄 floatcompressorold.cpp
字号:
compress_exponent(0,0,ae_exponent_none,rmExponentNone);
return 0.0f;
}
}
F32 FloatCompressorOld::DecompressNone()
{
I32 exponentReal = decompress_exponent(0,ad_exponent_none,rmExponentNone);
if (bits_for_mantissa[exponentReal] >= 0)
{
F32 fReal;
I32 signReal = decompress_sign(0,ad_sign_none,rmSignNone);
I32 mantissaReal = decompress_mantissa(exponentReal,0,ad_mantissa_none,rmMantissaNoneLow,rmMantissaNoneHigh);
if (signReal)
{
((U32&)fReal) = 0x80000000 | (exponentReal << 23) | mantissaReal;
}
else
{
((U32&)fReal) = (exponentReal << 23) | mantissaReal;
}
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
else
{
return 0.0f;
}
}
F32 FloatCompressorOld::CompressLast(F32 fPred, F32 fReal)
{
num_predictions_last++;
I32 signPred = (((U32&)fPred) & 0x80000000) == 0x80000000;
I32 exponentPred = (((U32&)fPred) & 0x7F800000) >> 23;
I32 mantissaPred = (((U32&)fPred) & 0x007FFFFF);
I32 signReal = (((U32&)fReal) & 0x80000000) == 0x80000000;
I32 exponentReal = (((U32&)fReal) & 0x7F800000) >> 23;
I32 mantissaReal = (((U32&)fReal) & 0x007FFFFF);
if (bits_for_mantissa[exponentReal] >= 0)
{
// compress exponent
compress_exponent(exponentPred,exponentReal,ae_exponent_last,rmExponentLast);
// compress sign
if (signPred == signReal)
{
compress_sign(exponentReal,0,ae_sign_last,rmSignLast); // correct predicted
}
else
{
compress_sign(exponentReal,1,ae_sign_last,rmSignLast); // incorrect predicted
}
// compress mantissa
if (signPred == signReal) // sign predicted correctly
{
if (exponentPred == exponentReal)
{
mantissaReal = compress_mantissa(exponentReal,mantissaPred,mantissaReal,ae_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
else if (exponentPred > exponentReal)
{
mantissaReal = compress_mantissa(exponentReal,0x007FFFFF,mantissaReal,ae_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
else
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
}
else if (signPred) // predicted negative, but in reality it is positive
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
else // predicted positive, but in reality it is negative
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
((U32&)fReal) = (((U32&)fReal) & 0xFF800000) | mantissaReal;
// update precision
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
else // the float is quantized to 0.0f
{
// compress only exponent
compress_exponent(exponentPred,0,ae_exponent_last,rmExponentLast);
return 0.0f;
}
}
F32 FloatCompressorOld::DecompressLast(F32 fPred)
{
I32 exponentPred = (((U32&)fPred) & 0x7F800000) >> 23;
I32 exponentReal = decompress_exponent(exponentPred,ad_exponent_last,rmExponentLast);
if (bits_for_mantissa[exponentReal] >= 0)
{
F32 fReal;
I32 signPred = (((U32&)fPred) & 0x80000000) == 0x80000000;
I32 mantissaPred = (((U32&)fPred) & 0x007FFFFF);
I32 signReal;
I32 mantissaReal;
// decompress sign
if (decompress_sign(exponentReal,ad_sign_last,rmSignLast))
{
signReal = !signPred;
}
else
{
signReal = signPred;
}
// decompress mantissa
if (signPred == signReal) // sign predicted correctly
{
if (exponentPred == exponentReal) // exponent predicted correctly
{
mantissaReal = decompress_mantissa(exponentReal,mantissaPred,ad_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
else if (exponentPred > exponentReal) // overshot exponent prediction
{
mantissaReal = decompress_mantissa(exponentReal,0x007FFFFF,ad_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
else // undershot exponent prediction
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
}
else if (signPred) // predicted negative, but in reality it is positive
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
else // predicted positive, but in reality it is negative
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_last,rmMantissaLastLow,rmMantissaLastHigh);
}
// put together decompressed float value
if (signReal)
{
((U32&)fReal) = 0x80000000 | (exponentReal << 23) | mantissaReal;
}
else
{
((U32&)fReal) = (exponentReal << 23) | mantissaReal;
}
// update precision
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
return 0.0f; // we should never get here
}
F32 FloatCompressorOld::CompressAcross(F32 fPred, F32 fReal)
{
num_predictions_across++;
I32 signPred = (((U32&)fPred) & 0x80000000) == 0x80000000;
I32 exponentPred = (((U32&)fPred) & 0x7F800000) >> 23;
I32 mantissaPred = (((U32&)fPred) & 0x007FFFFF);
I32 signReal = (((U32&)fReal) & 0x80000000) == 0x80000000;
I32 exponentReal = (((U32&)fReal) & 0x7F800000) >> 23;
I32 mantissaReal = (((U32&)fReal) & 0x007FFFFF);
if (bits_for_mantissa[exponentReal] >= 0)
{
// compress exponent
compress_exponent(exponentPred,exponentReal,ae_exponent_across,rmExponentAcross);
// compress sign
if (signPred == signReal)
{
compress_sign(exponentReal,0,ae_sign_across,rmSignAcross); // correct predicted
}
else
{
compress_sign(exponentReal,1,ae_sign_across,rmSignAcross); // incorrect predicted
}
// compress mantissa
if (signPred == signReal) // sign predicted correctly
{
if (exponentPred == exponentReal)
{
mantissaReal = compress_mantissa(exponentReal,mantissaPred,mantissaReal,ae_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
else if (exponentPred > exponentReal)
{
mantissaReal = compress_mantissa(exponentReal,0x007FFFFF,mantissaReal,ae_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
else
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
}
else if (signPred) // predicted negative, but in reality it is positive
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
else // predicted positive, but in reality it is negative
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
((U32&)fReal) = (((U32&)fReal) & 0xFF800000) | mantissaReal;
// update precision
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
else // the float is quantized to 0.0f
{
// compress only exponent
compress_exponent(exponentPred,0,ae_exponent_across,rmExponentAcross);
return 0.0f;
}
}
F32 FloatCompressorOld::DecompressAcross(F32 fPred)
{
I32 exponentPred = (((U32&)fPred) & 0x7F800000) >> 23;
I32 exponentReal = decompress_exponent(exponentPred,ad_exponent_across,rmExponentAcross);
if (bits_for_mantissa[exponentReal] >= 0)
{
F32 fReal;
I32 signPred = (((U32&)fPred) & 0x80000000) == 0x80000000;
I32 mantissaPred = (((U32&)fPred) & 0x007FFFFF);
I32 signReal;
I32 mantissaReal;
// decompress sign
if (decompress_sign(exponentReal,ad_sign_across,rmSignAcross))
{
signReal = !signPred;
}
else
{
signReal = signPred;
}
// decompress mantissa
if (signPred == signReal) // sign predicted correctly
{
if (exponentPred == exponentReal) // exponent predicted correctly
{
mantissaReal = decompress_mantissa(exponentReal,mantissaPred,ad_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
else if (exponentPred > exponentReal) // overshot exponent prediction
{
mantissaReal = decompress_mantissa(exponentReal,0x007FFFFF,ad_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
else // undershot exponent prediction
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
}
else if (signPred) // predicted negative, but in reality it is positive
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
else // predicted positive, but in reality it is negative
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_across,rmMantissaAcrossLow,rmMantissaAcrossHigh);
}
// put together decompressed float value
if (signReal)
{
((U32&)fReal) = 0x80000000 | (exponentReal << 23) | mantissaReal;
}
else
{
((U32&)fReal) = (exponentReal << 23) | mantissaReal;
}
// update precision
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
return 0.0f; // we should never get here
}
F32 FloatCompressorOld::CompressWithin(F32 fPred, F32 fReal)
{
num_predictions_within++;
I32 signPred = (((U32&)fPred) & 0x80000000) == 0x80000000;
I32 exponentPred = (((U32&)fPred) & 0x7F800000) >> 23;
I32 mantissaPred = (((U32&)fPred) & 0x007FFFFF);
I32 signReal = (((U32&)fReal) & 0x80000000) == 0x80000000;
I32 exponentReal = (((U32&)fReal) & 0x7F800000) >> 23;
I32 mantissaReal = (((U32&)fReal) & 0x007FFFFF);
if (bits_for_mantissa[exponentReal] >= 0)
{
// compress exponent
compress_exponent(exponentPred,exponentReal,ae_exponent_within,rmExponentWithin);
// compress sign
if (signPred == signReal)
{
compress_sign(exponentReal,0,ae_sign_within,rmSignWithin); // correct predicted
}
else
{
compress_sign(exponentReal,1,ae_sign_within,rmSignWithin); // incorrect predicted
}
// compress mantissa
if (signPred == signReal) // sign predicted correctly
{
if (exponentPred == exponentReal)
{
mantissaReal = compress_mantissa(exponentReal,mantissaPred,mantissaReal,ae_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
else if (exponentPred > exponentReal)
{
mantissaReal = compress_mantissa(exponentReal,0x007FFFFF,mantissaReal,ae_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
else
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
}
else if (signPred) // predicted negative, but in reality it is positive
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
else // predicted positive, but in reality it is negative
{
mantissaReal = compress_mantissa(exponentReal,0x0,mantissaReal,ae_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
((U32&)fReal) = (((U32&)fReal) & 0xFF800000) | mantissaReal;
// update precision
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
else // the float is quantized to 0.0f
{
// compress only exponent
compress_exponent(exponentPred,0,ae_exponent_within,rmExponentWithin);
return 0.0f;
}
}
F32 FloatCompressorOld::DecompressWithin(F32 fPred)
{
I32 exponentPred = (((U32&)fPred) & 0x7F800000) >> 23;
I32 exponentReal = decompress_exponent(exponentPred,ad_exponent_within,rmExponentWithin);
if (bits_for_mantissa[exponentReal] >= 0)
{
F32 fReal;
I32 signPred = (((U32&)fPred) & 0x80000000) == 0x80000000;
I32 mantissaPred = (((U32&)fPred) & 0x007FFFFF);
I32 signReal;
I32 mantissaReal;
// decompress sign
if (decompress_sign(exponentReal,ad_sign_within,rmSignWithin))
{
signReal = !signPred;
}
else
{
signReal = signPred;
}
// decompress mantissa
if (signPred == signReal) // sign predicted correctly
{
if (exponentPred == exponentReal) // exponent predicted correctly
{
mantissaReal = decompress_mantissa(exponentReal,mantissaPred,ad_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
else if (exponentPred > exponentReal) // overshot exponent prediction
{
mantissaReal = decompress_mantissa(exponentReal,0x007FFFFF,ad_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
else // undershot exponent prediction
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
}
else if (signPred) // predicted negative, but in reality it is positive
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
else // predicted positive, but in reality it is negative
{
mantissaReal = decompress_mantissa(exponentReal,0x0,ad_mantissa_within,rmMantissaWithinLow,rmMantissaWithinHigh);
}
// put together decompressed float value
if (signReal)
{
((U32&)fReal) = 0x80000000 | (exponentReal << 23) | mantissaReal;
}
else
{
((U32&)fReal) = (exponentReal << 23) | mantissaReal;
}
// update precision
if (exponentReal == 255)
{
fprintf(stderr,"WARNING: exponentReal is 255 -> infinite number\n");
}
else
{
if (bits) update_precision(fReal);
}
return fReal;
}
return 0.0f; // we should never get here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -