Sujet : Re: Baby X is bor nagain
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 26. Jun 2024, 01:23:47
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5fji3$1p5ds$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
User-Agent : Mozilla Thunderbird
On 25/06/2024 21:28, DFS wrote:
On 6/25/2024 3:39 PM, bart wrote:
On 25/06/2024 17:52, DFS wrote:
On 6/25/2024 7:18 AM, bart wrote:
On 25/06/2024 09:19, David Brown wrote:
>
At no point in all this does anyone care in the slightest about the speed of your little toys or of the cute little tcc. tcc might be ideal for the half-dozen people in the world who think C scripts are a good idea, and it had its place in a time when "live Linux" systems were booted from floppies, but that's about it.
>
Yet, projects like mine, and like tcc, show what is possible: just how fast should it take to turn lower level code into machine code.
>
>
Can you use tcc to generate assembly from a .c source file?
>
similar to:
>
$ gcc -S sourcefile.c
>
>
I don't think that's an option with tcc.
It's not listed in the tcc help anyway.
gcc works by generating intermediate assembly anyway, and the -S option exposes it.
>
Generally it depends on compiler. Mine has it for example.
Cool.
If you don't mind, what assembly code does your compiler generate for this C code:
I've shown the main code below. I normally use alternate registers names, I've changed it to use Intel; it looks about right.
This is for Win64 ABI running on x64.
Although I'm not sure how helpful this will be. Most of the runtime in your program will be spent inside library functions.
----------------------------------------
`main::
`main.argc = -8
`main.argv = -16
`R.main.N = edi
`R.main.nums = rbx
`R.main.datafile = rsi
`R.main.i.3 = r12d
`main.$env = -24
`main.$info = -152
push rdi
push rbx
push rsi
push r12
push rbp
mov rbp, rsp
sub rsp, 192
;... (some code which sets up argc/argv via __getmainargs() ...
mov edi, 0
mov rcx, 8
call `malloc*
mov rbx, rax
mov rax, [rbp+`main.argv]
lea rax, [rax+8]
mov rax, [rax]
mov rcx, rax
mov rdx, L6
call `fopen*
mov rsi, rax
jmp L7
L9:
lea eax, [rdi+1]
movsx rax, eax
shl rax, 2
mov rcx, rbx
mov rdx, rax
call `realloc*
mov rbx, rax
L7:
mov eax, edi
inc edi
movsx rax, eax
lea r10, [rbx+rax*4]
mov rcx, rsi
mov rdx, L10
mov r8, r10
call `fscanf*
cmp eax, 1
jz L9
L8:
mov rcx, rsi
call `fclose*
dec edi
mov r12d, 0
jmp L13
L14:
mov eax, r12d
movsx rax, eax
lea r10, [rbx+rax*4]
mov r10d, [r10]
lea eax, [r12+1]
mov rcx, L15
mov edx, eax
mov r8d, r10d
call `printf*
L11:
inc r12d
L13:
cmp r12d, edi
jl L14
L12:
mov rcx, rbx
call `free*
mov rcx, L16
call `printf*
;------------------------
xor ecx, ecx
call `exit*
add rsp, 192
pop rbp
pop r12
pop rsi
pop rbx
pop rdi
ret