From 7acad64c09776c18a090cc89e49ee4302fae3764 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh@NetBSD.org>
Date: Wed, 30 Mar 2022 20:55:02 +0000
Subject: [PATCH 04/49] x86: Omit needless store in membar_producer/exit.

On x86, every store is a store-release, so there is no need for any
barrier.  But this wasn't a barrier anyway; it was just a store,
which was redundant with the store of the return address to the stack
implied by CALL even if issuing a store made a difference.
---
 common/lib/libc/arch/i386/atomic/atomic.S   | 7 +++++--
 common/lib/libc/arch/x86_64/atomic/atomic.S | 7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/common/lib/libc/arch/i386/atomic/atomic.S b/common/lib/libc/arch/i386/atomic/atomic.S
index 3dea25c1ce90..d929dd25024d 100644
--- a/common/lib/libc/arch/i386/atomic/atomic.S
+++ b/common/lib/libc/arch/i386/atomic/atomic.S
@@ -188,8 +188,11 @@ ENTRY(_membar_consumer)
 END(_membar_consumer)
 
 ENTRY(_membar_producer)
-	/* A store is enough */
-	movl	$0, -4(%esp)
+	/*
+	 * Every store to normal memory is a store-release on x86, so
+	 * there is never any need for explicit barriers to order
+	 * anything-before-store.
+	 */
 	ret
 END(_membar_producer)
 
diff --git a/common/lib/libc/arch/x86_64/atomic/atomic.S b/common/lib/libc/arch/x86_64/atomic/atomic.S
index a483aa98de1d..02554cd00edd 100644
--- a/common/lib/libc/arch/x86_64/atomic/atomic.S
+++ b/common/lib/libc/arch/x86_64/atomic/atomic.S
@@ -263,8 +263,11 @@ ENTRY(_membar_consumer)
 END(_membar_consumer)
 
 ENTRY(_membar_producer)
-	/* A store is enough */
-	movq	$0, -8(%rsp)
+	/*
+	 * Every store to normal memory is a store-release on x86, so
+	 * there is never any need for explicit barriers to order
+	 * anything-before-store.
+	 */
 	ret
 END(_membar_producer)
 
-- 
2.33.0