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

unaligned float/double on arm #3515

Closed
ghost opened this issue Jul 22, 2020 · 5 comments
Closed

unaligned float/double on arm #3515

ghost opened this issue Jul 22, 2020 · 5 comments

Comments

@ghost
Copy link

ghost commented Jul 22, 2020

-mtriple=armv7-none-linux-androideabi

unittest
{
	char[] data = [1, 2, 0xc9, 0x76, 0xbe, 0x9f, 0x0c, 0x24, 0xfe, 0x40, 5, 6, 7, 8];
	// aligned ulong OK
	writeln("ulong =", *cast(ulong *)((cast(void *)data.ptr) + 0));
	// unaligned ulong OK
	writeln("ulong =", *cast(ulong *)((cast(void *)data.ptr) + 2));
	// unaligned double FAIL with SIGBUS
	writeln("double =", *cast(double *)((cast(void *)data.ptr) + 2));
}

@kinke
Copy link
Member

kinke commented Jul 22, 2020

To be expected, isn't it?

@ghost
Copy link
Author

ghost commented Jul 22, 2020

Do you think it is not bug?

@ghost
Copy link
Author

ghost commented Jul 22, 2020

I know, arm is not supported read floating from unaligned memory, but compiler can do it, just change assembler code for this operation. As you can see, we can read unaligned ulong, and then compiler could translate it into float.

@JohanEngelen
Copy link
Member

@Ewa-D This is a user error. You are forcing a read from an address that is only guaranteed to be valid for char, you are on your own here. All the pointer casting should be a clear sign that the compiler is not going to help you.

@dnadlinger
Copy link
Member

Indeed, in D, pointers are always assumed to be aligned. (Otherwise, all memory access would be super slow – they'd need to be pieced together byte by byte!)

You might want to check out https://forum.dlang.org/group/learn for questions like these.

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

No branches or pull requests

3 participants