简体   繁体   English

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

[英]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:新问题:

  • Can anyone figure out a way to rearrange the function so that it does not require the use of the long long integers (without causing any loss of precision?)谁能想出一种方法来重新排列 function 以便它不需要使用 long long 整数(不会造成任何精度损失?)
  • OR more specifically, can anyone figure out how I can do that long long division differently ie the line shown below:或者更具体地说,任何人都可以弄清楚我如何以不同的方式进行长长除法,即如下所示的行:
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.

相关问题 在Visual Studio 2013中调用malloc时由64位编译器生成的奇怪代码 - Strange code generated by 64-bit compiler when calling malloc in Visual Studio 2013 使用Windows和C编译器在64位系统上运行32位C代码 - Running a 32-bit C code on a 64-bit system with Windows and a C compiler Visual Studio - 在64位项目中编译32位代码 - Visual Studio - Compiling 32-bit code inside 64-bit project 如何在 32 位编译器中使用 64 位整数? - How to use 64-bit integers in 32-bit compiler? 64 位编译器结构填充与 32 位 arguments - 64-bit compiler struct padding with 32-bit arguments 此指针代码在64位计算机上合法吗? - Is this pointer code legal on 64-bit computers 在 Code::Blocks 上使用 64 位 MinGW 进行编译 - Compiling with 64-bit MinGW on Code::Blocks 需要C编译器为Windows 7 64位,编译到DOS目标 - Need C compiler for Windows 7 64-bit, to compile to DOS target 编译器不支持目标架构上的 64 位整数 - Compiler does not support 64-bit integers on target Architechture 当被除数为 64 位且商为 32 位时,如何使 gcc 或 clang 使用 64 位/32 位除法而不是 128 位/64 位除法? - How to make gcc or clang use 64-bit/32-bit division instead of 128-bit/64-bit division when the dividend is 64-bit and the quotient is 32-bit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM