Changeset 1289 for trunk/src/emx/include/386/builtin.h
- Timestamp:
- Mar 15, 2004, 2:50:57 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/src/emx/include/386/builtin.h ¶
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r1288 r1289 39 39 __asm__ __volatile__ ("cli"); 40 40 } 41 42 /** 43 * Atomically sets a bit and return the old one. 44 * 45 * @returns 1 if the bit was set, 0 if it was clear. 46 * @param pv Pointer to base of bitmap. 47 * @param uBit Bit in question. 48 */ 49 static __inline__ int __atomic_set_bit(__volatile__ void *pv, unsigned uBit) 50 { 51 int rc; 52 __asm__ __volatile__("lock btsl %2, %1\n\t" 53 "sbbl %0,%0" 54 : "=r" (rc), 55 "=m" (*(__volatile__ unsigned *)pv) 56 : "r" (uBit) 57 : "memory"); 58 return rc; 59 } 60 61 62 /** 63 * Atomically clears a bit. 64 * 65 * @param pv Pointer to base of bitmap. 66 * @param uBit Bit in question. 67 */ 68 static __inline__ void __atomic_clear_bit(__volatile__ void *pv, unsigned uBit) 69 { 70 __asm__ __volatile__("lock btrl %1, %0" 71 : "=m" (*(__volatile__ unsigned *)pv) 72 : "r" (uBit)); 73 } 74 75 76 /** 77 * Atomically (er?) tests if a bit is set. 78 * 79 * @returns non zero if the bit was set. 80 * @returns 0 if the bit was clear. 81 * @param pv Pointer to base of bitmap. 82 * @param uBit Bit in question. 83 */ 84 static __inline__ int __atomic_test_bit(const __volatile__ void *pv, unsigned uBit) 85 { 86 __asm__ __volatile__("btl %0, %1\n\t" 87 "sbbl %0, %0\t\n" 88 : "=r" (uBit) 89 : "m" (*(const __volatile__ unsigned *)pv)); 90 return uBit; 91 } 92 93 94 /** 95 * Atomically increments a 32-bit unsigned value. 96 * 97 * @param pu Pointer to the value to increment. 98 */ 99 static __inline__ void __atomic_increment(__volatile__ unsigned *pu) 100 { 101 __asm__ __volatile__("lock incl %0" 102 : "=m" (*pu)); 103 } 104 105 /** 106 * Atomically decrements a 32-bit unsigned value. 107 * 108 * @param pu Pointer to the value to decrement. 109 */ 110 static __inline__ void __atomic_decrement(__volatile__ unsigned *pu) 111 { 112 __asm__ __volatile__("lock decl %0" 113 : "=m" (*pu)); 114 } 115 116 /** 117 * Atomically increments a 32-bit unsigned value if less than max. 118 * 119 * @returns 0 if incremented. 120 * @returns *pu + 1 when not updated. 121 * @param pu Pointer to the value to increment. 122 * @param uMax *pu must not be above this value. 123 */ 124 static __inline__ int __atomic_increment_max(__volatile__ unsigned *pu, unsigned uMax) 125 { 126 unsigned rc; 127 __asm__ __volatile__("movl %1, %%eax\n" 128 "1:\n\t" 129 "lea 1(%%eax), %0\n\t" 130 "cmpl %0, %2\n\t" 131 "jna 2f\n\t" 132 "jmp 4f\n" 133 "2:\n\t" 134 "lock cmpxchgl %0, %1\n\t" 135 "jz 3f\n\t" 136 "jmp 1b\n" 137 "3:" 138 "xorl %0, %0\n\t" 139 "4:" 140 : "=r" (rc), 141 "=m" (pu) 142 : "r" (uMax) 143 : "%eax"); 144 return rc; 145 } 146 147 148 /** 149 * Atomically decrements a 32-bit unsigned value if greater than a min. 150 * 151 * @returns 0 if incremented. 152 * @returns *pu + 1 when not updated. 153 * @param pu Pointer to the value to decrement. 154 * @param uMin *pu must not be below this value. 155 */ 156 static __inline__ int __atomic_increment_min(__volatile__ unsigned *pu, unsigned uMin) 157 { 158 unsigned rc; 159 __asm__ __volatile__("movl %1, %%eax\n" 160 "1:\n\t" 161 "lea -1(%%eax), %0\n\t" 162 "cmpl %0, %2\n\t" 163 "jnb 2f\n\t" 164 "jmp 4f\n" 165 "2:\n\t" 166 "lock cmpxchgl %0, %1\n\t" 167 "jz 3f\n\t" 168 "jmp 1b\n" 169 "3:" 170 "xorl %0, %0\n\t" 171 "4:" 172 : "=r" (rc), 173 "=m" (*pu) 174 : "r" (uMin) 175 : "%eax"); 176 return rc; 177 } 178 41 179 42 180 #define __ROTATE_FUN(F,I,T) \ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.