News:

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

Main Menu

How to output 128 bits to the screen?

Started by Mikl__, July 19, 2017, 10:51:33 PM

Previous topic - Next topic

jj2007

Quote from: jack on July 20, 2017, 11:19:06 PMit should be trivial to extend it to print 128-bit floats (I think the code is already there).

Great, show us :t

jack

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

Quote from: jack on July 20, 2017, 11:54:59 PM
I have minimal C experience

Me too ;)

Quoteotherwise 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__

Hi, jj2007, aw27, TWell, jack, FORTRAN!
Many thanks for the tips and helpness!

jj2007

I am working on a MasmBasic implementation. Here is cos(45):
QuadMath        7.071067811865475244008443621048490885e-01
Wolfram Alpha   7.071067811865475244008443621048490392e-01


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

aw27

Quote from: jj2007 on July 23, 2017, 08:42:02 PM
I am working on a MasmBasic implementation. Here is cos(45):
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

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

Quote from: jj2007 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 ::)

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

Quote from: aw27 on July 23, 2017, 10:10:19 PMOf 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__


jj2007

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

I don't have GCC installed now.   :(  :shock:

Mikl__


jj2007

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

Stupid question: Where am I wrong?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?
0       expo R4
41      expo R8