Ignore:
Timestamp:
Mar 20, 2005, 1:16:43 AM (20 years ago)
Author:
bird
Message:

Fixed atomic inc/dec inline functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/386/builtin.h

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1875 r1876  
    126126 * @param   uAdd    The value to add to *pu.
    127127 */
    128 static __inline__ void __atomic_add(__volatile__ unsigned *pu, unsigned uAdd)
     128static __inline__ void __atomic_add(__volatile__ unsigned *pu, const unsigned uAdd)
    129129{
    130130    __asm__ __volatile__("lock addl %1, %0"
    131131                         : "=m" (*pu)
    132                          : "r" (uAdd));
     132                         : "nr" (uAdd),
     133                           "m"  (*pu));
    133134}
    134135
     
    139140 * @param   uAdd    The value to subtract from *pu.
    140141 */
    141 static __inline__ void __atomic_sub(__volatile__ unsigned *pu, unsigned uSub)
     142static __inline__ void __atomic_sub(__volatile__ unsigned *pu, const unsigned uSub)
    142143{
    143144    __asm__ __volatile__("lock subl %1, %0"
    144145                         : "=m" (*pu)
    145                          : "r" (uSub));
     146                         : "nr" (uSub),
     147                           "m"  (*pu));
    146148}
    147149
     
    155157{
    156158    __asm__ __volatile__("lock incl %0"
    157                          : "=m" (*pu));
     159                         : "=m" (*pu)
     160                         : "m"  (*pu));
    158161}
    159162
     
    166169{
    167170    __asm__ __volatile__("lock decl %0"
    168                          : "=m" (*pu));
     171                         : "=m" (*pu)
     172                         : "m"  (*pu));
    169173}
    170174
     
    177181 * @param   uMax    *pu must not be above this value.
    178182 */
    179 static __inline__ int __atomic_increment_max(__volatile__ unsigned *pu, unsigned uMax)
     183static __inline__ int __atomic_increment_max(__volatile__ unsigned *pu, const unsigned uMax)
    180184{
    181185    unsigned rc;
    182     __asm__ __volatile__("movl  (%1), %%eax\n\t"
     186    __asm__ __volatile__("movl  %2, %%eax\n\t"
    183187                         "1:\n\t"
    184                          "lea   1(%%eax), %0\n\t"
    185                          "cmpl  %2, %0\n\t"
    186                          "jna   2f\n\t"
    187                          "decl  %0\n\t"
     188                         "movl  %%eax, %0\n\t"
     189                         "cmpl  %3, %0\n\t"
     190                         "jb    2f\n\t"
    188191                         "jmp   4f\n"
    189192                         "2:\n\t"
    190                          "lock  cmpxchgl %0, (%1)\n\t"
     193                         "incl  %0\n\t"
     194                         "lock  cmpxchgl %0, %1\n\t"
    191195                         "jz    3f\n\t"
    192196                         "jmp   1b\n"
     
    194198                         "xorl  %0, %0\n\t"
    195199                         "4:"
    196                          : "=b" (rc)
    197                          : "c"  (pu),
    198                            "d"  (uMax)
     200                         : "=b" (rc),
     201                           "=m" (*pu)
     202                         : "m"  (*pu),
     203                           "nd" (uMax),
     204                           "0"  (rc)
    199205                         : "%eax");
    200206    return rc;
     
    210216 * @param   u16Max  *pu16 must not be above this value after the incrementation.
    211217 */
    212 static inline unsigned __atomic_increment_word_max(volatile uint16_t *pu16, uint16_t u16Max)
    213 {
    214     unsigned rc;
    215     __asm__ __volatile__("movw  (%1), %%ax\n\t"
    216                          "xorl  %%ebx, %%ebx\n\t"
     218static inline unsigned __atomic_increment_word_max(volatile uint16_t *pu16, const uint16_t u16Max)
     219{
     220    unsigned rc = 0;
     221    __asm__ __volatile__("movw  %2, %%ax\n\t"
    217222                         "1:\n\t"
    218                          "movw  %%ax, %%bx\n\t"
    219                          "cmpw  %%dx, %%ax\n\t"
     223                         "movw  %%ax, %w0\n\t"
     224                         "cmpw  %w3, %%ax\n\t"
    220225                         "jb    2f\n\t"
    221                          "orl   $0xffff0000, %%ebx\n\t"
     226                         "orl   $0xffff0000, %0\n\t"
    222227                         "jmp   3f\n"
    223228                         "2:\n\t"
    224                          "incw  %%bx\n\t"
    225                          "lock  cmpxchgw %%bx, (%1)\n\t"
     229                         "incw  %w0\n\t"
     230                         "lock  cmpxchgw %w0, %2\n\t"
    226231                         "jz    3f\n\t"
    227232                         "jmp   1b\n\t"
    228233                         "3:"
    229                          : "=b" (rc)
    230                          : "r"  (pu16),
    231                            "d"  (u16Max)
     234                         : "=r" (rc),
     235                           "=m" (*pu16)
     236                         : "m"  (*pu16),
     237                           "nr"  (u16Max),
     238                           "0"  (rc)
    232239                         : "%eax");
    233240    return rc;
     
    243250 * @param   uMin    *pu must not be below this value.
    244251 */
    245 static __inline__ int __atomic_decrement_min(__volatile__ unsigned *pu, unsigned uMin)
     252static __inline__ int __atomic_decrement_min(__volatile__ unsigned *pu, const unsigned uMin)
    246253{
    247254    unsigned rc;
    248     __asm__ __volatile__("movl  (%1), %%eax\n"
     255    __asm__ __volatile__("movl  %2, %%eax\n"
    249256                         "1:\n\t"
    250                          "lea   -1(%%eax), %0\n\t"
    251                          "cmpl  %2, %0\n\t"
    252                          "jnb   2f\n\t"
    253                          "incl  %0\n\t"
     257                         "movl  %%eax, %0\n\t"
     258                         "cmpl  %3, %0\n\t"
     259                         "ja    2f\n\t"
    254260                         "jmp   4f\n"
    255261                         "2:\n\t"
    256                          "lock  cmpxchgl %0, (%1)\n\t"
     262                         "decl  %0\n\t"
     263                         "lock  cmpxchgl %0, %1\n\t"
    257264                         "jz    3f\n\t"
    258265                         "jmp   1b\n"
     
    260267                         "xorl  %0, %0\n\t"
    261268                         "4:"
    262                          : "=b" (rc)
    263                          : "c"  (pu),
    264                            "d"  (uMin)
     269                         : "=b" (rc),
     270                           "=m" (*pu)
     271                         : "m"  (*pu),
     272                           "nr" (uMin),
     273                           "0"  (rc)
    265274                         : "%eax");
    266275    return rc;
     
    276285 * @param   u16Min  *pu16 must not be below this value after the decrementation.
    277286 */
    278 static inline unsigned __atomic_decrement_word_min(volatile uint16_t *pu16, uint16_t u16Min)
    279 {
    280     unsigned rc;
    281     __asm__ __volatile__("movw  (%1), %%ax\n\t"
    282                          "xorl  %%ebx, %%ebx\n\t"
     287static inline unsigned __atomic_decrement_word_min(volatile uint16_t *pu16, const uint16_t u16Min)
     288{
     289    unsigned rc = 0;
     290    __asm__ __volatile__("movw  %2, %%ax\n\t"
    283291                         "1:\n\t"
    284                          "movw  %%ax, %%bx\n\t"
    285                          "cmpw  %%dx, %%ax\n\t"
     292                         "movw  %%ax, %w0\n\t"
     293                         "cmpw  %w3, %%ax\n\t"
    286294                         "ja    2f\n\t"
    287                          "orl   $0xffff0000, %%ebx\n\t"
     295                         "orl   $0xffff0000, %0\n\t"
    288296                         "jmp   3f\n"
    289297                         "2:\n\t"
    290298                         "decw  %%bx\n\t"
    291                          "lock  cmpxchgw %%bx, (%1)\n\t"
     299                         "lock  cmpxchgw %w0, %1\n\t"
    292300                         "jz    3f\n\t"
    293301                         "jmp   1b\n"
    294302                         "3:"
    295                          : "=b" (rc)
    296                          : "r"  (pu16),
    297                            "d"  (u16Min)
     303                         : "=b" (rc),
     304                           "=m" (*pu16)
     305                         : "m"  (*pu16),
     306                           "nr" (u16Min),
     307                           "0"  (rc)
    298308                         : "%eax");
    299309    return rc;
Note: See TracChangeset for help on using the changeset viewer.