Changeset 1454 for trunk/src/emx/include/386/builtin.h
- Timestamp:
- Sep 4, 2004, 8:22:38 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/include/386/builtin.h
-
Property cvs2svn:cvs-rev
changed from
1.6
to1.7
r1453 r1454 7 7 #define _I386_BUILTIN_H 8 8 9 #if defined (__cplusplus) 10 extern "C" { 11 #endif 9 #include <sys/cdefs.h> 10 #include <stdint.h> 11 12 __BEGIN_DECLS 13 12 14 13 15 static __inline__ signed char __cxchg (__volatile__ signed char *p, … … 40 42 } 41 43 44 45 /** 46 * Performs an atomical xchg on an unsigned int. 47 * @returns old value. 48 * @param pu Pointer to the value to update. 49 * @param u The new value. 50 */ 51 static __inline__ unsigned __atomic_xchg(__volatile__ unsigned *pu, unsigned u) 52 { 53 __asm__ __volatile__ ("xchgl %0, %1" : "=m" (*pu), "=r" (u) : "1" (u)); 54 return u; 55 } 56 57 /** 58 * Performs an atomical xchg on an 16-bit unsigned integer. 59 * 60 * @returns old value. 61 * @param pu16 Pointer to the value to update. 62 * @param u16 The new value. 63 */ 64 static inline uint16_t __atomic_xchg_word(volatile uint16_t *pu16, uint16_t u16) 65 { 66 __asm__ __volatile__ ("xchgw %0, %1" : "=m" (*pu16), "=r" (u16) : "1" (u16)); 67 return u16; 68 } 69 42 70 /** 43 71 * Atomically sets a bit and return the old one. 44 72 * 45 * @returns 1 if the b it was set, 0 if it was clear.73 * @returns 1 if the bwit was set, 0 if it was clear. 46 74 * @param pv Pointer to base of bitmap. 47 75 * @param uBit Bit in question. … … 89 117 "0" (uBit)); 90 118 return uBit; 119 } 120 121 122 /** 123 * Atomically add a 32-bit unsigned value to another. 124 * 125 * @param pu Pointer to the value to add to. 126 * @param uAdd The value to add to *pu. 127 */ 128 static __inline__ void __atomic_add(__volatile__ unsigned *pu, unsigned uAdd) 129 { 130 __asm__ __volatile__("lock addl %1, %0" 131 : "=m" (*pu) 132 : "r" (uAdd)); 133 } 134 135 /** 136 * Atomically subtract a 32-bit unsigned value from another. 137 * 138 * @param pu Pointer to the value to subtract from. 139 * @param uAdd The value to subtract from *pu. 140 */ 141 static __inline__ void __atomic_sub(__volatile__ unsigned *pu, unsigned uSub) 142 { 143 __asm__ __volatile__("lock subl %1, %0" 144 : "=m" (*pu) 145 : "r" (uSub)); 91 146 } 92 147 … … 148 203 149 204 /** 205 * Atomically increments a 16-bit unsigned value if less than max. 206 * 207 * @returns New value. 208 * @returns Current value | 0xffff0000 if current value is less or equal to u16Min. 209 * @param pu16 Pointer to the value to increment. 210 * @param u16Max *pu16 must not be above this value after the incrementation. 211 */ 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 "1:\n\t" 217 "movw %%ax, %%bx\n\t" 218 "cmpw %%dx, %%ax\n\t" 219 "jb 2f\n\t" 220 "orl $0xffff0000, %%ebx\n\t" 221 "jmp 3f\n" 222 "2:\n\t" 223 "incw %%bx\n\t" 224 "lock cmpxchgw %%bx, (%1)\n\t" 225 "jz 3f\n\t" 226 "jmp 1b\n\t" 227 "3:" 228 : "=b" (rc) 229 : "r" (pu16), 230 "d" (u16Max) 231 : "%eax"); 232 return rc; 233 } 234 235 236 /** 150 237 * Atomically decrements a 32-bit unsigned value if greater than a min. 151 238 * … … 180 267 181 268 269 /** 270 * Atomically decrements a 16-bit unsigned value if greater than a min. 271 * 272 * @returns New value. 273 * @returns Current value | 0xffff0000 if current value is less or equal to u16Min. 274 * @param pu16 Pointer to the value to decrement. 275 * @param u16Min *pu16 must not be below this value after the decrementation. 276 */ 277 static inline unsigned __atomic_decrement_word_min(volatile uint16_t *pu16, uint16_t u16Min) 278 { 279 unsigned rc; 280 __asm__ __volatile__("movw (%1), %%ax\n" 281 "1:\n\t" 282 "movw %%ax, %%bx\n\t" 283 "cmpw %%dx, %%ax\n\t" 284 "ja 2f\n\t" 285 "orl $0xffff0000, %%ebx\n\t" 286 "jmp 3f\n" 287 "2:\n\t" 288 "decw %%bx\n\t" 289 "lock cmpxchgw %%bx, (%1)\n\t" 290 "jz 3f\n\t" 291 "jmp 1b\n" 292 "3:" 293 : "=b" (rc) 294 : "r" (pu16), 295 "d" (u16Min) 296 : "%eax"); 297 return rc; 298 } 299 300 182 301 #define __ROTATE_FUN(F,I,T) \ 183 302 static __inline__ T F (T value, int shift) \ … … 356 475 } 357 476 358 #if defined (__cplusplus) 359 } 360 #endif 361 477 __END_DECLS 362 478 #endif /* not _I386_BUILTIN_H */ -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.