Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alignment of scalar values should be specified #19

Closed
asb opened this issue Mar 13, 2017 · 3 comments · Fixed by #38
Closed

Alignment of scalar values should be specified #19

asb opened this issue Mar 13, 2017 · 3 comments · Fixed by #38
Assignees

Comments

@asb
Copy link
Collaborator

asb commented Mar 13, 2017

The calling convention description is incomplete without specifying the alignment of scalar values. Of course the alignment is usually sizeof(ty), but some 32-bit ABIs allow doubles to be 4-byte aligned.

@palmer-dabbelt
Copy link
Contributor

Thanks for going through the documentation, it's great to make sure the LLVM and GCC stuff match before people start really using our stuff. Looks like we're 64-bit aligned for uint64_t on rv32g. @sorear, can you document it?

palmer gamma02 ~ $ cat doublealign.c 
#include <stdint.h>

struct aligntest {
	uint32_t a;
	uint64_t b;
	uint32_t c;
};

void func(void *);

extern struct aligntest aligntest;

int main() {
	func(&aligntest.a);
	func(&aligntest.b);
	func(&aligntest.c);
	return 0;
};
	
	
palmer gamma02 ~ $ riscv64-unknown-linux-gnu-gcc doublealign.c -march=rv32g -mabi=ilp32 -O3 -S -o -
	.file	"doublealign.c"
	.option nopic
	.section	.text.startup,"ax",@progbits
	.align	2
	.globl	main
	.type	main, @function
main:
	lui	a0,%hi(aligntest)
	add	sp,sp,-16
	add	a0,a0,%lo(aligntest)
	sw	ra,12(sp)
	call	func
	lui	a0,%hi(aligntest+8)
	add	a0,a0,%lo(aligntest+8)
	call	func
	lui	a0,%hi(aligntest+16)
	add	a0,a0,%lo(aligntest+16)
	call	func
	lw	ra,12(sp)
	li	a0,0
	add	sp,sp,16
	jr	ra
	.size	main, .-main
	.ident	"GCC: (GNU) 6.1.0"

@asb
Copy link
Collaborator Author

asb commented Mar 13, 2017

Thanks Palmer, it was actually double fp I was referring to, though I would guess these are 64-bit aligned on RV32 as well (can't ssh into my machine with riscv-gcc to verify right now).

@palmer-dabbelt
Copy link
Contributor

doubles would definitely want to be 64-bit aligned, since there's a fld instruction even on RV32D.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants