Skip to contentSkip to conversation

PATCH: Not use branch likely on mips

PATCH H . J . Lu 3 participants 6 messages Feb 6, 2002 – Feb 8, 2002 MIPS

lore
Share & tools
lore

H . J . Lu

author
#0 lore raw

This patch removes branch likely.

H.J.
----
2002-02-05 H.J. Lu <[email protected]>

* sysdeps/mips/pspinlock.c (__pthread_spin_lock): Not use branch likely.
* sysdeps/mips/pt-machine.h (testandset): Liekwise. (__compare_and_swap): Liekwise.

2002-02-05 H.J. Lu <[email protected]>

* sysdeps/mips/atomicity.h (exchange_and_add): Not use branch likely.
(atomic_add): Likewise.
(compare_and_swap): Likewise.
* sysdeps/unix/sysv/linux/mips/sys/tas.h (_test_and_set):
Likewise.

linuxthreads/sysdeps/mips/pspinlock.c renamed from linuxthreads/sysdeps/mips/pspinlock.c.llsc +4 -5
@@ -32,17 +32,16 @@ __pthread_spin_lock (pthread_spinlock_t 
   unsigned int tmp1, tmp2;
 
   asm volatile
-    ("\t\t\t# spin_lock\n\t"
-     "ll	%1,%3\n"
+    ("\t\t\t# spin_lock\n"
      "1:\n\t"
+     "ll	%1,%3\n\t"
      ".set	push\n\t"
      ".set	noreorder\n\t"
      "bnez	%1,1b\n\t"
      " li	%2,1\n\t"
+     ".set	pop\n\t"
      "sc	%2,%0\n\t"
-     "beqzl	%2,1b\n\t"
-     " ll	%1,%3\n\t"
-     ".set	pop"
+     "beqz	%2,1b"
      : "=m" (*lock), "=&r" (tmp1), "=&r" (tmp2)
      : "m" (*lock)
      : "memory");
linuxthreads/sysdeps/mips/pt-machine.h renamed from linuxthreads/sysdeps/mips/pt-machine.h.llsc +4 -5
@@ -57,18 +57,17 @@ __compare_and_swap (long int *p, long in
   long int ret, temp;
 
   __asm__ __volatile__
-    ("/* Inline compare & swap */\n\t"
-     "ll	%1,%5\n"
+    ("/* Inline compare & swap */\n"
      "1:\n\t"
+     "ll	%1,%5\n\t"
      ".set	push\n\t"
      ".set	noreorder\n\t"
      "bne	%1,%3,2f\n\t"
      " move	%0,$0\n\t"
+     ".set	pop\n\t"
      "move	%0,%4\n\t"
      "sc	%0,%2\n\t"
-     "beqzl	%0,1b\n\t"
-     " ll	%1,%5\n\t"
-     ".set	pop\n"
+     "beqz	%0,1b\n"
      "2:\n\t"
      "/* End compare & swap */"
      : "=&r" (ret), "=&r" (temp), "=m" (*p)
sysdeps/mips/atomicity.h renamed from sysdeps/mips/atomicity.h.llsc +10 -19
@@ -32,16 +32,12 @@ exchange_and_add (volatile uint32_t *mem
   int result, tmp;
 
   __asm__ __volatile__
-    ("/* Inline exchange & add */\n\t"
-     "ll	%0,%3\n"
+    ("/* Inline exchange & add */\n"
      "1:\n\t"
+     "ll	%0,%3\n\t"
      "addu	%1,%4,%0\n\t"
      "sc	%1,%2\n\t"
-     ".set	push\n\t"
-     ".set	noreorder\n\t"
-     "beqzl	%1,1b\n\t"
-     " ll	%0,%3\n\t"
-     ".set	pop\n\t"
+     "beqz	%1,1b\n\t"
      "/* End exchange & add */"
      : "=&r"(result), "=&r"(tmp), "=m"(*mem)
      : "m" (*mem), "r"(val)
@@ -57,16 +53,12 @@ atomic_add (volatile uint32_t *mem, int 
   int result;
 
   __asm__ __volatile__
-    ("/* Inline atomic add */\n\t"
-     "ll	%0,%2\n"
+    ("/* Inline atomic add */\n"
      "1:\n\t"
+     "ll	%0,%2\n\t"
      "addu	%0,%3,%0\n\t"
      "sc	%0,%1\n\t"
-     ".set	push\n\t"
-     ".set	noreorder\n\t"
-     "beqzl	%0,1b\n\t"
-     " ll	%0,%2\n\t"
-     ".set	pop\n\t"
+     "beqz	%0,1b\n\t"
      "/* End atomic add */"
      : "=&r"(result), "=m"(*mem)
      : "m" (*mem), "r"(val)
@@ -80,18 +72,17 @@ compare_and_swap (volatile long int *p, 
   long int ret, temp;
 
   __asm__ __volatile__
-    ("/* Inline compare & swap */\n\t"
-     "ll	%1,%5\n"
+    ("/* Inline compare & swap */\n"
      "1:\n\t"
+     "ll	%1,%5\n\t"
      ".set	push\n\t"
      ".set	noreorder\n\t"
      "bne	%1,%3,2f\n\t"
      " move	%0,$0\n\t"
+     ".set	pop\n\t"
      "move	%0,%4\n\t"
      "sc	%0,%2\n\t"
-     "beqzl	%0,1b\n\t"
-     " ll	%1,%5\n\t"
-     ".set	pop\n"
+     "beqz	%0,1b\n"
      "2:\n\t"
      "/* End compare & swap */"
      : "=&r" (ret), "=&r" (temp), "=m" (*p)
sysdeps/unix/sysv/linux/mips/sys/tas.h renamed from sysdeps/unix/sysv/linux/mips/sys/tas.h.llsc +4 -5
@@ -42,17 +42,16 @@ _test_and_set (int *p, int v) __THROW
   int r, t;
 
   __asm__ __volatile__
-    ("/* Inline test and set */\n\t"
-     "ll	%0,%3\n"
+    ("/* Inline test and set */\n"
      "1:\n\t"
+     "ll	%0,%3\n\t"
      ".set	push\n\t"
      ".set	noreorder\n\t"
      "beq	%0,%4,2f\n\t"
      " move	%1,%4\n\t"
+     ".set	pop\n\t"
      "sc	%1,%2\n\t"
-     "beqzl	%1,1b\n\t"
-     " ll	%0,%3\n\t"
-     ".set	pop\n"
+     "beqz	%1,1b\n"
      "2:\n\t"
      "/* End test and set */"
      : "=&r" (r), "=&r" (t), "=m" (*p)
#1 lore raw
Quoted 1 line · H . J . Lu

This patch removes branch likely.

Please update the copyright years next time.

I've committed the patch,

Andreas

Quoted 19 lines

H.J.
----
2002-02-05 H.J. Lu <[email protected]>

* sysdeps/mips/pspinlock.c (__pthread_spin_lock): Not use branch likely.
* sysdeps/mips/pt-machine.h (testandset): Liekwise. (__compare_and_swap): Liekwise.

2002-02-05 H.J. Lu <[email protected]>

* sysdeps/mips/atomicity.h (exchange_and_add): Not use branch likely.
(atomic_add): Likewise.
(compare_and_swap): Likewise.
* sysdeps/unix/sysv/linux/mips/sys/tas.h (_test_and_set):
Likewise.
[...]

Signature · 4 lines
 Andreas Jaeger
  SuSE Labs [email protected]
   private [email protected]
    http://www.suse.de/~aj
author
#2 lore raw
Quoted 8 lines · Andreas Jaeger
Quoted 1 line · H . J . Lu

This patch removes branch likely.

Please update the copyright years next time.

I've committed the patch,

Here is a new patch. I have checked in a gcc patch which makes ".set noreorder" unnecessary even with "gcc -g".

Thanks.

H.J.
----
2002-02-07 H.J. Lu <[email protected]>

* sysdeps/mips/pspinlock.c (__pthread_spin_lock): Silence the gcc warning.
(__pthread_spin_lock): Remove ".set noreorder".
* sysdeps/mips/pt-machine.h (__compare_and_swap): Liekwise.

2002-02-07 H.J. Lu <[email protected]>

* sysdeps/mips/atomicity.h (compare_and_swap): Remove ".set noreorder".
* sysdeps/unix/sysv/linux/mips/sys/tas.h (_test_and_set):
Likewise.

linuxthreads/sysdeps/mips/pspinlock.c renamed from linuxthreads/sysdeps/mips/pspinlock.c.llsc +2 -5
@@ -35,11 +35,8 @@ __pthread_spin_lock (pthread_spinlock_t 
     ("\t\t\t# spin_lock\n"
      "1:\n\t"
      "ll	%1,%3\n\t"
-     ".set	push\n\t"
-     ".set	noreorder\n\t"
+     "li	%2,1\n\t"
      "bnez	%1,1b\n\t"
-     " li	%2,1\n\t"
-     ".set	pop\n\t"
      "sc	%2,%0\n\t"
      "beqz	%2,1b"
      : "=m" (*lock), "=&r" (tmp1), "=&r" (tmp2)
@@ -54,7 +51,7 @@ __pthread_spin_lock (pthread_spinlock_t 
 int
 __pthread_spin_lock (pthread_spinlock_t *lock)
 {
-  while (_test_and_set (lock, 1));
+  while (_test_and_set ((int *) lock, 1));
   return 0;
 }
 
linuxthreads/sysdeps/mips/pt-machine.h renamed from linuxthreads/sysdeps/mips/pt-machine.h.llsc +1 -4
@@ -60,11 +60,8 @@ __compare_and_swap (long int *p, long in
     ("/* Inline compare & swap */\n"
      "1:\n\t"
      "ll	%1,%5\n\t"
-     ".set	push\n\t"
-     ".set	noreorder\n\t"
+     "move	%0,$0\n\t"
      "bne	%1,%3,2f\n\t"
-     " move	%0,$0\n\t"
-     ".set	pop\n\t"
      "move	%0,%4\n\t"
      "sc	%0,%2\n\t"
      "beqz	%0,1b\n"
sysdeps/mips/atomicity.h renamed from sysdeps/mips/atomicity.h.llsc +1 -4
@@ -75,11 +75,8 @@ compare_and_swap (volatile long int *p, 
     ("/* Inline compare & swap */\n"
      "1:\n\t"
      "ll	%1,%5\n\t"
-     ".set	push\n\t"
-     ".set	noreorder\n\t"
+     "move	%0,$0\n\t"
      "bne	%1,%3,2f\n\t"
-     " move	%0,$0\n\t"
-     ".set	pop\n\t"
      "move	%0,%4\n\t"
      "sc	%0,%2\n\t"
      "beqz	%0,1b\n"
sysdeps/unix/sysv/linux/mips/sys/tas.h renamed from sysdeps/unix/sysv/linux/mips/sys/tas.h.llsc +1 -4
@@ -45,11 +45,8 @@ _test_and_set (int *p, int v) __THROW
     ("/* Inline test and set */\n"
      "1:\n\t"
      "ll	%0,%3\n\t"
-     ".set	push\n\t"
-     ".set	noreorder\n\t"
+     "move	%1,%4\n\t"
      "beq	%0,%4,2f\n\t"
-     " move	%1,%4\n\t"
-     ".set	pop\n\t"
      "sc	%1,%2\n\t"
      "beqz	%1,1b\n"
      "2:\n\t"
#3 lore raw
Quoted 5 lines · H . J . Lu
Quoted 4 lines · Andreas Jaeger
Quoted 1 line · H . J . Lu

This patch removes branch likely.

Quoted 7 lines
Quoted 4 lines

Please update the copyright years next time.

I've committed the patch,

Here is a new patch. I have checked in a gcc patch which makes ".set noreorder" unnecessary even with "gcc -g".

But what about current GCC releases? Does it work there also without problems?

Andreas

Signature · 4 lines
 Andreas Jaeger
  SuSE Labs [email protected]
   private [email protected]
    http://www.suse.de/~aj
#4 lore raw
Quoted 5 lines · Andreas Jaeger
Quoted 2 lines

Here is a new patch. I have checked in a gcc patch which makes ".set noreorder" unnecessary even with "gcc -g".

But what about current GCC releases? Does it work there also without problems?

At worst you lose a few cycles for superfluous nops.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#5 lore raw
In reply to H . J . Lu
Quoted 7 lines · H . J . Lu
Quoted 6 lines · Andreas Jaeger
Quoted 1 line · H . J . Lu

This patch removes branch likely.

Please update the copyright years next time.

Quoted 7 lines
Quoted 2 lines

I've committed the patch,

Here is a new patch. I have checked in a gcc patch which makes ".set noreorder" unnecessary even with "gcc -g".

Thanks.

Thanks, committed,

Andreas

Signature · 4 lines
 Andreas Jaeger
  SuSE Labs [email protected]
   private [email protected]
    http://www.suse.de/~aj