Autor
| c compiler comparison
|
ARTRAG msx master Mensajes: 1802 | Publicado: Marzo 05 2007, 13:55   |
@manuel
Can you compile the latest vesrsion of the sieve file? the one that prints the à of ints?
|
|
manuel msx guru Mensajes: 3635 | Publicado: Marzo 05 2007, 16:51   |
ARTRAG, as I said, the one from MicroTech didn't compile in z88dk, some error on this line:
size_t start0, stop0;
|
|
MicroTech msx lover Mensajes: 123 | Publicado: Marzo 06 2007, 07:58   |
Quote:
| ARTRAG, as I said, the one from MicroTech didn't compile in z88dk, some error on this line:
size_t start0, stop0;
|
@ Manuel: try to replace "size_t" with "unsigned int"...  |
|
ARTRAG msx master Mensajes: 1802 | Publicado: Marzo 06 2007, 15:15   |
Manuel, I mean this one (posted by me)
/* - SIEVE.C -
The benchmark C source function.
$Name: V3_34K V3_34J V3_34I V3_34H V3_34G $
*/
#include "stdio.h"
/* Eratosthenes Sieve Prime Number Program in C from Byte Jan 1983. */
#define TRUE 1
#define FALSE 0
#define SIZE 8190
char flags[SIZE+1];
void main()
{
register int i,k;
int prime,count,iter;
*((int*) 0xFC9E) = 0; /* reset internal timer jiffy */
printf("10 iterations\n");
for (iter = 1; iter <= 10; iter++) /* do program 10 times */
{
count = 0; /* initialize prime counter */
for (i = 0; i <= SIZE; i++) /* set all flags true */
flags[i] = TRUE;
for (i = 0; i <= SIZE; i++)
{
if (flags[i]) /* found a prime */
{
prime = i + i + 3; /* twice index + 3 */
for (k = i + prime; k <= SIZE; k += prime)
flags[k] = FALSE; /* kill all multiples */
count++; /* primes found */
}
}
}
printf("%d primes.\n",count); /*primes found in 10th pass */
printf("%d ints.\n",*((int*) 0xFC9E)); /*ints passed in 10th pass */
}
|
|
manuel msx guru Mensajes: 3635 | Publicado: Marzo 07 2007, 19:29   |
Z88dk:
3164 ints without any flags
3167 ints with -O1 
3165 ints with -O2  (
3354 ints with -O3  ((
Hi-Tech C CP/M:
1783 ints without any flags
1697 ints with optimization.
SDCC:
881 ints!
(but printing isn't entirely correct: there seem to be tabs before the printed lines...)
For me, the clear winner of for me freely available and usable compilers *for this benchmark*: SDCC!
Note: all done on 50Hz... (Interesting: times halve when trying new compilers...?) |
|
jltursan msx professional Mensajes: 887 | Publicado: Marzo 07 2007, 22:00   |
Really curious, I was expecting better scores from z88dk...after all seems a compiler specifically oriented to Zilog cpus. Now seems it's time to work on new MSX SDCC add-ons!.
|
|
ARTRAG msx master Mensajes: 1802 | Publicado: Marzo 07 2007, 23:30   |
Manuel, I did all the tests at 60Hz. About SDCC I had this
Quote:
|
Posted: March 02 2007, 00:02
SDCC (Small Devices C Compiler)
It takes 1050 ints at 60Hz!!
I have modified the ASM code posted here in order to assemble it with Hitech C cross compiler libraries
|
that fits very well with you result as
881*6*5 = 1057 ints @60Hz
Actually at the moment the best code is from from IAR
Quote:
|
This is sieve from IAR 4.06A
It takes only 943 ints @60Hz !!!!
I converted the ASM in order to assemble and link with Hitech C as IAR has no support for CPM and I do know (jet) how to do MSX roms
|
that at 50Hz would be 785 ints |
|
dvik msx master Mensajes: 1376 | Publicado: Marzo 08 2007, 01:35   |
IAR is Swedish so it has to be best  |
|
PingPong msx master Mensajes: 1069 | Publicado: Marzo 08 2007, 08:04   |
Quote:
| IAR is Swedish so it has to be best 
|
eh, eh...  |
|
ARTRAG msx master Mensajes: 1802 | Publicado: Marzo 08 2007, 10:54   |
I need to test also ADC-Z80 C Compiler
I'll post what I can asap
|
|
manuel msx guru Mensajes: 3635 | Publicado: Marzo 08 2007, 11:02   |
Yes, but IAR is not free as in beer nor as in speech nor available for free operating systems, which renders it unusable for me.
|
|
zeilemaker54 msx lover Mensajes: 97 | Publicado: Marzo 08 2007, 13:11   |
A quick question:
Why are you including the printf statements in your measuring ? There can be huge differences between printf implementations, so it seems fair to leave the printf's out of the measuring code.
So:
int vdpints;
printf("10 iterations\n"  ;
*((int*) 0xFC9E) = 0; /* reset internal timer jiffy */
....
....
vdpints = *((int*) 0xFC9E)
printf("%d primes.\n",count); /*primes found in 10th pass */
printf("%d ints.\n",vdpints); /*ints passed in 10th pass */
|
|
ARTRAG msx master Mensajes: 1802 | Publicado: Marzo 08 2007, 15:27   |
Actually printf is also interesting to be measured.
In any case if you look at the source the printf included in the timings are:
printf("10 iterations\n");
and
printf("%d primes.\n",count); /*primes found in 10th pass */
Not the one you spotted:
printf("%d ints.\n",*((int*) 0xFC9E)); /*ints passed in 10th pass */
that is translated in
ld hl,(-866)
push hl
ld hl,u39
push hl
call _printf
BTW note that the codes I execuded have been modified in order to be linked by the Hitech C, so
all my experiments run the same printf (by Hitech). This makes all comparisons uniform.
|
|
manuel msx guru Mensajes: 3635 | Publicado: Marzo 09 2007, 11:29   |
The calculations take quite long and the prints are not in the loops, so there is not a big difference.
|
|
ARTRAG msx master Mensajes: 1802 | Publicado: Marzo 09 2007, 18:39   |
I discovered that IAR can allocate statically in RAM (in a common area? to be explored...) the auto and register variables.
This avoids the use to IX as pointer to the heap and IX becomes free to be used as extra register...
This is what you get with this option...
NAME sieve(16)
RSEG CODE(0)
RSEG CSTR(0)
RSEG TEMP(0)
RSEG UDATA0(0)
PUBLIC flags
PUBLIC main
EXTERN printf
EXTERN ?CLZ80L_4_06_L00
RSEG CODE
; 1. /* - SIEVE.C -
; 2. The benchmark C source function.
; 3. $Name: V3_34K V3_34J V3_34I V3_34H V3_34G $
; 4. */
; 5.
; 6. #include "stdio.h"
; 7.
; 8. /* Eratosthenes Sieve Prime Number Program in C from Byte Jan 1983. */
; 9.
; 10. #define TRUE 1
; 11. #define FALSE 0
; 12. #define SIZE 8190
; 13.
; 14. char flags[SIZE+1];
; 15.
; 16. void main()
; 17. {
main:
PUSH BC
; 18. register int i,k;
; 19. int prime,count,iter;
; 20.
; 21. *((int*) 0xFC9E) = 0; /* reset internal timer jiffy */
LD HL,0
LD (64670),HL
; 22.
; 23. printf("10 iterations\n");
LD HL,?0011
PUSH HL
CALL printf
POP AF
; 24. for (iter = 1; iter <= 10; iter++) /* do program 10 times */
LD HL,1
?0036:
LD (?0010+8),HL
?0013:
LD C,L
LD B,H
LD HL,10
OR 128
SBC HL,BC
JP PO,?0032
XOR H
?0032:
JP M,?0012
?0014:
; 25. {
; 26. count = 0; /* initialize prime counter */
LD HL,0
LD (?0010+6),HL
; 27. for (i = 0; i <= SIZE; i++) /* set all flags true */
LD (?0010),HL
?0017:
LD BC,(?0010)
LD HL,8190
OR 128
SBC HL,BC
JP PO,?0033
XOR H
?0033:
JP M,?0016
?0018:
; 28. flags[i] = TRUE;
LD HL,flags
ADD HL,BC
LD (HL),1
INC BC
LD (?0010),BC
JR ?0017
?0016:
; 29. for (i = 0; i <= SIZE; i++)
LD HL,0
?0037:
LD (?0010),HL
?0021:
LD C,L
LD B,H
LD HL,8190
OR 128
SBC HL,BC
JP PO,?0034
XOR H
?0034:
JP M,?0020
?0022:
; 30. {
; 31. if (flags[i]) /* found a prime */
LD HL,flags
ADD HL,BC
LD A,(HL)
OR A
JR Z,?0025
?0024:
; 32. {
; 33. prime = i + i + 3; /* twice index + 3 */
LD L,C
LD H,B
INC HL
ADD HL,HL
INC HL
LD (?0010+4),HL
; 34. for (k = i + prime; k <= SIZE; k += prime)
LD BC,(?0010)
?0038:
ADD HL,BC
LD (?0010+2),HL
?0027:
LD C,L
LD B,H
LD HL,8190
OR 128
SBC HL,BC
JP PO,?0035
XOR H
?0035:
JP M,?0026
?0028:
; 35. flags[k] = FALSE; /* kill all multiples */
LD HL,flags
ADD HL,BC
LD (HL),0
LD HL,(?0010+4)
JR ?0038
?0026:
; 36. count++; /* primes found */
LD HL,(?0010+6)
INC HL
LD (?0010+6),HL
?0025:
LD HL,(?0010)
INC HL
JR ?0037
; 37. }
; 38. }
; 39. }
?0020:
LD HL,(?0010+8)
INC HL
JP ?0036
?0012:
; 40. printf("%d primes.\n",count); /*primes found in 10th pass */
LD HL,(?0010+6)
PUSH HL
LD HL,?0030
PUSH HL
CALL printf
POP AF
POP AF
; 41. printf("%d ints.\n",*((int*) 0xFC9E)); /*ints passed in 10th pass */
LD HL,64670
LD C,(HL)
INC HL
LD B,(HL)
PUSH BC
LD HL,?0031
PUSH HL
CALL printf
POP AF
POP AF
; 42. }
POP BC
RET
RSEG CSTR
?0011:
DEFB '10 iterations'
DEFB 10,0
?0030:
DEFB '%d primes.'
DEFB 10,0
?0031:
DEFB '%d ints.'
DEFB 10,0
RSEG TEMP
?0010:
DEFS 10
RSEG UDATA0
flags:
DEFS 8191
END
|
|
|
|
|