Comments (6)
Thanks for the feedback.
@markos please take a look at the information above and decide if you recommend any changes.
from arm-learning-paths.
@pan- @jasonrandrews I agree that it will hurt performance, however that's exactly one of the points of the LP, that it will do that. I wanted to show that cache alignment is important if someone is focuses on performance. The suggestions for the code, were to demonstrate the point, as you probably have noted in the end of that page you linked. Bad alignment will make the same code much slower.
Sometimes a developer may have to maintain or improve existing software with such packed structures. Also, it was specifically meant for Linux systems -as noted in the first page of the LP. Windows on Arm is a very recent thing and not my expertise, if I am honest. And not being available on Windows is not really an argument not to use a feature, there are plenty of GCC/LLVM specific features that are used in general because they are useful and solve a problem.
Furthermore, alignas
(available only recently in C23 even though it's part of C++11) is not a substitute for packed attribute, it does not do the same thing (you probably mean the __attribute__(aligned))
).
from arm-learning-paths.
@markos _Alignas
is available since C11; C23 just adds an alias to it as alignas
.
Furthermore, alignas (available only recently in C23 even though it's part of C++11) is not a substitute for packed attribute, it does not do the same thing (you probably mean the attribute(aligned))).
Of course alignas
is not the same as packed
. alignas
will guarantee that the type is properly aligned while the packed
attribute destroys type alignment (example) and exposes your fields to unaligned access which may decrease performance as latter in the document or worse results in a crash on V8M or if the compiler decides to use load/store multiple...
In other terms, if a an array of the data structure is declared on the stack, if you use packed
it won't be aligned at all and you expose yourself to undesirable side effects whereas if alignas
is used it will be aligned as requested without ill side effects.
Things are getting slightly more complex for dynamic allocation as malloc/free
don't offer over alignment guarantees beyond what is in the ABI. However there are standard functions for this: Aligned alloc available in C11 is one of them combined with _Alignof
it becomes easy to allocate properly aligned arrays: (aligned_alloc(sizeof(T) * count, _Alignof(T))
) . The new operator also supports an alignment argument since C++17.
To summarise my point I believe we (I'm working for Arm) should recommend good practices and use language standard API and constructs where applicable to promote portable solutions.
from arm-learning-paths.
Hi @pan-
Would you be interested to write a short Learning Path to share your points? This would be a great outcome.
It looks like you have some good knowledge and are already pointing to example code in your comments. Because this is a community project, it's good for multiple people to share knowledge, even if the material covers similar topics.
I'm happy to help you get started if you need any help.
Thanks,
Jason
from arm-learning-paths.
Of course
alignas
is not the same aspacked
.alignas
will guarantee that the type is properly aligned while thepacked
attribute destroys type alignment (example) and exposes your fields to unaligned access which may decrease performance as latter in the document or worse results in a crash on V8M or if the compiler decides to use load/store multiple...
Erm, which is exactly the point I was trying to make in that section in the LP. I used on purpose bad alignment to show that there is measurable performance degradation. This was not an "accident". I tried to write something short and simple that will show the worst impact in performance. And packed structures are very common especially in networking protocols and storage file formats, on purpose.
Things are getting slightly more complex for dynamic allocation as
malloc/free
don't offer over alignment guarantees beyond what is in the ABI. However there are standard functions for this: Aligned alloc available in C11 is one of them combined with_Alignof
it becomes easy to allocate properly aligned arrays: (aligned_alloc(sizeof(T) * count, _Alignof(T))
) . The new operator also supports an alignment argument since C++17.To summarise my point I believe we (I'm working for Arm) should recommend good practices and use language standard API and constructs where applicable to promote portable solutions.
Regarding the portable part, I specifically mentioned Linux as a requirement for the LP, and it was accepted as such. In fact it will run also on the BSD as well. I never even implied that the code would work on Windows.
In any case, I don't want to engage in a needless debate here. I don't disagree with you that I could add a few notes about alignas
or even align_alloc
here (which btw, according the link you pasted is also not available on MS Windows C Runtime). I will finish my current LPs and then I'll revisit this one with the requested additions. But I'll be honest, in general I do not plan to do anything special to ensure portability with Windows, as I have zero interest in it. Someone else will have to do that part.
from arm-learning-paths.
Hi @markos ,
There is no required action here, but please submit PRs for improvement or new Learning Paths as you are able to contribute.
Thank you for your effort and participation.
Jason
from arm-learning-paths.
Related Issues (20)
- Python for Windows on Arm HOT 3
- Prepare AVH instances of Raspberry Pi 4 HOT 1
- Feedback - Arm Software Licensing HOT 4
- Review question results should highlight what was the right answer if you make an incorrect choice HOT 1
- Markdown code blocks without a type are allowed but can be misinterpreted HOT 3
- Explanations HOT 2
- Unknown --project argument HOT 6
- Get started with Yocto Linux on Qemu HOT 2
- Build and Run 64-bit Arm Yocto Linux image on Qemu HOT 5
- Debug connection with Arm DSTREAM HOT 9
- Configure and run WSL with various Linux distributions HOT 3
- Enable systemd in WSL HOT 1
- How to develop Flash loader using DSTREAM in FPGA HOT 3
- Modify the example to use the UART for printf output HOT 2
- Connectivity between FVP and VMs in cca emulator HOT 5
- Browsers on Arm HOT 2
- Migrating C/C++ applications HOT 4
- Accessing elements of a matrix row_wise using SVE. HOT 2
- Feedback - Missing info that it is ONLY x86_64 installation and no ARM64 version HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arm-learning-paths.