c - 为什么生成此代码以取消引用浮点指针?

标签 c gcc avr avr-gcc

我有这个生成奇怪机器代码的文件 float_deref.c:

float float_deref(float *ptr)
{
        return *ptr;
}

这是 avr-gcc -mmcu=atmega328p -O3 -S -o - float_deref.c 生成的程序集:

    .file   "float_deref.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
    .text
.global float_deref
    .type   float_deref, @function
float_deref:
    push r28
    push r29
    rcall .
    rcall .
    in r28,__SP_L__
    in r29,__SP_H__
/* prologue: function */
/* frame size = 4 */
/* stack size = 6 */
.L__stack_usage = 6
    movw r30,r24
    ld r18,Z
    ldd r19,Z+1
    ldd r20,Z+2
    ldd r21,Z+3
    movw r24,r20
    movw r22,r18
/* epilogue start */
    pop __tmp_reg__
    pop __tmp_reg__
    pop __tmp_reg__
    pop __tmp_reg__
    pop r29
    pop r28
    ret
    .size   float_deref, .-float_deref
    .ident  "GCC: (Homebrew AVR GCC 9.3.0) 9.3.0"

我不明白为什么代码将四个额外的字节压入堆栈并将堆栈指针加载到 Y 中。据我所知,Y 从未在函数中使用过。

最佳答案

这是 v9+ 中的一个已知问题,请参阅 https://gcc.gnu.org/PR90706

关于c - 为什么生成此代码以取消引用浮点指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61685542/

相关文章:

c - 指针之间的赋值仅在 main 内部有效,而在过程体中无效

c - 升级到Mojave后,无法在Mac上编译C程序

C - 是否有必要检查 freopen 的返回值?

c - sprintf float 和 double 变量

c - 包含名为 "generic"的变量的结构无法在 C++/CLI 项目中编译

c - 指针中的*p、**p、***p有什么区别?

c++ - R包错误错误: ‘std::Rf_beta’ has not been declared #define beta Rf_beta

c++ - 防止 GCC 在使用 -mavx 和 -mfma 编译时自动使用 AVX 和 FMA 指令

installation - AtmelStudio 7 安装 avr8 设备支持包失败

avr - 我的 AVR 闪存是否因太大的程序而溢出?