linux/arch/sparc/lib/bitops.S
<<
>>
Prefs
   1/* bitops.S: Sparc64 atomic bit operations.
   2 *
   3 * Copyright (C) 2000, 2007 David S. Miller (davem@davemloft.net)
   4 */
   5
   6#include <asm/asi.h>
   7#include <asm/backoff.h>
   8
   9        .text
  10
  11        .globl  test_and_set_bit
  12        .type   test_and_set_bit,#function
  13test_and_set_bit:       /* %o0=nr, %o1=addr */
  14        BACKOFF_SETUP(%o3)
  15        srlx    %o0, 6, %g1
  16        mov     1, %o2
  17        sllx    %g1, 3, %g3
  18        and     %o0, 63, %g2
  19        sllx    %o2, %g2, %o2
  20        add     %o1, %g3, %o1
  211:      ldx     [%o1], %g7
  22        or      %g7, %o2, %g1
  23        casx    [%o1], %g7, %g1
  24        cmp     %g7, %g1
  25        bne,pn  %xcc, 2f
  26         and    %g7, %o2, %g2
  27        clr     %o0
  28        movrne  %g2, 1, %o0
  29        retl
  30         nop
  312:      BACKOFF_SPIN(%o3, %o4, 1b)
  32        .size   test_and_set_bit, .-test_and_set_bit
  33
  34        .globl  test_and_clear_bit
  35        .type   test_and_clear_bit,#function
  36test_and_clear_bit:     /* %o0=nr, %o1=addr */
  37        BACKOFF_SETUP(%o3)
  38        srlx    %o0, 6, %g1
  39        mov     1, %o2
  40        sllx    %g1, 3, %g3
  41        and     %o0, 63, %g2
  42        sllx    %o2, %g2, %o2
  43        add     %o1, %g3, %o1
  441:      ldx     [%o1], %g7
  45        andn    %g7, %o2, %g1
  46        casx    [%o1], %g7, %g1
  47        cmp     %g7, %g1
  48        bne,pn  %xcc, 2f
  49         and    %g7, %o2, %g2
  50        clr     %o0
  51        movrne  %g2, 1, %o0
  52        retl
  53         nop
  542:      BACKOFF_SPIN(%o3, %o4, 1b)
  55        .size   test_and_clear_bit, .-test_and_clear_bit
  56
  57        .globl  test_and_change_bit
  58        .type   test_and_change_bit,#function
  59test_and_change_bit:    /* %o0=nr, %o1=addr */
  60        BACKOFF_SETUP(%o3)
  61        srlx    %o0, 6, %g1
  62        mov     1, %o2
  63        sllx    %g1, 3, %g3
  64        and     %o0, 63, %g2
  65        sllx    %o2, %g2, %o2
  66        add     %o1, %g3, %o1
  671:      ldx     [%o1], %g7
  68        xor     %g7, %o2, %g1
  69        casx    [%o1], %g7, %g1
  70        cmp     %g7, %g1
  71        bne,pn  %xcc, 2f
  72         and    %g7, %o2, %g2
  73        clr     %o0
  74        movrne  %g2, 1, %o0
  75        retl
  76         nop
  772:      BACKOFF_SPIN(%o3, %o4, 1b)
  78        .size   test_and_change_bit, .-test_and_change_bit
  79
  80        .globl  set_bit
  81        .type   set_bit,#function
  82set_bit:                /* %o0=nr, %o1=addr */
  83        BACKOFF_SETUP(%o3)
  84        srlx    %o0, 6, %g1
  85        mov     1, %o2
  86        sllx    %g1, 3, %g3
  87        and     %o0, 63, %g2
  88        sllx    %o2, %g2, %o2
  89        add     %o1, %g3, %o1
  901:      ldx     [%o1], %g7
  91        or      %g7, %o2, %g1
  92        casx    [%o1], %g7, %g1
  93        cmp     %g7, %g1
  94        bne,pn  %xcc, 2f
  95         nop
  96        retl
  97         nop
  982:      BACKOFF_SPIN(%o3, %o4, 1b)
  99        .size   set_bit, .-set_bit
 100
 101        .globl  clear_bit
 102        .type   clear_bit,#function
 103clear_bit:              /* %o0=nr, %o1=addr */
 104        BACKOFF_SETUP(%o3)
 105        srlx    %o0, 6, %g1
 106        mov     1, %o2
 107        sllx    %g1, 3, %g3
 108        and     %o0, 63, %g2
 109        sllx    %o2, %g2, %o2
 110        add     %o1, %g3, %o1
 1111:      ldx     [%o1], %g7
 112        andn    %g7, %o2, %g1
 113        casx    [%o1], %g7, %g1
 114        cmp     %g7, %g1
 115        bne,pn  %xcc, 2f
 116         nop
 117        retl
 118         nop
 1192:      BACKOFF_SPIN(%o3, %o4, 1b)
 120        .size   clear_bit, .-clear_bit
 121
 122        .globl  change_bit
 123        .type   change_bit,#function
 124change_bit:             /* %o0=nr, %o1=addr */
 125        BACKOFF_SETUP(%o3)
 126        srlx    %o0, 6, %g1
 127        mov     1, %o2
 128        sllx    %g1, 3, %g3
 129        and     %o0, 63, %g2
 130        sllx    %o2, %g2, %o2
 131        add     %o1, %g3, %o1
 1321:      ldx     [%o1], %g7
 133        xor     %g7, %o2, %g1
 134        casx    [%o1], %g7, %g1
 135        cmp     %g7, %g1
 136        bne,pn  %xcc, 2f
 137         nop
 138        retl
 139         nop
 1402:      BACKOFF_SPIN(%o3, %o4, 1b)
 141        .size   change_bit, .-change_bit
 142