gpt4 book ai didi

c++ - 通过宏替换展开循环无效

转载 作者:太空宇宙 更新时间:2023-11-04 01:59:51 25 4
gpt4 key购买 nike

我正在尝试使用以下代码在 gcc 中执行循环展开。

#define SINGLE_INSTRUCTION(x,y) x + y
#define FIVE_INSTRUCTIONS(x,y) SINGLE_INSTRUCTION(x,y); SINGLE_INSTRUCTION(x,y); SINGLE_INSTRUCTION(x,y); SINGLE_INSTRUCTION(x,y); SINGLE_INSTRUCTION(x,y);
#define TWENTYFIVE_INSTRUCTIONS(x,y) FIVE_INSTRUCTIONS(x,y); FIVE_INSTRUCTIONS(x,y); FIVE_INSTRUCTIONS(x,y); FIVE_INSTRUCTIONS(x,y); FIVE_INSTRUCTIONS(x,y);
#define ONEHUNDRED_INSTRUCTIONS(x,y); TWENTYFIVE_INSTRUCTIONS(x,y); TWENTYFIVE_INSTRUCTIONS(x,y); TWENTYFIVE_INSTRUCTIONS(x,y); TWENTYFIVE_INSTRUCTIONS(x,y);

#define FIVEHUNDERED_INSTRUCTIONS(x,y); ONEHUNDRED_INSTRUCTIONS(x,y); ONEHUNDRED_INSTRUCTIONS(x,y); ONEHUNDRED_INSTRUCTIONS(x,y); ONEHUNDRED_INSTRUCTIONS(x,y); ONEHUNDRED_INSTRUCTIONS(x,y);

#define TWOTHOUSAND_INSTRUCTIONS(x,y); FIVEHUNDERED_INSTRUCTIONS(x,y); FIVEHUNDERED_INSTRUCTIONS(x,y); FIVEHUNDERED_INSTRUCTIONS(x,y); FIVEHUNDERED_INSTRUCTIONS(x,y);

#define TENTHOUSAND_INSTRUCTIONS(x,y) TWOTHOUSAND_INSTRUCTIONS(x,y); TWOTHOUSAND_INSTRUCTIONS(x,y); TWOTHOUSAND_INSTRUCTIONS(x, y); TWOTHOUSAND_INSTRUCTIONS(x,y); TWOTHOUSAND_INSTRUCTIONS(x,y);

#define FIFTYTHOUSAND_INSTRUCTIONS(x,y) TENTHOUSAND_INSTRUCTIONS(x,y); TENTHOUSAND_INSTRUCTIONS(x,y); TENTHOUSAND_INSTRUCTIONS(x, y); TENTHOUSAND_INSTRUCTIONS(x,y); TENTHOUSAND_INSTRUCTIONS(x,y);

#define TWOHUNDREDTHOUSAND_INSTRUCTIONS(x,y) FIFTYTHOUSAND_INSTRUCTIONS(x,y); FIFTYTHOUSAND_INSTRUCTIONS(x,y); FIFTYTHOUSAND_INSTRUCTIONS(x, y); FIFTYTHOUSAND_INSTRUCTIONS(x,y);

#define ONEMILLION_INSTRUCTIONS(x,y) TWOHUNDREDTHOUSAND_INSTRUCTIONS(x,y); TWOHUNDREDTHOUSAND_INSTRUCTIONS(x,y); TWOHUNDREDTHOUSAND_INSTRUCTIONS(x, y); TWOHUNDREDTHOUSAND_INSTRUCTIONS(x,y); TWOHUNDREDTHOUSAND_INSTRUCTIONS(x,y);

无效主(){

ONEMILLION_INSTRUCTIONS(50,100);
ONEMILLION_INSTRUCTIONS(200,300);
/*
ONEMILLION_INSTRUCTIONS(200,300);
ONEMILLION_INSTRUCTIONS(50,100);
ONEMILLION_INSTRUCTIONS(50,100);
ONEMILLION_INSTRUCTIONS(200,300);
ONEMILLION_INSTRUCTIONS(50,100);
ONEMILLION_INSTRUCTIONS(200,300);
ONEMILLION_INSTRUCTIONS(50,100);
*/

}但每次我增加指令宏时,输出箱似乎总是<8KB。我预计大小约为 40MB。我不明白发生了什么。

最佳答案

您的指令不会产生任何可观察到的行为。 C 是根据抽象机定义的。只要程序的可观察行为符合规范规定,编译器就可以生成任何代码。

在 C 中,可观察到的行为是:调用库函数、将数据写入文件以及访问 volatile 变量。

作为一种解决方法,您可以将一条指令更改为 { volatile int z = x + y;

关于c++ - 通过宏替换展开循环无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28733732/

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