Author Topic: Simple floating point macros.  (Read 10429 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7553
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Simple floating point macros.
« Reply #105 on: August 21, 2018, 06:06:58 PM »
Magnus,

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

LOCAL num
num = 1
mov rax, num
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

HSE

  • Member
  • *****
  • Posts: 1383
  • <AMD>< 7-32>
Re: Simple floating point macros.
« Reply #106 on: August 21, 2018, 08:43: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!"

daydreamer

  • Member
  • *****
  • Posts: 1364
  • building nextdoor
Re: Simple floating point macros.
« Reply #107 on: August 21, 2018, 11:12:51 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
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

jj2007

  • Member
  • *****
  • Posts: 10557
  • Assembler is fun ;-)
    • MasmBasic
Re: Simple floating point macros.
« Reply #108 on: August 21, 2018, 11:18:19 PM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 7553
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Simple floating point macros.
« Reply #109 on: August 22, 2018, 01:14:39 AM »
 :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 ?
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10557
  • Assembler is fun ;-)
    • MasmBasic
Re: Simple floating point macros.
« Reply #110 on: August 22, 2018, 03:07:44 AM »
Yeah, the Watcom folks are innovative :P

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7553
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Simple floating point macros.
« Reply #111 on: August 22, 2018, 09:15:24 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Caché GB

  • Member
  • **
  • Posts: 97
  • MASM IS HOT
Re: Simple floating point macros.
« Reply #112 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)

May be like this

    local  TheRealDeal:real4

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

daydreamer

  • Member
  • *****
  • Posts: 1364
  • building nextdoor
Re: Simple floating point macros.
« Reply #113 on: August 22, 2018, 07:35:36 PM »
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


Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

jj2007

  • Member
  • *****
  • Posts: 10557
  • Assembler is fun ;-)
    • MasmBasic
Re: Simple floating point macros.
« Reply #114 on: August 22, 2018, 08:00:24 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):
Code: [Select]
  push 4640E6B7h
  fld REAL4 ptr [esp]
  pop edx

Code: [Select]
  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--

  • Administrator
  • Member
  • ******
  • Posts: 7553
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Simple floating point macros.
« Reply #115 on: August 22, 2018, 09:55:48 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: