Recent

Author Topic: Platforms with no analigned write  (Read 831 times)

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Platforms with no analigned write
« on: October 20, 2025, 05:07:34 pm »
Are there a platforms that supports by FPC where you can't do analigned write?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LeP

  • Full Member
  • ***
  • Posts: 124
Re: Platforms with no analigned write
« Reply #1 on: October 20, 2025, 05:57:22 pm »
Are there a platforms that supports by FPC where you can't do analigned write?
This may be a start of knowledge: https://blog.vitlabuda.cz/2025/01/22/unaligned-memory-access-on-various-cpu-architectures.html

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: Platforms with no analigned write
« Reply #2 on: October 20, 2025, 06:09:25 pm »
Good, LeP.
Maybe FPC has compiler defines to mark platforms with no unaligned access?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

MathMan

  • Sr. Member
  • ****
  • Posts: 472
Re: Platforms with no analigned write
« Reply #3 on: October 20, 2025, 06:54:13 pm »
Good, LeP.
Maybe FPC has compiler defines to mark platforms with no unaligned access?

No need for that, there is already UnAligned - use it like i.e.

Code: Pascal  [Select][+][-]
  1.   Value: DWord;
  2.   P: pByte;
  3.  
  4.   Val := $ffffffff;
  5.   UnAligned( pDWord( P )^ ) := Val;
  6.  

LeP

  • Full Member
  • ***
  • Posts: 124
Re: Platforms with no analigned write
« Reply #4 on: October 20, 2025, 07:39:48 pm »
No need for that, there is already UnAligned - use it like i.e.
...............
@LemonParty asked about knowing platforms where you CAN'T do unaligned operations, not how to do an UNALIGNED operations.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8528
Re: Platforms with no analigned write
« Reply #5 on: October 20, 2025, 07:45:34 pm »
Are there a platforms that supports by FPC where you can't do analigned write?

SPARC. I can't speak for recent work, but traditionally it would either fail fatally or rely on the OS to simulate the unaligned access with a considerable performance penalty.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

creaothceann

  • Sr. Member
  • ****
  • Posts: 257
Re: Platforms with no analigned write
« Reply #6 on: October 20, 2025, 07:50:56 pm »

MathMan

  • Sr. Member
  • ****
  • Posts: 472
Re: Platforms with no analigned write
« Reply #7 on: October 20, 2025, 08:12:03 pm »
No need for that, there is already UnAligned - use it like i.e.
...............
@LemonParty asked about knowing platforms where you CAN'T do unaligned operations, not how to do an UNALIGNED operations.

Yes, I understood as much. And what is the consequence if you know these platforms? Or asked different - what is the background to the question? I could only think of one - and towards that I answered. So maybe not an answer to the question asked but maybe an answer to the motivation behind?

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: Platforms with no analigned write
« Reply #8 on: October 20, 2025, 08:55:23 pm »
Yes, I understood as much. And what is the consequence if you know these platforms? Or asked different - what is the background to the question? I could only think of one - and towards that I answered. So maybe not an answer to the question asked but maybe an answer to the motivation behind?
The purpouse is to generate different code for platforms where unaligned is not supported.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

PascalDragon

  • Hero Member
  • *****
  • Posts: 6311
  • Compiler Developer
Re: Platforms with no analigned write
« Reply #9 on: October 20, 2025, 08:55:43 pm »
Good, LeP.
Maybe FPC has compiler defines to mark platforms with no unaligned access?

Yes, it has: FPC_REQUIRES_PROPER_ALIGNMENT. ;) (though this also includes platforms that can allow unaligned accesses but where they might be slower, like Aarch64)

LemonParty

  • Sr. Member
  • ****
  • Posts: 393
Re: Platforms with no analigned write
« Reply #10 on: October 20, 2025, 08:57:04 pm »
Thank you, PascalDragon.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

MathMan

  • Sr. Member
  • ****
  • Posts: 472
Re: Platforms with no analigned write
« Reply #11 on: October 20, 2025, 11:35:42 pm »
Yes, I understood as much. And what is the consequence if you know these platforms? Or asked different - what is the background to the question? I could only think of one - and towards that I answered. So maybe not an answer to the question asked but maybe an answer to the motivation behind?
The purpouse is to generate different code for platforms where unaligned is not supported.

Which is what I assumed was the background. Now, with the answer from PascalDragon, you have two choices to handle it. I use UnAligned where I have too - and checked that, i.e. on x86-64, that it is simply ignored by FPC if the target platform supports unaligned access.

After reading PascalDragon's answer carefully I have to admit that I don't know how the compiler handles it on Aarch64 - I simply do not have a system to check.

 

TinyPortal © 2005-2018