The MASM Forum

General => The Campus => Topic started by: Gunther on May 02, 2022, 03:35:52 AM

Title: Good old FPU question
Post by: Gunther on May 02, 2022, 03:35:52 AM
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?
Title: Re: Good old FPU question
Post by: 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
But macro that emulates it?
fadd 0.5
Fistp var
Title: Re: Good old FPU question
Post by: Gunther on May 03, 2022, 08:24:50 AM
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.
Title: Re: Good old FPU question
Post by: 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.

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
Title: Re: Good old FPU question
Post by: Gunther on May 03, 2022, 09:45:25 AM
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.