Live data from Hacker News

Writing Portable ARM64 Assembly

ariadne.space

11–20 of 22 posts

Re: Writing Portable ARM64 Assembly

#11
post #9
post #3

Earlier quoted context omitted.

Hardly an Apple specific issue. People have been writing non-portable assembly for pretty much every architecture for as long as assembly has been a thing. Heck, people write non-portable C and C++ too by using compiler specific extensions or intrinsics all the time too, that only end up working on very specific stacks. Or when you go to web and people target browser specific extensions and behaviour. Developers will…

I agree. Not to mention planned obsolescence of C and c++ syntax via ISO, that on a medium cycle (5/10 years). With c++ it is even worse: its syntax complexity is grotesque and absurd, it requires beyond sanity compilers, hence limiting to very few the ones which actually "work". c++ and similar should be avoided like hell. But C has already a waaaaay too rich and complex syntax: integer promotion, enum, switch, type…

Why would removing all those features be helpful? Most of those are important and very useful

Re: Writing Portable ARM64 Assembly

#12
post #8
post #3

Earlier quoted context omitted.

Hardly an Apple specific issue. People have been writing non-portable assembly for pretty much every architecture for as long as assembly has been a thing. Heck, people write non-portable C and C++ too by using compiler specific extensions or intrinsics all the time too, that only end up working on very specific stacks. Or when you go to web and people target browser specific extensions and behaviour. Developers will…

To be fair writing trully portable C that does useful things is not that simple. When was the last time you made sure your code supports CHAR_BIT != 8 for example.

I thought that because the C standard requires sizeof(char) to be 1, CHAR_BIT cannot be anything other than 8, unless the architecture is redefining what 'byte' means.

Re: Writing Portable ARM64 Assembly

#14
post #8

Earlier quoted context omitted.

To be fair writing trully portable C that does useful things is not that simple. When was the last time you made sure your code supports CHAR_BIT != 8 for example.

I thought that because the C standard requires sizeof(char) to be 1, CHAR_BIT cannot be anything other than 8, unless the architecture is redefining what 'byte' means.

That's right, char in C doesn't necessarily mean an 8-bit byte. There are modern architectures where there is no 8-bit type and CHAR_BIT is 16.

Re: Writing Portable ARM64 Assembly

#15
post #8

Earlier quoted context omitted.

To be fair writing trully portable C that does useful things is not that simple. When was the last time you made sure your code supports CHAR_BIT != 8 for example.

I thought that because the C standard requires sizeof(char) to be 1, CHAR_BIT cannot be anything other than 8, unless the architecture is redefining what 'byte' means.

The possibility for a byte to be something other than 8 bit is the reason, why some people refer to 8 bit as octet in network protocols etc.

I think I remember somebody pointing to such a machine in some special area (Telco?) still in use in a previous discussion here ... but if that still exists it's very very rare and mostly historical.

Re: Writing Portable ARM64 Assembly

#16
In general, most use cases for assembler are better off using intrinsics - these give access to the advanced instructions of a processor while the compiler still does the register allocation and scheduling, and ABI compatibility. Only in a few cases, like if you really expect to invest a lot of time to scrape out the last few processor cycles, or you're doing something that can't be done with intrinsics (like an interrupt vector) does it make sense to drop into plain assembler.

Re: Writing Portable ARM64 Assembly

#17
post #8
post #3

Earlier quoted context omitted.

Hardly an Apple specific issue. People have been writing non-portable assembly for pretty much every architecture for as long as assembly has been a thing. Heck, people write non-portable C and C++ too by using compiler specific extensions or intrinsics all the time too, that only end up working on very specific stacks. Or when you go to web and people target browser specific extensions and behaviour. Developers will…

To be fair writing trully portable C that does useful things is not that simple. When was the last time you made sure your code supports CHAR_BIT != 8 for example.

Yeah for sure, I just didn’t want to introduce multi-architecture portability since the main issue at hand was intra-arch portability.

But yeah, when you get into multiple architectures, it gets gnarly. Take even something as simple as instruction ordering when porting from x86_64 to arm64

Re: Writing Portable ARM64 Assembly

#18

Earlier quoted context omitted.

I thought that because the C standard requires sizeof(char) to be 1, CHAR_BIT cannot be anything other than 8, unless the architecture is redefining what 'byte' means.

The possibility for a byte to be something other than 8 bit is the reason, why some people refer to 8 bit as octet in network protocols etc. I think I remember somebody pointing to such a machine in some special area (Telco?) still in use in a previous discussion here ... but if that still exists it's very very rare and mostly historical.

Several DSPs don’t use 8 bit chars

https://stackoverflow.com/a/2098444

Re: Writing Portable ARM64 Assembly

#20
post #5

ISA specific extensions has been a thing on ARM before Apple.

That's true, but before M1, ARM was a lot more diverse, so software developers were way less likely to recklessly treat any single company's extensions as if they were part of the ARM spec.

Embedded development usually doesn't care.
Post reply on HN