[英]Disable 64-bit division in Code Composer Studio compiler
I'm currently writing a program in C using Code Composer Studio (CCS) V7.4.0.00015.我目前正在使用 Code Composer Studio (CCS) V7.4.0.00015 在 C 中编写一个程序。 The program has several self-written libraries that perform Byte, unsigned int and float division.该程序有几个自写的库,可以执行字节、无符号整数和浮点除法。
I have reached that stage in the project where I need to reduce code size in order to ensure there is enough space to fit the boot-loader.我已经到了项目的那个阶段,我需要减少代码大小以确保有足够的空间来容纳引导加载程序。
Looking at my.map file reveals several a runtime-support objects that CCS is automatically including.查看 my.map 文件可以发现 CCS 自动包含的几个运行时支持对象。 Some of these include the following:其中一些包括以下内容:
div64u.obj
--> 846 bytes div64u.obj
--> 846 字节div64s.obj
--> 316 bytes div64s.obj
--> 316 字节These objects are from the rts430x_lc_sd_eabi.lib
这些对象来自rts430x_lc_sd_eabi.lib
My question is: Why are these 64bit division objects being included (especially when I don't have any 64 bit floats in my program)?我的问题是:为什么要包含这些 64 位除法对象(尤其是当我的程序中没有任何 64 位浮点数时)? And more importantly, can I disable them (or stop CCS from including them)?更重要的是,我可以禁用它们(或阻止 CCS 包含它们)吗?
I've spent a few days googling around and trawling different sites but I haven't been able to find much documentation on these objects or how to disable them.我花了几天时间在谷歌上搜索并搜索不同的站点,但我找不到关于这些对象或如何禁用它们的太多文档。
Edit: Turns out I do in fact have one function utilising long long ints (typedef'd as SLLONG)编辑:事实证明我确实有一个 function 使用长整数(typedef'd as 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;
}
New question:新问题:
p = (((p<<31) - var2)*3125) / var1;
Summary of my solution to the original problem of 64bit float operations:我对64位浮点运算的原始问题的解决方案总结:
The following lines were first inserted into the compiler flags:以下行首先插入到编译器标志中:
--float_operations_allowed=32
This however produced several errors around the project.然而,这在项目周围产生了几个错误。 The error was the same for each location:每个位置的错误都是相同的:
#1558-D 64-bit floating point operations are not allowed
The code that produced these errors was:产生这些错误的代码是:
float lowerFence = med -1.5 * IQR;
float upperFence = med +1.5 * IQR;
and和
return 0.5*coeffs->c0+tempScaled*coeffs->c1;
The error was fixed by casting literals to floats and moving multiple float operations to single lines该错误已通过将文字转换为浮点数并将多个浮点操作移动到单行来修复
float IQR = STATS_Iqr(sorted, numSamples);
float iqrScaled = 1.5 * IQR;
float lowerFence = med - iqrScaled;
float upperFence = med + iqrScaled;
and和
float half = 0.5;
float c0Scaled = half*coeffs->c0;
float c1Scaled = tempScaled*coeffs->c1;
return c0Scaled + c1Scaled;
After the above errors were resolved, the project was cleaned and rebuilt.上述错误解决后,清理并重建项目。 Adding this compiler flag had the effect of removing the below objects添加此编译器标志具有删除以下对象的效果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.