gpt4 book ai didi

c - 在 Code Composer Studio 编译器中禁用 64 位除法

转载 作者:行者123 更新时间:2023-11-30 16:12:13 29 4
gpt4 key购买 nike

我目前正在使用 Code Composer Studio (CCS) V7.4.0.00015 用 C 语言编写程序。该程序有几个自写的库,可以执行Byte、unsigned int 和float 除法。

我已经达到了项目的阶段,我需要减少代码大小以确保有足够的空间来容纳引导加载程序。

查看我的 .map 文件会发现 CCS 自动包含的几个运行时支持对象。其中一些包括以下内容:

  • div64u.obj --> 846 字节
  • div64s.obj --> 316 字节

这些对象来自rts430x_lc_sd_eabi.lib

我的问题是:为什么要包含这些 64 位除法对象(特别是当我的程序中没有任何 64 位 float 时)?更重要的是,我可以禁用它们(或阻止 CCS 包含它们)吗?

我花了几天时间在不同的网站上进行谷歌搜索,但我找不到太多关于这些对象或如何禁用它们的文档。

编辑:事实证明,我确实有一个使用 long long int 的函数(类型定义为 SLLONG)

/**
* @brief Compensate the raw pressure gained from the BME
* @details Uses the pressure compensation parameters to
* calculate the true pressure from the raw pressure
*
* Output value of “96386.2” equals 96386.2 Pa = 963.862 hPa
*
* The contents of this function have been taken from the Adafruit Github page
* https://github.com/adafruit/Adafruit_BME280_Library
*
* @param rawPressure The raw pressure
* @param tempFine The temperature in high resoltuion format,
* gained from the BME_compensateTemp() function
*
* @return the pressure read from the device
*/
float BME_compensatePressure(ULONG rawPressure, SLONG tempFine)
{
SLLONG var1, var2, p;

if (rawPressure == 0x800000) // value in case pressure measurement was disabled
return SNaN;
rawPressure >>= 4;

var1 = ((SLLONG)tempFine) - 128000; // SLONG cast to SLLONG
var2 = var1 * var1 * (SLLONG)compParamsStruct.dig_P6; // SLONG^2 x (SWORD cast to SLLONG)
var2 = var2 + ((var1*(SLLONG)compParamsStruct.dig_P5)<<17); // SLLONG + (SLLONG * SWORD cast to SLLONG)
var2 = var2 + (((SLLONG)compParamsStruct.dig_P4)<<35);
var1 = ((var1 * var1 * (SLLONG)compParamsStruct.dig_P3)>>8) +
((var1 * (SLLONG)compParamsStruct.dig_P2)<<12);
var1 = (((((SLLONG)1)<<47)+var1))*((SLLONG)compParamsStruct.dig_P1)>>33;

if (var1 == 0) {
return 0; // avoid exception caused by division by zero
}
p = 1048576 - rawPressure;
p = (((p<<31) - var2)*3125) / var1;
var1 = (((SLLONG)compParamsStruct.dig_P9) * (p>>13) * (p>>13)) >> 25;
var2 = (((SLLONG)compParamsStruct.dig_P8) * p) >> 19;

p = ((p + var1 + var2) >> 8) + (((SLLONG)compParamsStruct.dig_P7)<<4);
return ((float)p)/256;
}

新问题:

  • 谁能想出一种方法来重新排列函数,以便它不需要使用长整型(不会导致任何精度损失?)
  • 或者更具体地说,任何人都可以弄清楚我如何以不同的方式进行长除法,即如下所示的行:
p = (((p<<31) - var2)*3125) / var1;

最佳答案

我对64位浮点运算原始问题的解决方案总结:

以下行首先插入到编译器标志中:

--float_operations_allowed=32

然而,这在项目中产生了一些错误。每个位置的错误都是相同的:

#1558-D 64-bit floating point operations are not allowed

产生这些错误的代码是:

float lowerFence = med -1.5 * IQR;
float upperFence = med +1.5 * IQR;

return 0.5*coeffs->c0+tempScaled*coeffs->c1;                

通过将文字转换为 float 并将多个浮点操作移动到单行来修复该错误

float IQR = STATS_Iqr(sorted, numSamples);
float iqrScaled = 1.5 * IQR;
float lowerFence = med - iqrScaled;
float upperFence = med + iqrScaled;

float half = 0.5;
float c0Scaled = half*coeffs->c0;
float c1Scaled = tempScaled*coeffs->c1;
return c0Scaled + c1Scaled;

解决上述错误后,清理并重建了项目。添加此编译器标志具有删除以下对象的效果

关于c - 在 Code Composer Studio 编译器中禁用 64 位除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58387753/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com