Author Topic: How to output 128 bits to the screen?  (Read 17700 times)

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #30 on: July 20, 2017, 11:37:00 PM »
it should be trivial to extend it to print 128-bit floats (I think the code is already there).

Great, show us :t

jack

  • Member
  • **
  • Posts: 223
Re: How to output 128 bits to the screen?
« Reply #31 on: July 20, 2017, 11:54:59 PM »
I have minimal C experience otherwise I would take you up on the challenge, but you can convert a 128-bit float in exponential format to string using e113toasc, you just have to #define UNUSED 1

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #32 on: July 21, 2017, 01:19:33 AM »
I have minimal C experience

Me too ;)

Quote
otherwise I would take you up on the challenge, but you can convert a 128-bit float in exponential format to string using e113toasc, you just have to #define UNUSED 1

There are many competent C/C++ coders here, so soon we'll see a DLL or LIB :t

Mikl__

  • Member
  • *****
  • Posts: 1304
Re: How to output 128 bits to the screen?
« Reply #33 on: July 22, 2017, 10:03:41 AM »
Hi, jj2007, aw27, TWell, jack, FORTRAN!
Many thanks for the tips and helpness!

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #34 on: July 23, 2017, 08:42:02 PM »
I am working on a MasmBasic implementation. Here is cos(45):
Code: [Select]
QuadMath        7.071067811865475244008443621048490885e-01
Wolfram Alpha   7.071067811865475244008443621048490392e-01

Not bad, but it will require a GCC installation :(

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #35 on: July 23, 2017, 09:45:21 PM »
I am working on a MasmBasic implementation. Here is cos(45):
Code: [Select]
QuadMath        7.071067811865475244008443621048490885e-01
Wolfram Alpha   7.071067811865475244008443621048490392e-01

Not bad, but it will require a GCC installation :(

Are you working on a BigNum library or on a way to print a 128 bit float to the screen?  :icon_eek:

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #36 on: July 23, 2017, 10:01:43 PM »
The latter. Since GCC is a very popular compiler, and has the QuadMath library "out of the box", I am trying to get an assembler interface to that lib. Pretty useless, I know :badgrin:

Anyway, this works already:

        PrintLine "xmm0=", Tb$, Quad$(xmm0)
        PrintLine "MyReal16=", Tb$, Quad$(MyReal16)


But I must say that GCC QuadMath is not user-friendly. Badly documented, you need to read the header file to get info ::)

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #37 on: July 23, 2017, 10:10:19 PM »
The latter. Since GCC is a very popular compiler, and has the QuadMath library "out of the box", I am trying to get an assembler interface to that lib. Pretty useless, I know :badgrin:

Anyway, this works already:

        PrintLine "xmm0=", Tb$, Quad$(xmm0)
        PrintLine "MyReal16=", Tb$, Quad$(MyReal16)


But I must say that GCC QuadMath is not user-friendly. Badly documented, you need to read the header file to get info ::)

Just note that SSE/AVX does not support 128-bit floats/Real16 and Intel has no current plans to implement. So, printing a xmm/ymm/zmm register looking for the 128-bit float in there, just prints garbage. Of course you can work with a software only solution.

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #38 on: July 23, 2017, 10:44:27 PM »
Of course you can work with a software only solution.

Exactly. It's called "QuadMath", and it works already, see above.

I attach a proggie that reads a RAD string (e.g. 45*PI/180=0.785398163397448309615660845819875721049292349843776455243) and spits out the cosine. As mentioned before, it needs C:\TDM-GCC-32\bin\libquadmath-0.dll

Mikl__

  • Member
  • *****
  • Posts: 1304
Re: How to output 128 bits to the screen?
« Reply #39 on: July 23, 2017, 11:01:57 PM »
?

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #40 on: July 23, 2017, 11:13:02 PM »
Hi Mikl,

You were too fast - the first version had an exception handler, and instead of telling you that the DLL doesn't exist, it just threw an exception. Try the new attachment, and make sure you have GCC installed in the right location.

Interesting that you got non-printable characters, though. Which codepage? What do you get with chcp 65001?

aw27

  • Guest
Re: How to output 128 bits to the screen?
« Reply #41 on: July 23, 2017, 11:18:21 PM »
I don't have GCC installed now.   :(  :shock:

Mikl__

  • Member
  • *****
  • Posts: 1304
Re: How to output 128 bits to the screen?
« Reply #42 on: July 23, 2017, 11:19:30 PM »
codepage=866

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #43 on: July 23, 2017, 11:36:14 PM »
Try this one, the "Dll not found" warning was broken :icon_redface:

And yes, it won't work without C:\TDM-GCC-32\bin\libquadmath-0.dll 8)

jj2007

  • Member
  • *****
  • Posts: 13648
  • Assembly is fun ;-)
    • MasmBasic
Re: How to output 128 bits to the screen?
« Reply #44 on: July 24, 2017, 12:52:38 AM »
Stupid question: Where am I wrong?
Code: [Select]
include \masm32\include\masm32rt.inc
.data
My4 REAL4 -1.23456789012345678901234567890e0
My8 REAL8 -1.23456789012345678901234567890e0

.code
start:
  mov esi, offset My4
  mov eax, [esi]
  sar eax, 23
  and eax, 11111111b ; 8 bits expo
  sub eax, 127  ; bias
  print str$(eax), 9, "expo R4", 13, 10

  mov esi, offset My8
  mov eax, [esi]
  sar eax, 52-32
  and eax, 11111111111b ; 11 bits expo
  sub eax, 1023 ; bias
  print str$(eax), 9, "expo R8", 13, 10
  exit
end start

Should be 2x0, right?
Code: [Select]
0       expo R4
41      expo R8