flat assembler
Message board for the users of flat assembler.
Index
> Windows > Type conversions |
Author |
|
madpsychocell 02 Sep 2023, 14:55
How to convert types:
Int64ToFloat64 Int64ToString Float64ToInt64 Float64ToString StringToInt64 StringToFloat64 |
|||
02 Sep 2023, 14:55 |
|
madpsychocell 02 Sep 2023, 18:23
I found some conversions in internet but not all. It is faster then sprintf.
|
|||
02 Sep 2023, 18:23 |
|
bitRAKE 02 Sep 2023, 18:38
Some of these can be performed by a single instruction:
Int64ToFloat64 Code: cvtsi2sd xmm0, rax ; rax contains the int64, xmm0 will contain the float64 Code: cvttsd2si rax, xmm0 ; xmm0 contains the float64, rax will contain the int64 Some have legacy window functions (confusing naming without floating-point support): StringToInt64 - SHLWAPI.wnsprintfA Int64ToString - USER32.wsprintfA All the operations can be performed by UCRT, but there is an abstraction layer. MSVCRT doesn't have the abstraction layer - containing atof(), atol(), printf(), sprintf(), etc. functions. There are conversion functions on this board as well. FPU |
|||
02 Sep 2023, 18:38 |
|
madpsychocell 02 Sep 2023, 21:04
I have to find a conversions: string to double, double to string and int to string in x64...
|
|||
02 Sep 2023, 21:04 |
|
bitRAKE 03 Sep 2023, 00:40
Are you looking for the cutting edge AVX512, super optimized version or something? Or are you looking to learn about the IEEE floating point format. Int to string is trivial if coded for size:
Code: virtual CONST.32 ; "base32hex", RFC 2938, Sec.3-1 digit_table db '0123456789ABCDEFGHIJKLMNOPQRSTUV' end virtual align 16, codepad # UINT64__Baseform: ; RAX: number to convert ; RCX: number base to use [2,32] radix ; RDI: string buffer of length [65,14] bytes push 0 ; sentinel .A: xor edx,edx div rcx push qword [digit_table+rdx] ; #32# test rax,rax jnz .A .B: pop rax stosb test al,al jnz .B retn |
|||
03 Sep 2023, 00:40 |
|
bitRAKE 03 Sep 2023, 02:31
In windows there are many ways to convert double/float to string.
*oleaut32.VarBstrFromR8() supports the full range of the IEEE format - generating inf, nan and processing subnormals. (Not to mention the locale presentation of numbers - for those people that like to see 123,456 instead of 123.456.) *Click the link for the dozens of conversion functions present in this library!
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
03 Sep 2023, 02:31 |
|
Roman 06 Sep 2023, 10:58
VarBstrFromR8 Unicode string.
And BSTR it is a COM object. Wow ! I never used VarBstrFromR8. Sound like as Bastard from reality number 8 |
|||
06 Sep 2023, 10:58 |
|
bitRAKE 07 Sep 2023, 09:46
The OLE stuff has it's place, but the overhead of that library is a little steep for one function. The function names can be misleading because they don't all produce VARIANT types - more like VARIANT support functions.
Here is another one - not meant to be the fastest - just get the job done: Code: align 16, codepad # atoi64: xor ecx, ecx cmp byte [rdi], '-' setz cl add rdi, rcx bts rcx, 63 xor eax, eax push rdi .read_digits: movzx edx, byte [rdi] sub edx, '0' ; jc .done cmp edx, 10 jnc .done imul rax, rax, 10 jo .overflow add rax, rdx add rdi, 1 cmp rax, rcx jc .read_digits .overflow: pop rdi push rdi .done: jecxz .positive ; note ECX! neg rax .positive: pop rcx sub ecx, edi retn ; ZF=1, RCX=0 on error ; RDI updated ; RAX signed-qword atou64() would just be a reduction of this function.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||||||||||
07 Sep 2023, 09:46 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.