English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 27 November 2019, 14:05   #1
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Are "memory barriers" needed with GCC?

Of late I've grown increasingly suspicious that the enabling and disabling of interrupts around the sensitive parts of my code wasn't working as expected. Looking into it, GCC is happy to rearrange bits of code as it sees fit, the only real exception being accesses to things marked volatile, which it will keep in order (relative to other volatile things).

So, if I have code like:

Code:
    extern volatile struct Custom * custom;

    ...

    custom->intena = INTF_INTEN;
    Event * event = (Event *) Queue_Dequeue(&eventQueue);
    custom->intena = INTF_SETCLR | INTF_INTEN;
Do I need to add GCC Memory Barriers:

Code:
    asm volatile ("" ::: "memory");
around the call to Dequeue?

Edit: The answer is "Yes".

Last edited by deimos; 28 November 2019 at 17:33.
deimos is offline  
Old 27 November 2019, 17:51   #2
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Just found this: https://gcc.gnu.org/onlinedocs/gcc/Volatiles.html

Quote:
Accesses to non-volatile objects are not ordered with respect to volatile accesses. You cannot use a volatile object as a memory barrier to order a sequence of writes to non-volatile memory. For instance:
Code:
int *ptr = something;
volatile int vobj;
*ptr = something;
vobj = 1;
Unless *ptr and vobj can be aliased, it is not guaranteed that the write to *ptr occurs by the time the update of vobj happens. If you need this guarantee, you must use a stronger memory barrier such as:
Code:
int *ptr = something;
volatile int vobj;
*ptr = something;
asm volatile ("" : : : "memory");
vobj = 1;
Which seems to back up what I'm saying, even if I can't pinpoint it in my compiled code.
deimos is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Diabolik" & "Dylan Dog" & "Tex" & "Time Runners" series DamienD request.Old Rare Games 20 21 July 2022 16:58
"Voices8" 8 Channel Soundtracker "DemoSongI" song - "This is the Amiga with 8 Voices" DemosongIHunter request.Music 45 23 May 2022 20:07
WHDLoad, Alien Breed 3D TKG "Not enough chip memory!" kris2222 support.Games 4 27 April 2019 15:48
"Reminder "Lincs Amiga User Group aka "LAG" Meet Sat 5th of January 2013" rockape News 4 30 January 2013 00:06
Old cache memory as a "base" for GVP memory rkauer Hardware pics 4 22 November 2008 06:23

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 19:37.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10643 seconds with 15 queries