[M3commit] CVS Update: cm3
Jay Krell
jkrell at elego.de
Sun Feb 14 13:02:21 CET 2010
CVSROOT: /usr/cvs
Changes by: jkrell at birch. 10/02/14 13:02:21
Modified files:
cm3/m3-sys/m3back/src/: M3x86.m3
Log message:
fix indirection in atomic fetch_and_op
just my ignorance using movOp instead of load_ind
code is like:
_Main__Test_AtomicInteger_FetchOr:
00000250: 8D 35 38 00 00 00 lea esi,[_MM_Main+38h] ; atomic variable
00000256: 8B 15 98 00 00 00 mov edx,dword ptr [_MM_Main+98h] ; value to or with
0000025C: 8B 06 mov eax,dword ptr [esi] ; fetch old value
0000025E: 8B D8 mov ebx,eax ; move old value to tmp (this is needed)
00000260: 0B DA or ebx,edx ; compute new value
00000262: F0 0F B1 1E lock cmpxchg dword ptr [esi],ebx ; try to swap
00000266: 75 F6 jne 0000025E
; old value is in eax (always eax; or edx:eax pair for 64bit operations, not yet implemented)
; new value is in, in this case, ebx
still could be better, could be:
mov edx,dword ptr [_MM_Main+98h]
mov eax,[_MM_Main+38h]
retry:
mov ebx,eax
or ebx,edx
lock cmpxchg [_MM_Main+38h],ebx
jne retry
; old value is in eax
; new value is in, in this case, ebx
six instructions instead of seven
three registers (eax, ebx, edx) instead of four (eax, ebx, edx, esi)
(problem is that we get load_address on the variable first,
and we go ahead and enregister that address unnecessarily)
And even so: if six instructions is considered too large, we can
use a function instead.
As well, add, sub, we can do more efficiently with xadd.
(still need to check what libatomic does here)
also we can probably optimize
or(-1) => store_ordered(-1)
or(0) => do nothing
and(-1) => do nothing
and(0) => store_ordered(0)
probably they are rare/nonexistant
More information about the M3commit
mailing list