函数地址对齐 __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:

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

相关推荐
exe45212 分钟前
力扣每日一题5-18
java·算法·leetcode
点云SLAM35 分钟前
C++中聚合类(Aggregate Class)知识详解和注意事项
c++·算法·c++20·c++学习·聚合类·面向对象设计、·c++高级应用
YuforiaCode1 小时前
LeetCode 219.存在重复元素 II
算法·leetcode·职场和发展
CodeQingqing1 小时前
C语言练手磨时间
c语言·数据结构·算法
卡尔曼的BD SLAMer2 小时前
计算机视觉与深度学习 | Python实现EMD-SSA-VMD-LSTM时间序列预测(完整源码和数据)
python·深度学习·算法·cnn·lstm
yu_anan1112 小时前
Denoising Score Matching with Langevin Dynamics
算法·机器学习·概率论
小葡萄20253 小时前
黑马程序员C++2024新版笔记 第三章 数组
笔记·算法·c++20
勇闯逆流河9 小时前
【数据结构】堆
c语言·数据结构·算法
pystraf10 小时前
LG P9844 [ICPC 2021 Nanjing R] Paimon Segment Tree Solution
数据结构·c++·算法·线段树·洛谷
飞川撸码11 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang