🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.asm
Article #2029

nie widzi stanu flag po “sub”?

#2029
From: gupi manʼaʼgo
Date: Wed, 23 Sep 2009 03:08
67 lines
2892 bytes
mamy strukturę, której istotny fragment jak niżej:
❝
struct s_t
{ // …
    unsigned n;
// …
};
❞
mamy dwie równoważne w efekcie procedury jak niżej:
❝
void
proc_1( struct s_t *s,
    unsigned count
)
{ if( s->n >= count )
        s->n -= count;
    else
        s->n = 0;
}
void
proc_2( struct s_t *s,
    unsigned count
)
{ if(( s->n -= count ) > count )
        s->n = 0;
}
❞
⁂
co zrobić, by kompilator ‟gcc 4.3.2” zauważył, że po odejmowaniu instru-
kcją “sub” ma  flagi, które może wykorzystać zamiast umieszczać instruk-
cje “cmp”?
a może ja się mylę?
❝
<proc_1>:
8b 47 10                mov    0x10(%rdi),%eax
39 f0                   cmp    %esi,%eax
73 08                   jae    0f
c7 47 10 00 00 00 00    movl   $0x0,0x10(%rdi)
c3                      retq
29 f0                0: sub    %esi,%eax
89 47 10                mov    %eax,0x10(%rdi)
c3                      retq
<proc_2>:
8b 57 10                mov    0x10(%rdi),%edx
29 f2                   sub    %esi,%edx
39 d6                   cmp    %edx,%esi   # nadmiarowa?
b8 00 00 00 00          mov    $0x0,%eax
0f 43 c2                cmovae %edx,%eax
89 47 10                mov    %eax,0x10(%rdi)
c3                      retq
❞
⁂
może w takiej kolejności, jeśli można :-) :
1.   czy się mylę?
2.   czy  kompilator robi to specjalnie ze względu na wewnętrzne działa-
nie ‘cpu’, któremu pomaga w czymś ta instrukcja “cmp”.
3.   co zrobić, by zapis w ‟C” był ładny, a mimo to nie było nadmiarowej
“cmp”?
4.   a jeśli  nic nie da się zrobić łatwo :-) , to  jak składniowo pytać
w ‟C” o odpowiednią flagę bez użycia wstawek “asm”?
⁂
PS   „drogie koleżanki i koledzy”…   aha, miało być na początku. ;->
-- 
/ qo   |)  :@=N%_g=v=a=g_eD_e=c()=d=8! =%!gN@8'Re. w8in/ad
\  _x/ ,  ;h-%-a'hA'H4,X0'Xo~xo~xO,R`-%EXp01ITed: *-7/+eh
/  |   ng `-%__%--'__%--'__%--~__%--^%B`/$qV3r[o; &GooMee
L_._o_O_*_^_"_'_`_ -> http://thereis.notlong.com <- `L"EnOF"
Technical Details
Message-ID: <h9c3fs$bi4$1@adenine.netfront.net>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!news.nask.pl!news.nask.org.pl!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!news.nask.pl!news.nask.org.pl!goblin3!goblin.stu.neva.ru!news.netfront.net!not-for-mail
From: gupi manʼaʼgo <2009czerwiec@inmail.sk>
Newsgroups: pl.comp.lang.c,pl.comp.lang.asm
Subject: nie widzi stanu flag po “sub”?
Date: Wed, 23 Sep 2009 03:08:47 +0000 (UTC)
Organization: opRWTng
Lines: 67
Message-ID: <h9c3fs$bi4$1@adenine.netfront.net>
NNTP-Posting-Host: 66.230.230.230
Mime-Version: 1.0
X-Trace: adenine.netfront.net 1253675327 11844 66.230.230.230 (23 Sep 2009 03:08:47 GMT)
X-Complaints-To: news@netfront.net
NNTP-Posting-Date: Wed, 23 Sep 2009 03:08:47 +0000 (UTC)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit