News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to output 128 bits to the screen?

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

Previous topic - Next topic

Mikl__

Hi, All!
If I need to output 64-bits float to the screen, I do so; CONSOLE #
include win64a.inc
include msvcrt.inc
includelib msvcrt.lib
.data
pi  dq 3.14159265358979323846264338327
textformat db "hello, %.16llf!",0
.code
WinMain proc
sub rsp,28h
lea rcx,textformat
mov rdx,pi
call printf
xor rax,rax
add rsp,28h
ret
WinMain endp
end
What should I do to output 128-bits float to the screen? Thanks...


Mikl__

Ciao, jj2007! Come stai?
I do not need an exact calculation of the Pi number, but I need an example of using format string for prints and  xmm-registers...

jj2007

Display with "normal" code ends with Real10 precision:
include \masm32\MasmBasic\MasmBasic.inc
  Init
  fldpi
  Inkey Str$("PI=%Jf", ST(0)v) ; PI=3.141592653589793238
EndOfCode


Everything beyond needs special libraries, like Dave's Ling Long Kai Fang Bignum library. Rumours say Drizz also has one.

If you want to see C/C++/G++ coders fighting with 128-bit windmills, check
how to print __uint128_t number using gcc?
or
How to print __int128 in g++?

Of course, you can always use hex representation:My128Bits xmmword 1111111111abcdef2222222222abcdefh
  movups xmm0, My128Bits
  deb 4, "Test", x:xmm0


Output: Test    x:xmm0          11111111 11ABCDEF 22222222 22ABCDEF

nidud


aw27

Another alternative:


; x64
;uasm64 -win64 -Zp8 -c p128.asm

.xmm
option casemap:none
option frame:auto

includelib \masm32\lib64\msvcrt.lib
printf proto :ptr, :vararg

_DOUBLESTOXMM MACRO par1, par2
Local xmmValue
  .const
  align 16
  xmmValue REAL8 par1, par2
  .code
  exitm <xmmValue>
ENDM

.data
format db "Results: %.16llf, %.16llf",13,10,0

.code

main proc
       ;sub rsp, 8 by uasm
sub rsp, 20h
movaps xmm0, XMMWORD ptr _DOUBLESTOXMM(3.14159265358979323846264338327, -6.28318530717958647692528676654)

movq r8, xmm0 ; Note: ML64 does not accept movq, it is a know bug. But it accepts movd and converts it to movq. Weird
shufpd xmm0, xmm0, 1
movq rdx, xmm0
mov rcx, offset format
call printf

add rsp, 20h
ret
main endp

end



Results: -6.2831853071795862, 3.1415926535897931

jj2007


aw27


jj2007

Yes, I printed a float: PI=3.141592653589793238

But that is "only" an 80 bit float. OP wants 128 bits, and that is not possible with "normal" code. You need a bignum library.

RuiLoureiro

Quote from: jj2007 on July 20, 2017, 08:07:47 AM
Yes, I printed a float: PI=3.141592653589793238

But that is "only" an 80 bit float. OP wants 128 bits, and that is not possible with "normal" code. You need a bignum library.
Yes it seems Mikl__ wants a 128 bits converter. But if there is one BIGNUM library then it
has the converter. Where to see it Jochen (but i dont want it) ? And what is a bignum library, what it does ?
Does it real128 * real128 = real128 ? What is the format ? (real128 means any real with 128 bits in the same way real80 is the same as REAL10- 10 bytes)
:t

aw27

Quote from: jj2007 on July 20, 2017, 08:07:47 AM
Yes, I printed a float: PI=3.141592653589793238

But that is "only" an 80 bit float. OP wants 128 bits, and that is not possible with "normal" code. You need a bignum library.

Of course, it is not possible without a bignum library.
And he asked for "an example of using format string for prints and  xmm-register".
So what comes closer to what he wants, in the realm of possibilities, is what I did.
I also did it in Assembly Language, which this forum is all about.

jj2007

Quote from: aw27 on July 20, 2017, 03:05:40 PM
I also did it in Assembly Language, which this forum is all about.

call printf

:t

aw27

Quote from: jj2007 on July 20, 2017, 04:39:32 PM
call printf
:t
You do the same, or equivalent, hidden in the middle of obscure code supported by undocumented libs you developed (MasmBasic, JBasic.*).
That way, I can only expect newbies to learn ASM when pigs can fly.  :badgrin:

jj2007

We are doing almost the same. The difference is that I am not pretending to solve the problem, I just demonstrate that it is NOT possible, and I do it using a library that is written 100% in assembly, developed here in this forum by many members, without even a trace of C code. And I really don't understand why this turns into a pissing contest, José. If you want to be constructive, start a bignum library thread in the Laboratory. That could be interesting indeed.

aw27

Quote from: jj2007 on July 20, 2017, 05:10:13 PM
If you want to be constructive, start a bignum library thread in the Laboratory. That could be interesting indeed.
In my opinion there are already enough BigNum libraries out there. Probably the best one for Windows, is the MPIR, which is written partially in YASM. I used it to do a freeware I published called Googol+