flat assembler
Message board for the users of flat assembler.
Index
> Main > FPU Conditional Testing; What's wrong with this code? |
Author |
|
revolution 18 Feb 2010, 09:05
Hint: Look at the sahf opcode. It probably does everything you want without needing all those complicated 'test' instructions.
|
|||
18 Feb 2010, 09:05 |
|
LocoDelAssembly 18 Feb 2010, 16:55
Or he could just take a look to FCOMI/FCOMIP, I think that very few still-working old computers won't work with it.
|
|||
18 Feb 2010, 16:55 |
|
revolution 18 Feb 2010, 17:00
BTW: Why do you have the 'mov eax,0' after every fnstsw?
Code: FNSTSW ax mov eax,0 ;<---- What is this for? |
|||
18 Feb 2010, 17:00 |
|
bitshifter 18 Feb 2010, 21:15
Here a snippet...
Code: fld [value] fld [max] ; 60.0 for example (>0) fcom fnstsw ax sahf jc .clamp fstp st0 fld [min] ; -60.0 for example (<0) fcom fnstsw ax sahf jc .noclamp .clamp: fxch .noclamp: fstp st0 fstp [value] Also you can gain speed in some cases by just checking sign bit... |
|||
18 Feb 2010, 21:15 |
|
fasmnub 18 Feb 2010, 21:55
@bitshifter, @revolution
perfect! just what i needed, thanks both! |
|||
18 Feb 2010, 21:55 |
|
LocoDelAssembly 18 Feb 2010, 22:27
Sorry to insist but is really so problematic FCOMI?
Code: fld [value] fld [max] ; 60.0 for example (>0) fcomi jc .clamp fstp st0 fld [min] ; -60.0 for example (<0) fcomi jc .noclamp .clamp: fxch .noclamp: fstp st0 fstp [value] |
|||
18 Feb 2010, 22:27 |
|
bitshifter 19 Feb 2010, 02:28
Thanks Loco!
No need to apologize when posting nicer code. I wish you would insist a little more often Also, if you have SSE2 and can find some way to have the need to min/max 4 floats at the same time (even in less clocks) Code: ; data is assumed to be aligned on 16 byte boundary! movaps xmm0,[_4values] maxps xmm0,[_4mins] minps xmm0,[_4maxes] movaps [_4results],xmm0 So to make it work, the data need to be like this... Code: align 16 _4values dd 0.0,0.0,0.0,0.0 _4mins dd 0.0,0.0,0.0,0.0 _4maxes dd 0.0,0.0,0.0,0.0 _4results dd 0.0,0.0,0.0,0.0 ; TODO: Give values something valid... Have fun |
|||
19 Feb 2010, 02:28 |
|
bitshifter 19 Feb 2010, 14:44
Ooh, i just cant stop playing with this...
So now we use a conditional move (no jumping) Code: fld [value] fld [max] fcomi st0,st1 fcmovnb st0,st1 fxch fstp st0 fld [min] fcomi st0,st1 fcmovb st0,st1 fstp [result] fstp st0 Just for fun |
|||
19 Feb 2010, 14:44 |
|
LocoDelAssembly 19 Feb 2010, 15:27
And seems that fcmov was introduced in PPro too so you are not adding extra hardware requirements
|
|||
19 Feb 2010, 15:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.