News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Simple floating point macros.

Started by hutch--, August 13, 2018, 04:36:54 PM

Previous topic - Next topic

hutch--

Magnus,

In macros, a number when added to code is an immediate integer.

LOCAL num
num = 1
mov rax, num

HSE

Quote from: daydreamer on August 21, 2018, 06:01:33 PM
these variables in macros, are they restricted to be 32bit integers,or can you make macros which have floating Point math inside them too?

You can use qWord's "MREAL macros - when you need floating point arithmetic while assembling!"
Equations in Assembly: SmplMath

daydreamer

Quote from: HSE on August 21, 2018, 08:43:33 PM
Quote from: daydreamer on August 21, 2018, 06:01:33 PM
these variables in macros, are they restricted to be 32bit integers,or can you make macros which have floating Point math inside them too?

You can use qWord's "MREAL macros - when you need floating point arithmetic while assembling!"
thanks
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

jj2007

Works like a charm, but you need a modern assembler, e.g. UAsm or AsmC:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  push 123.4567
  fld stack
  Print Str$("ST(0)=%f", ST(0)v)  ; output: ST(0)=123.4567
EndOfCode

hutch--

 :biggrin:

push 123.4567

"push" is an Intel mnemonic that works on integer data, not floating point. Are you suggesting that the Watcom forks are not Intel compatible ?

jj2007

Yeah, the Watcom folks are innovative :P

hutch--

Yeah, they have to be with the quality of code they must process.  :P

MASM is for folks who already know how to write assembler.

Caché GB

How does a modern assembler implement this

    local  TheNoReal:real4

         push  123.4567
          pop  TheNoReal

under the cover? (of darkness)

May be like this

    local  TheRealDeal:real4

         push  042F6E9D5h  ;; 123.4567
          pop  TheRealDeal
Caché GB's 1 and 0-nly language:MASM

daydreamer

I want to write a crossover macro for rotation
I have read a tutorial long ago about rotation and now I read a different tutorial that showed it simpler so I got an idea
X1 =  X0 * cos(theta)  +  Y0 * sin(theta)
      Y1 = -X0 * sin(theta)  +  Y0 * cos(theta)

so you need 4 values:sin alpha,cos alpha,-sin alpha and a second copy of cos alpha for prepare for many MULPS/HADDPS combo rotating many pixels or meshes...or maybe you want to use fpu afterwards so I follow Hutch's rule about leaving them in fpu registers

I dont what name it should have
prerotate alpha MACRO
fld alpha
fmul degtorad ;degtoradconstant=pi/180
fsincos ;st0 cos,st1 sin
fld st1 ;st0 sin,st1 cos,st2 sin
fchs ;st0 -sin,st1 cos,st2 sin
fld st1 ;st0 cos,st1-sin,st2 cos,st3 sin
ENDM


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

jj2007

Quote from: Caché GB on August 22, 2018, 02:21:46 PM
How does a modern assembler implement this

    local  TheNoReal:real4

         push  123.4567
          pop  TheNoReal

under the cover? (of darkness)

Not so difficult. Here is a simulation:

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  push eax                              ; create a dword slot   
  fld FP10(12345.67890)                 ; load the FPU with the desired value
  fstp REAL4 ptr [esp]                  ; pop the real10 into the dword slot
  pop eax                               ; and get the corresponding integer
  Inkey "Use this hex value to push REAL4: ", Hex$(eax), "h"
EndOfCode


Output: Use this hex value to push REAL4: 4640E6B7h

Btw it's rarely worth the effort. These two snippets do the same, load 123... into ST(0):
  push 4640E6B7h
  fld REAL4 ptr [esp]
  pop edx


  fld FP4(12345.67890)

The first one is only one byte shorter, considering that FP4 creates a slot in the .DATA section. Speedwise the latter is faster.

hutch--

If you are loading data to data, there is no problem using an integer register as the transfer medium so you can move a FP value to another if both are memory operands using a 32 bit register.

.data
fval REAL4 1234.5678
......
.code
LOCAL lval :REAL4
......
mov eax, fval
mov lval, eax

The only place I have needed to do this in 64 bit MASM is in getting the return value from a floating point conversion.