News:

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

Main Menu

Intel SSE and ARM NEON hexadecimal string

Started by ttribelli, November 17, 2023, 03:24:42 AM

Previous topic - Next topic

Vortex

Hi ttribelli,

Compared to a human, a machine is much more robust and productive in some cases. That was the point of my example.

ttribelli

Quote from: Vortex on November 18, 2023, 06:39:30 AMCompared to a human, a machine is much more robust and productive in some cases. That was the point of my example.

I agree, until the profiler tells me about serious hotspots. Modern C/C++ compilers have inline assembly or SIMD intrinsic support for very good reasons.

jj2007

Quote from: Vortex on November 18, 2023, 06:25:09 AMimagine that I am tasked to write a very very big application in assembly. Trying to optimize the whole application would be a very tiring task too. On the other side,you could write the same application with an optimizing C\C++ compiler. The optimizing engine does not get tired like me or another human. From a practical point of view, the C\C++ compiler can be the winner.

The compiler can be the winner, but it depends on a number of factors:
- I am a lousy C programmer; programming a simple string like Let my$="Today is the "+fDate$()+", and it's "+fTime$() would cost me ages in C but a few seconds in Assembly;
- we are Assembly programmers: we know exactly how to design an application for speed;
- we know how to recognise an innermost loop, and how to tickle out of the cpu the minimum cycle count inside that loop;
- we are Windows API experts: our code will not be portable, but we can make the best use of Windows without bloated libraries like Electron or QT.

In short: it depends. Maybe the average C programmer can beat the average Assembly programmer for a medium-sized project when looking at the function Overall performance = f(development time, application runtime, user experience). However, 1. we are not average Assembly programmers here in this forum and 2. our overall performance function will give zero weight to the development time factor simply because we are hobby programmers who enjoy coding: it's so much fun to beat a C function :biggrin:

TimoVJL

Quote from: jj2007 on November 18, 2023, 10:17:25 AM- I am a lousy C programmer; programming a simple string like Let my$="Today is the "+fDate$()+", and it's "+fTime$() would cost me ages in C but a few seconds in Assembly;",
I am a bit beginner in assembly language, so what assembler you use with that example ? Example just looks like an old basic language or VB script.
I am a bit rusty with C, but:
#include <stdio.h>
#include <time.h>

int __cdecl main(void)
{
    time_t tm = time(NULL);
    printf("Today is the %s\n", ctime(&tm));
    return 0;
}
outputs
Today is the Sat Nov 18 06:48:56 2023and exe size can be 3 072 bytes / 3 584 bytes (x64), if OS msvcrt.dll is used.
May the source be with you

Vortex

#19
Hi Timo,

The code above is MasmBasic :

https://masm32.com/board/index.php?board=57.0

MasmBasic allows string concatenation like the traditional Basic dialects.

jj2007

Quote from: TimoVJL on November 18, 2023, 03:57:04 PMI am a bit beginner in assembly language, so what assembler you use with that example ?

MASM or UAsm, sometimes also AsmC or JWasm.

Btw your example is not equivalent: you are just printing stuff to the console, while I am assigning it to a string for further use.

@Erol: thanks, but Timo is just pulling my leg :biggrin:

adeyblue

Quote from: jj2007 on November 18, 2023, 09:46:01 PMBtw your example is not equivalent: you are just printing stuff to the console, while I am assigning it to a string for further use.
strftime
#include <stdio.h>
#include <time.h>

int __cdecl main(void)
{
    time_t now = time(0);
    char buff[200];
    strftime(buff, 200, "Today is %#x and it's %X", localtime(&now));
    puts(buff);
}

daydreamer

Jochen,well some assembler programmers have spent much time programming SIMD
about code productivity,with many years asm programming = we can whip up a program faster than expected what HLL programmer thinks asm is slow development compared to C
,faster than a newbie asm programmer
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Yes indeed, Magnus :thumbsup:

It's all about "socialisation". Adeyblue whips up his strftime example in 2 minutes because he is a professional, and as such he has spent most of his career coding in C or C++. Same for Timo.

We are mostly hobby coders here, but we are fluent in Assembly, so we can do the same in our domain. Besides, you and me and many others here have also gone well beyond what a C/C++ guys can/will do in terms of SIMD programming.

P.S., I just hacked together a little challenge: How many files in \Masm32\Examples use ComCtr32.inc?

ttribelli

[quote author=Vortex link=msg=125188 date=1700164017]
Hi ttribelli,

Thanks for the code. I could not manage to assemble this module :

D:\FreeBASIC\bin\win64>as -o hexstr-x64.o hexstr-x64.s
[/quote]

I apologize for the delay but the code is building and running properly under Debian now.

Vortex

Hi ttribelli,

No worries. Do you have a new version of the source code for members operating on Windows? Thanks.

ttribelli

Quote from: Vortex on January 04, 2024, 04:46:09 AMNo worries. Do you have a new version of the source code for members operating on Windows? Thanks.

The problem was specific to the Mac/Linux version (.s), and only manifested on Linux. The Windows version (.asm) always worked.

The Mac/Linux version (.s) cannot be compiled on Windows using a GNU toolchain. The C ABI (register usage) is different between Windows and Mac/Linux.

The updated code has been tested on Debian and macOS.