shithub: riscv

Download patch

ref: 01140dbe1733050a8da45645eac5c4279f0629b4
parent: 1b09060f468f530af2f4ef75441a40084e912e54
author: mia soweli <inbox@tachibana-labs.org>
date: Sun May 19 11:35:55 EDT 2024

gefs: convert to atomic instructions

8[al] now support the required atomics, so let's
stop using byte constants.

--- a/sys/src/cmd/gefs/atomic-386.s
+++ b/sys/src/cmd/gefs/atomic-386.s
@@ -1,12 +1,3 @@
-#define CMPXCHG	/* (CX) */\
-	BYTE $0x0F; BYTE $0xB1; BYTE $0x11
-#define CMPXCHG64 /* (DI) */\
-	BYTE $0x0F; BYTE $0xC7; BYTE $0x0F
-#define XADDL /* BX, (AX) */ \
-	BYTE $0x0F; BYTE $0xC1; BYTE $0x03
-#define XADDLSP /* AX, (SP) */ \
-	BYTE $0x0F; BYTE $0xC1; BYTE $0x04; BYTE $0x24
-
 /*  get variants */
 TEXT ageti+0(SB),1,$0
 TEXT agetl+0(SB),1,$0
@@ -38,7 +29,7 @@
 	MOVL	0(DI), AX
 	MOVL	4(DI), DX
 loop:
-	LOCK;	CMPXCHG64
+	LOCK;	CMPXCHG8B (DI)
         JNE     loop
 	MOVL	p+0(FP),DI
 	MOVL	AX, 0(DI)
@@ -52,7 +43,7 @@
 	MOVL	p+0(FP), BX
 	MOVL	v+4(FP), CX
 	MOVL	CX, AX
-	LOCK; XADDL
+	LOCK; XADDL AX, (BX)
 	ADDL	CX, AX
 	RET
 
@@ -65,7 +56,7 @@
 	MOVL	DX, CX
 	ADDL	v+8(FP), BX
 	ADCL	v+12(FP), CX
-	LOCK; CMPXCHG64
+	LOCK; CMPXCHG8B (DI)
 	JNE	retry
 	MOVL	r+0(FP), DI
 	MOVL	BX, 0x0(DI)
@@ -79,7 +70,7 @@
 	MOVL	p+0(FP), CX
 	MOVL	ov+4(FP), AX
 	MOVL	nv+8(FP), DX
-	LOCK; CMPXCHG
+	LOCK; CMPXCHGL DX, (CX)
 	JNE	fail32
 	MOVL	$1,AX
 	RET
@@ -93,7 +84,7 @@
 	MOVL	ov+8(FP), DX
 	MOVL	nv+12(FP), BX
 	MOVL	nv+16(FP), CX
-	LOCK; CMPXCHG64
+	LOCK; CMPXCHG8B (DI)
 	JNE	fail64
 	MOVL	$1,AX
 	RET
@@ -105,5 +96,5 @@
 TEXT coherence+0(SB),1,$0
 	/* this is essentially mfence but that requires sse2 */
 	XORL	AX, AX
-	LOCK; XADDLSP
+	LOCK; XADDL AX, (SP)
 	RET