Author Topic: if-elseif Mab's macros for floating comparisons  (Read 1935 times)

HSE

  • Member
  • *****
  • Posts: 2197
  • AMD 7-32 / i3 10-64
if-elseif Mab's macros for floating comparisons
« on: September 08, 2020, 08:54:30 AM »
Hi all!

Some extension of Mabdelouahab's macros that allow floating point numbers comparisons for conditional flow easily (usually it's not so simple because early expansion).

Code: [Select]
  mov wParam, 1
    mov pMsg, WM_PAINT
    mov lParam, 3

    fSlv8 alor1 = 1.5
    fSlv8 alor2 = 2.2

    @if wParam eq 1
      @if lParam ne 3 || pMsg eq WM_COMMAND
        @if wParam gt 1 || wParam lt 4
          print "  ----------------------------------------",13,10
          print "  Ain't Mabdelouahab's runtime comparisons great",13,10
          print "  ----------------------------------------",13,10
        @endif
      @elseif alor1 fGT 1.0 && alor2 fNE 2.0
          print "  ----------------------------------------",13,10
          print "  Is working? Yes",13,10
          print "  ----------------------------------------",13,10
      @else
          print "  ----------------------------------------",13,10
          print "  Nothing ",13,10
          print "  ----------------------------------------",13,10
      @endif
    @endif
   

I was developing almost exactly the same :biggrin:, but discovery of Mab's macros save me to make most difficult part (comparison expansion)  :thumbsup:

Last modifications 2021 in files:
« Last Edit: December 04, 2021, 04:22:58 AM by HSE »
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2197
  • AMD 7-32 / i3 10-64
Re: if-elseif Mab's macros for floating comparisons
« Reply #1 on: December 03, 2021, 01:42:45 AM »
Hi all!!

Some extensions for unsigned comparisons and check floting point:
Code: [Select]
    run_time_comparisons MACRO
      % echo     **************************************
      % echo     variable run time comparison operators
      % echo     **************************************
      % echo     -------------
      % echo     equality test
      % echo     -------------
      % echo     eq equal
      % echo     ne not equal
      % echo   
      % echo     -----------------
      % echo     signed comparison
      % echo     -----------------
      % echo     gt signed greater than
      % echo     lt signed less than
      % echo     ge signed greater than or equal
      % echo     le signed less than or equal
      % echo   
      % echo     -------------------
      % echo     unsigned comparison
      % echo     -------------------
      % echo     ua unsigned above
      % echo     ub unsigned below
      % echo     ae unsigned above or equal
      % echo     be unsigned below or equal
      % echo   
      % echo     -------------------------
      % echo     floating point comparison
      % echo     -------------------------
      % echo     fEQ equal
      % echo     fNE not equal
      % echo   
      % echo     fGT greater than
      % echo     fLT less than
      % echo     fGE greater than or equal
      % echo     fLE signed less than or equal
      % echo   
      % echo     --------------------
      % echo     floating point check
      % echo     --------------------
      % echo     r4Is  check real4 is NotNaN/Valid
      % echo     r8Is  check real8 is NotNaN/Valid
      % echo     **************************************
    ENDM
  ; ************************************************

Some problem with registers. Work perfectly eax lt ebx (opcodes are same that MASM HLL eax < ebx), but fails eax ub ebx.

Regards, HSE.

Later: Because macros are not sofisticated the wrong operation is founded:  eaxubebx instead eaxubebx  :biggrin: very funny
« Last Edit: December 04, 2021, 04:23:37 AM by HSE »
Equations in Assembly: SmplMath

HSE

  • Member
  • *****
  • Posts: 2197
  • AMD 7-32 / i3 10-64
Re: if-elseif Mab's macros for floating comparisons
« Reply #2 on: December 04, 2021, 04:31:29 AM »
Hi all !!

Because letters to identify integer comparisons are so common, original macros can have a lot of problems.

I replaced spaces remotion with filling, in this case "___"(three underscores). Then no more conflicts.

Right now requiere single spaces, but everybody can improve that  :biggrin:

Files in first post.

Regards, HSE.
Equations in Assembly: SmplMath

Biterider

  • Member
  • ****
  • Posts: 984
  • ObjAsm Developer
    • ObjAsm
Re: if-elseif Mab's macros for floating comparisons
« Reply #3 on: December 04, 2021, 05:07:31 AM »
Thanks HSE!  :thumbsup:


Biterider

HSE

  • Member
  • *****
  • Posts: 2197
  • AMD 7-32 / i3 10-64
Re: if-elseif Mab's macros for floating comparisons
« Reply #4 on: December 05, 2021, 03:53:33 AM »
 :biggrin: Here a test in 64 bits using ML64.

Line 28 must be commented because qWord only tested SmplMath for 64 bits in JWASM, that was before invoke macro for ML64:
Code: (Math.inc) [Select]
ELSEIF @WordSize EQ 8
IFNDEF __JWASM__
; .err <The SmplMath System requires JWASM for x86-64 support>
fslv_glb_error = 1
ENDIF
includelib \masm32\macros\SmplMath\lib\x64\SmplMath.lib
ELSE
Equations in Assembly: SmplMath