函数地址对齐 __attribute__((aligned(64))) 编译器选项 -falign-functions=4

1, 实验原料 源代码

hello.c

复制代码
#include <stdio.h>

#define  ALI // __attribute__((aligned(64)))

float ALI  adddd(float a, float b, float c, float d){

	a+=b;
	a+=c;
	a+=d;

	return a;
}

float ALI  subbbb(float a, float b, float c, float d)
{
	a-= b;
	a-=c;
	a-=d;

	return a;
}


int main ()
{
	float x,y,z,s;

	x = 77.777;
	y =  1.111;
	z =  2.222;
	s =  3.333;

	printf("sum = %7.3f\n", adddd(x,y,z,s));
	printf("sub = %7.3f\n", subbbb(x,y,z,s));

	return 0;
}

2, no align 要求

#define ALI // attribute((aligned(64)))

ALI 定义为空,相当于不存在;

gcc hello.c

./a.out

objdump -d ./a.out

运气比较好,adddd函数的指令首地址为 0000001149

3,16字节 align

下面分别变成

#define ALI attribute((aligned(16)))

#define ALI attribute((aligned(64)))

来试试效果:

#define ALI attribute((aligned(16)))

效果同预期,adddd 的首指令地址变成了 00000001150,是可以整除16的

#define ALI attribute((aligned(64)))

4, 使用 -falign-functions=N

gcc -falign-functions=1 hello_align.c -o a.16.out

gcc -falign-functions=2 hello_align.c -o a.16.out

gcc -falign-functions=4 hello_align.c -o a.16.out

16:

可以看出来,函数体指令首地址都满足对齐要求。

相关推荐
rannn_1117 小时前
【力扣hot100】链表专题|160、206、234、141、142
java·算法·leetcode·链表·面试·开发
数模竞赛Paid answer7 小时前
2026年华东杯数学建模B题医药物流安排问题解题全过程文档及程序
算法·数学建模·数据分析·华东杯
不会代码的小猴8 小时前
21. 泛型编程上
开发语言·c++·笔记·算法
AI备案指南-满满9 小时前
大模型与算法备案全流程详解:从零到通过的完整指南
人工智能·算法·备案·大模型备案·算法备案
江畔柳前堤9 小时前
LLM 训练核心机制深度解析:Warmup、Cosine Decay 与 Perplexity 的完整知识体系
网络·人工智能·深度学习·算法·机器学习·语音识别
一只旭宝9 小时前
细讲C加加【9】C++ std::function与std::bind详解|仿函数、绑定器、类成员绑定、占位符、成员偏移指针
开发语言·c++·算法
良木林9 小时前
子串 - LeetCode hot 100
算法·leetcode·职场和发展
陌诺曦.10 小时前
Python扩展小练习
算法
coder!mq11 小时前
说几个常见的语法糖?
java·开发语言·算法