News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

x87 FPU and SSE/SSE2 Floating-Point Assists: A Comprehensive Guide for RosAsm

Started by guga, May 03, 2025, 06:31:07 AM

Previous topic - Next topic

guga

Hi Guys

Finished an article about the several different flags and masks used in FPU and SSE registers (Control Word, Status Words, mask and friends).

I hope this is clear and easier to follow as possible. I created a new set of equates to be used on this opcodes to make our life a bit easier when working with those masks.

It may be useful not only for RosAsm, but for masm users as well.

The pdf is bigger than the limit allowed on the forum, so here are the links where it can be downloaded:

 :icon_idea: Version2 of the article (Updated - 03/05/2025) - added more equates
Version2 - Updated
Verson 2 - Direct Link from the old forum
Link of the article on the main RosAsm old forum


version1 of the article
Link of the article on the main RosAsm old forum
Direct link
MediaFire
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

daydreamer

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

guga

Thanks a lot !  :thumbsup:  :thumbsup:  :thumbsup:  I'm creating two or three more equates to work better with these FPU and SSE masks. Once I'm done, I'll update the article if necessary, or I'll just post them as comments here.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

New equates added:

FPU_DEFAULT_CONTROL_WORD_ALL_MASKED   0x3F
FPU_DEFAULT_CONTROL_WORD_WITH_RESERVED   0x7F
SSE_MXCSR_CONTROL_ALL 0xFF80

FPU_DEFAULT_CONTROL_WORD_ALL_MASKED (0x03F): Combines all exception masks (bits 0-5: Invalid Operation, Denormalized, Zero Divide, Overflow, Underflow, Precision). Value: 0x01 + 0x02 + 0x04 + 0x08 + 0x10 + 0x20 = 0x3F. Use this when you want to ensure all exceptions are masked (default behavior) and bit 6 is 0, as recommended for modern CPUs.
Usage:

fnstcw W@ControlWord
mov ax &FPU_DEFAULT_CONTROL_WORD  ; Start with default (0x033F)
or ax &FPU_DEFAULT_CONTROL_WORD_ALL_MASKED  ; Ensure bits 0-5 are 1 (0x3F)
mov W@ControlWord ax
fldcw W@ControlWord

FPU_DEFAULT_CONTROL_WORD_WITH_RESERVED (0x7F): Extends FPU_DEFAULT_CONTROL_WORD_ALL_MASKED to include the reserved bit 6 (0x40). Value: 0x3F + 0x40 = 0x7F. Use this for compatibility with legacy configurations (e.g., float.h in C libraries) where bit 6 is set. Modern CPUs ignore bit 6, but some older software expects it to be 1.

Usage:

fnstcw W@FCW
mov ax W@FCW
and ax &FPU_DEFAULT_CONTROL_WORD_WITH_RESERVED
If ax = &FPU_DEFAULT_CONTROL_WORD_WITH_RESERVED
    mov eax &TRUE
Else
    mov eax &FALSE
End_If


SSE_MXCSR_CONTROL_ALL (0xFF80): To simplify working with the MXCSR's control bits (bits 6-15, covering DAZ, exception masks, rounding, and FTZ), we've added a new combined equate. This equate is designed for procedures like CheckEnvironment, where you need to verify or set these bits without worrying about status flags (bits 0-5).
Usage:
stmxcsr D@MXCSR
mov eax D@MXCSR
and eax &SSE_MXCSR_CONTROL_ALL
If eax = &SSE_MXCSR_FULL_OPTIMIZATION
    mov eax &TRUE
Else
    mov eax &FALSE
End_If
•   Covers bits 6-15: DAZ (bit 6), exception masks (bits 7-12), rounding mode (bits 13-14), and FTZ (bit 15).
•   Value: 0x0040 + 0x0080 + 0x0100 + 0x0200 + 0x0400 + 0x0800 + 0x1000 + 0x2000 + 0x4000 + 0x8000 = 0xFF80.
•   Use this to mask or set all control bits, ensuring a consistent SSE/SSE2 environment, especially when enabling performance optimizations like FTZ and DAZ.


Updated the article and posted the new links on the 1st post
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Quin

Very nice work, guga.
Also, off topic, but I love your signature!  :biggrin:

TimoVJL

Off topic:
signature of 10% of alcoholic levels in your blood don't conforms some of studies, like Microsoft, less than 1 %% can be useful.
For an example, richedit might not programmed in sober state and results we all know  :biggrin:

PS: i wasn't sober while writing this  :biggrin:
May the source be with you

Quin

Quote from: TimoVJL on May 03, 2025, 08:15:27 PMFor an example, richedit might not programmed in sober state and results we all know  :biggrin:
I'd say the alcohol levels had to be around 50% when they were programming Rich Edit...  :rofl:

zedd

Quote from: TimoVJL on May 03, 2025, 08:15:27 PMOff topic:
...
BS: i wasn't sober while writing this  :biggrin:

Is that really BS???
Or did you mean PS? Inebriation can cause those effects.  :joking:

In my case though I would think it a typo, or my iPads autocorrect 'assisting' me.  I do not partake in alcoholic beverages.
:cool:

TimoVJL

A that Microsoft study wasn't BS, but i don't have a link for it right now.
May the source be with you

zedd

Quote from: TimoVJL on May 03, 2025, 11:56:17 PMA that Microsoft study wasn't BS, but i don't have a link for it right now.

No, I wasn't talking about the Microsoft study. But what I assume was supposed to be your post script. I.e., BS vs. PS... :biggrin: 

Where you said "BS: i wasn't sober while writing this  :biggrin: "

My attempt at humor before having my morning coffee.
Now back to the originally scheduled topic. Sorry guga.
:cool:

TimoVJL

May the source be with you


guga

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

TimoVJL

@guga
You might be here with some funny people for you.
See things a their own way and you might like it.
May the source be with you

guga

Hi Timo.

I'm enjoying it. It's fun to read. :biggrin: :biggrin: :biggrin: I never thought anyone would notice the joke I put in my signature :bgrin: . But, regarding RichEdit, well... maybe we really need to have 50% alcohol in your bloodstream to get the right programs for RichEdit.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com