Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » SDCC
  • » [Sdcc-user] Z80 --std-c99 and _Bool results in larger code size and slow speed [RSS Feed]

#1 Dec. 6, 2010 19:55:30

Lin R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] Z80 --std-c99 and _Bool results in larger code size and slow speed


Seems nobody cares about --std-c99 and _Bool speed before, so I made a test
my self, using the following function:

BOOLEAN TestBoolean(BOOLEAN b1)
{
USHORT s;
BOOLEAN b2;
BOOLEAN b3;

b3 = IsHighSpeed();
for (s = 0; s < 30000; s ++)
{
b2 = b1 ? b3 : FALSE;
}
return b2;
}

When BOOLEAN as unsigned char, the running time of this function on my Z80
is 137ms, and code generated is less by 4 bytes.
When BOOLEAN as _Bool, using bit related instructions, this function need
167ms to run.

Woodyhttp://palmmicro.com/woody/----- Original Message -----
From: "Lin Rongrong" <wo***@*almmicro.com>
To: <sdcc-u***@*ists.sourceforge.net>; <supp***@*almmicro.com>
Sent: Monday, December 06, 2010 8:30 AM
Subject: Z80 --std-c99 and _Bool


>I have noticed that Philipp used _Bool in his own project, so I tried it
>with my own. To my surprise, after I added --std-c99 option, change BOOLEAN
>from "unsigned char" to "_Bool", I found code size generally get larger as
>below:
>
> code0 data code1 code2 code3 code4 code5 code6 code7 code
> 1D5B 19C4 456D 4F9C 4742 50AD 53F1 4354 5571 1B64 // gp2266 sip
> 0.49.022, without --std-c99, or BOOLEAN as "unsigned char" with --std-c99,
> they generated the same result
> 1D76 19C4 4610 4FD4 47A7 50B9 542D 4354 55A6 1B67 // gp2266 sip
> 0.49.023, with --std-c99 and BOOLEAN as "_Bool"
>
> I am willing to get faster speed with more code size, should I
> keep --std-c99 option and use BOOLEAN as _Bool?
>
> Woody
>
>http://palmmicro.com/woody/>



Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

#2 Dec. 6, 2010 21:57:17

Philipp K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] Z80 --std-c99 and _Bool results in larger code size and slow speed


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 06.12.2010 20:53, schrieb Lin Rongrong:
> Seems nobody cares about --std-c99 and _Bool speed before,

Well, I do, and _Bool does get better. Naturally I use my own code for
test cases, so if your coding style is different from mine, it's likely,
that there's untapped potential for optimization when compiling your code.
That's true even for things other than _Bool.

> Aso I made a test
> my self, using the following function:
>
> BOOLEAN TestBoolean(BOOLEAN b1)
> {
> USHORT s;
> BOOLEAN b2;
> BOOLEAN b3;
>
> b3 = IsHighSpeed();
> for (s = 0; s < 30000; s ++)
> {
> b2 = b1 ? b3 : FALSE;
> }
> return b2;
> }
>
> When BOOLEAN as unsigned char, the running time of this function on my Z80
> is 137ms, and code generated is less by 4 bytes.
> When BOOLEAN as _Bool, using bit related instructions, this function need
> 167ms to run.
>
> Woody

Well, _Bool is still much younger, so not all potential for optimization
has been used yet. On the other hand, unsigned char has been around for
a very long time.
The ternary operator ?: was not that good for _Bool, resulting in an
unecessary cast. I just fixed it (rev #6078). From now on your example
TestBoolean() should be faster when using _Bool compared to unsigned char.

Philipp
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/iEYEARECAAYFAkz9U04ACgkQbtUV+xsoLpqtuACgoYlylnNUIDShTcKuWa7eO1Ei
5FUAoNwdd8AlPVPqvfgAT3tKdc9HhOn1
=JPer
-----END PGP SIGNATURE-----


Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

#3 Dec. 7, 2010 20:54:34

Philipp K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[Sdcc-user] Z80 --std-c99 and _Bool results in larger code size and slow speed


Am 07.12.2010 16:16, schrieb Lin Rongrong:
> Just tested rev #6078, with TestBoolean function, the compiled size are the
> same now, and "_Bool" is 4ms faster than "unsigned char".

On an original Z80 _Bool should be exactly three clock cycles faster per
loop iteration in your example. In terms of speed this is the main
advantage of _Bool over unsigned char: saving three clock cycles each
time we use it as a condition, be it in the ternary operator, an if/else
or some other control mechanism.

> Really a fast fix.
> But I am still uncomfortable with "_Bool", as my overall code size is still
> a little larger with "_Bool".

Well there probably are still some places where sdcc generates
unnecessary casts for _Bool, this will improve over time (and the
improvmeent will be faster when users report the issue on this list (as
you did) or as a feature request (which has the advantage of not being
forgotten as easily)).

Philipp


Sdcc-user mailing list
Sdcc-user@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/sdcc-user

Offline

  • Root
  • » SDCC
  • » [Sdcc-user] Z80 --std-c99 and _Bool results in larger code size and slow speed [RSS Feed]

Board footer

Moderator control

Enjoy the 23rd of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support