| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
June 10, 2010 unoptimised assembly code when compiling one code? | ||||
|---|---|---|---|---|
| ||||
Hello,
When I compile this C code:(in a 16 bits system, so sizeof(int) = 2)
long i;
....
TValue *rb = (cast(int, ((i)>>23) & 0x1F));
float nb = rb->value.n;
The asm code (obj2asm) is:
mov DI,-070h[BP]
mov DX,-072h[BP]
mov AX,-074h[BP]
mov CL,017h
L1251: shr DX,1
rcr AX,1
loop L1251
and AH,1
imul BX,AX,6
add BX,-07Ah[BP]
mov DX,2[BX]
mov AX,[BX]
This code is often read in my programm, and I know the loop L1251 isn't very
optimised.
I think this should be faster:
instead of :
mov CL,017h
L1251: shr DX,1
rcr AX,1
loop L1251
having:
mov AX,DX
shr AX, 7
Could you help me, please, to improve my C code to obtain a better assembly code when compiling this code(like the faster assembly code I wrote)
Thanks!
veb
| ||||
June 11, 2010 Re: unoptimised assembly code when compiling one code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to veb | veb wrote:
> Could you help me, please, to improve my C code to obtain a better assembly
> code when compiling this code(like the faster assembly code I wrote)
You can try using the inline assembler.
| |||
June 11, 2010 Re: unoptimised assembly code when compiling one code? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Hello,
I changed the code to:
struct f16
{
unsigned int word1;
unsigned int word2;
};
TValue *rb = cast(int, ((((struct f16 *)&i)-> word2)>>(23-16) & 0x1F)));
float nb = rb->value.n;
My new code is globally two time more faster, because I have exactly what I wanted to have in the asm code.
I post for those who would have te same problem on a 16 bits system.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply