News:

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

Main Menu

Good old FPU question

Started by Gunther, May 02, 2022, 03:35:52 AM

Previous topic - Next topic

Gunther

I'm currently experimenting with numerics for Taylor series. In this context, I need rounding by truncation. Of course, this can be achieved by modifying the control word of the FPU.
But according to the current Intel manuals, the FPU instruction FISTTP - Store Integer with Truncation is existing.

Both JWASM for DOS and TASM 4 don't know this instruction. NASM, YASM and GAS, on the other hand, translate without complaint. What does ML for DOS say about this?
You have to know the facts before you can distort them.

daydreamer

You could write a macro for it,but it's later sse3 instruction so probably not supported in dos emulator
But macro that emulates it?
fadd 0.5
Fistp var
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

Gunther

Daydreamer,

Quote from: daydreamer on May 03, 2022, 07:22:37 AM
You could write a macro for it,but it's later sse3 instruction so probably not supported in dos emulator

you're right. Looks like an FPU instruction, but belongs to SSE3. I'll find another solution.
You have to know the facts before you can distort them.

HSE

Quote from: daydreamer on May 03, 2022, 07:22:37 AM
fadd fsub 0.5
Fistp var

:biggrin: That is the solution because default rounding mode is to-nearest. But it will fail if your number is already rounded.

A little perturbation can solve that, but depends what precision you need.
   .data
        uno          real8    1.0
        perturbation real8    1.0e-15
        cero5        real8    0.5
        a2           sdword   0
    .code
        fld uno
        fadd perturbation
        fsub cero5
        fistp a2
Equations in Assembly: SmplMath

Gunther

HSE,

Quote from: HSE on May 03, 2022, 08:52:07 AM
Quote from: daydreamer on May 03, 2022, 07:22:37 AM
fadd fsub 0.5
Fistp var

:biggrin: That is the solution because default rounding mode is to-nearest. But it will fail if your number is already rounded.

You're right. This is faster than modifying the rounding mode of the FPU.

Quote from: HSE on May 03, 2022, 08:52:07 AM
A little perturbation can solve that, but depends what precision you need.

Excellent idea. I think for REAL4 is 1e-5 good enough.
You have to know the facts before you can distort them.