; TASKING TriCore C compiler v1.5r1 Build 322 SN 00090364
; options: -e -A1 -g -O0 -Id:\ctri\include -s -N8 -zTC112_COR1 -zTC112_COR4
;          -zTC112_COR10 -zTC112_COR13 -zTC112_COR14 -zTC112_COR16 -zTC112_COR17
	.name	"sieve"
	.symb	TOOL, "TASKING TriCore C compiler v1.5", 1
	.symb	TYPE, 256, "bit", 'g', 0, 1
	.symb	FILE, "sieve.c"
; file "sieve.c":
;    1 |/************************************************************************
;    2 | *
;    3 | *      FILENAME:       sieve.c
;    4 | *
;    5 | *      DESCRIPTION:    Eratosthenes Sieve Prime Number
;    6 | *                      Program in C
;    7 | *                      Byte, januari 1983
;    8 | *
;    9 | *      Copyright 1997-2002 Altium BV
;   10 | *
;   11 | ************************************************************************/
;   12 |
;   13 |/*
;   14 | * Compile with -DPRINT for result printing.
;   15 | *  
;   16 | * Compile with -DMEASURE_TIME for time measurement.
;   17 | */
;   18 |
;   19 |#include <stdio.h>
	.symb	FILE, "d:\\ctri\\include\\stdio.h"
	.symb	FILE, "d:\\ctri\\include\\stdarg.h"
	.symb	ENDF
	.symb	TYPE, 258, 'P', #2
	.symb	TYPE, 259, "_iobuf", 'S', 24,\
		 "_ptr", #258, 0,\
		 "_base", #258, 4,\
		 "_cnt", #16, 8,\
		 "_bufsiz", #16, 12,\
		 "_flag", #5, 16,\
		 "_file", #2, 18,\
		 "_wcnt", #16, 20
	.symb	TYPE, 260, "FILE", 'T', #259
	.symb	TYPE, 261, "va_list", 'T', #258
	.symb	TYPE, 262, "size_t", 'T', #18
	.symb	TYPE, 263, "fpos_t", 'T', #7
	.symb	TYPE, 264, "off_t", 'T', #6
	.symb	ENDF
;   20 |#include "main.h"
	.symb	FILE, "main.h"
	.symb	TYPE, 265, "uword", 'T', #18
	.symb	FILE, "TC1775BRegs.h"
	.symb	ENDF
	.symb	FILE, "ASC0.H"
	.symb	TYPE, 266, "ushort", 'T', #5
	.symb	ENDF
	.symb	ENDF
;   21 |
;   22 |
;   23 |#define PRINT
;   24 |#define MEASURE_TIME
;   25 |
;   26 |
;   27 |
;   28 |#ifdef MEASURE_TIME
;   29 |#include <time.h>
	.symb	FILE, "d:\\ctri\\include\\time.h"
	.symb	FILE, "d:\\ctri\\include\\stddef.h"
	.symb	ENDF
	.symb	TYPE, 267, "time_t", 'T', #7
	.symb	TYPE, 268, "clock_t", 'T', #7
	.symb	ENDF
;   30 |unsigned        Begin_Time,End_Time;
;   31 |#endif
;   32 |
;   33 |#define true    1
;   34 |#define false   0
;   35 |#define size    8190
;   36 |
;   37 |char flags[size + 1];
;   38 |
;   39 |void sieve( void )
;   40 |{
	.sdecl	"code.sieve",CODE
	.sect	"code.sieve"
	.align	4
	.symb	LINE, 40
	.symb	TYPE, 269, 'X', 8, #1, 26, 0
	.symb	GFUN, "sieve", sieve, #269, 0, 32, 0
	.symb	ALAB, sieve, #269
sieve:
	.symb	SOFF, 32
	.symb	IDEN, "i", -28, #16, 131, 0x5
	.symb	IDEN, "prime", -24, #16, 131, 0x5
	.symb	IDEN, "k", -20, #16, 131, 0x5
	.symb	IDEN, "count", -16, #16, 131, 0x5
	.symb	IDEN, "iter", -12, #16, 131, 0x5
	nop
	sub16.a	sp,#32
;   41 |        int     i,prime,k,count,iter;
;   42 |        
;   43 |#ifdef PRINT
;   44 |        TC1775_ASC0_printf( "10 iterations\n\r" );
	.symb	LINE, 44
	movh.a	a4,#@his(_17)
	lea	a4,[a4]@los(_17)
	callg	TC1775_ASC0_printf
;   45 |#ifdef MEASURE_TIME
;   46 |        Begin_Time = clock();
	.symb	LINE, 46
	callg	clock
	st.w	Begin_Time,d2			; Begin_Time
;   47 |#endif
;   48 |#endif
;   49 |        for( iter = 1; iter <= 10; iter++ )     /* do program 10 times  */
	.symb	LINE, 49
	mov16	d15,#1				; iter
	st16.w	[sp]20,d15			; iter
	j	_28
_20:
;   50 |        {
;   51 |                count = 0;                      /* prime counter        */
	.symb	LINE, 51
	mov16	d15,#0				; count
	st16.w	[sp]16,d15			; count
;   52 |                for( i = 0; i <= size; i++ )    /* set all flags true   */
	.symb	LINE, 52
	mov16	d15,#0				; i
	st16.w	[sp]4,d15			; i
	j	_22
_21:
;   53 |                        flags[i] = true;
	.symb	LINE, 53
	movh.a	a15,#@his(flags)
	lea	a15,[a15]@los(flags)
	ld16.w	d15,[sp]4			; i
	addsc.a	a15,a15,d15,#0
	mov16	d15,#1				; 1
	st16.b	[a15],d15
	.symb	LINE, 52
	ld16.w	d15,[sp]4			; i
	add16	d15,#1				; i
	st16.w	[sp]4,d15			; i
_22:
	nop
	ld16.w	d15,[sp]4			; i
	mov	d7,#8190			; 8190
	jge	d7,d15,_21
;   54 |                for( i = 0; i <= size; i++ )
	.symb	LINE, 54
	mov16	d15,#0				; i
	st16.w	[sp]4,d15			; i
	j	_27
_23:
;   55 |                {
;   56 |                        if( flags[i] )          /* found a prime        */
	.symb	LINE, 56
	movh.a	a15,#@his(flags)
	lea	a15,[a15]@los(flags)
	ld16.w	d15,[sp]4			; i
	addsc.a	a15,a15,d15,#0
	ld.b	d15,[a15]
	jeq	d15,#0,_26
;   57 |                        {
;   58 |                                prime = i + i + 3; /* twice index + 3   */
	.symb	LINE, 58
	ld16.w	d15,[sp]4			; i
	ld.w	d7,[sp]4			; i
	add16	d15,d7
	add16	d15,#3
	st16.w	[sp]8,d15			; prime
;   59 |                                for(k=i+prime; k<=size; k+=prime)
	.symb	LINE, 59
	ld16.w	d15,[sp]4			; i
	ld.w	d7,[sp]8			; prime
	add16	d15,d7
	st16.w	[sp]12,d15			; k
	j	_25
_24:
;   60 |                                        flags[k] = false;
	.symb	LINE, 60
	movh.a	a15,#@his(flags)
	lea	a15,[a15]@los(flags)
	ld16.w	d15,[sp]12			; k
	addsc.a	a15,a15,d15,#0
	mov16	d15,#0				; 0
	st16.b	[a15],d15
	.symb	LINE, 59
	ld16.w	d15,[sp]12			; k
	ld.w	d7,[sp]8			; prime
	add16	d15,d7				; k
	st16.w	[sp]12,d15			; k
_25:
	nop
	ld16.w	d15,[sp]12			; k
	mov	d7,#8190			; 8190
	jge	d7,d15,_24
;   61 |                                                /* kill all multiples   */
;   62 |                                count++;        /* primes found         */
	.symb	LINE, 62
	ld16.w	d15,[sp]16			; count
	add16	d15,#1				; count
	st16.w	[sp]16,d15			; count
;   63 |                        }
	.symb	LINE, 63
_26:
	.symb	LINE, 54
	nop
	ld16.w	d15,[sp]4			; i
	add16	d15,#1				; i
	st16.w	[sp]4,d15			; i
_27:
	nop
	ld16.w	d15,[sp]4			; i
	mov	d7,#8190			; 8190
	jge	d7,d15,_23
	.symb	LINE, 49
	ld16.w	d15,[sp]20			; iter
	add16	d15,#1				; iter
	st16.w	[sp]20,d15			; iter
_28:
	nop
	ld16.w	d15,[sp]20			; iter
	lt	d15,d15,#11
	jne	d15,#0,_20
;   64 |                }
;   65 |        }
;   66 |#ifdef PRINT
;   67 |#ifdef MEASURE_TIME
;   68 |        End_Time = clock();
	.symb	LINE, 68
	callg	clock
	st.w	End_Time,d2			; End_Time
;   69 |#endif
;   70 |        TC1775_ASC0_printf( "%d primes.\n\r", count ); /* primes found on 10th pass   */
	.symb	LINE, 70
	movh.a	a4,#@his(_18)
	lea	a4,[a4]@los(_18)
	ld16.w	d15,[sp]16			; count
	st16.w	[sp],d15			; count
	callg	TC1775_ASC0_printf
;   71 |#ifdef MEASURE_TIME
;   72 |        TC1775_ASC0_printf( "Time: %d msec.\n\r",
;   73 |                1000 * (End_Time - Begin_Time) / CLOCKS_PER_SEC );
	.symb	LINE, 73
	movh.a	a4,#@his(_19)
	lea	a4,[a4]@los(_19)
	ld.w	d4,End_Time			; End_Time
	ld.w	d15,Begin_Time			; Begin_Time
	sub16	d4,d15
	mov	d15,#1000			; 1000
	mul16	d4,d15
	mov	d5,#1000			; 1000
	callg	__rt_udivmod
	st16.w	[sp],d2
	callg	TC1775_ASC0_printf
;   74 |#endif
;   75 |#endif
;   76 |}
	.symb	LINE, 76
	ret16
	.symb	EFUN
	.symb	ENDF
	.symb	TYPE, 270, 'Z', #2, 8190
	.symb	IDEN, "flags", flags, #270, 129, 0x0
	.symb	ALAB, flags, #270
	.sdecl	"farbss.sieve",DATA,CLEAR
	.sect	"farbss.sieve"
	.align	4
flags:
	.space	8191
	.sdecl	"fardata.sieve",DATA,INIT
	.sect	"fardata.sieve"
	.align	4
_18:
	.ascii	"%d primes."
	.byte	0x0a,0x0d,0x00
	.symb	IDEN, "End_Time", End_Time, #18, 131, 0x0
	.symb	ALAB, End_Time, #18
	.sdecl	"bss.sieve",DATA,CLEAR,ABS18
	.sect	"bss.sieve"
	.align	4
End_Time:
	.space	4
	.symb	TYPE, 272, 'X', 8, #7, 26, 0
	.symb	ALAB, clock, #272
	.sect	"fardata.sieve"
	.align	2
_19:
	.ascii	"Time: %d msec."
	.byte	0x0a,0x0d,0x00
	.symb	TYPE, 273, 'X', 8, #1, 26, 2, #258, #1
	.symb	ALAB, TC1775_ASC0_printf, #273
	.align	2
_17:
	.ascii	"10 iterations"
	.byte	0x0a,0x0d,0x00
	.symb	IDEN, "Begin_Time", Begin_Time, #18, 131, 0x0
	.symb	ALAB, Begin_Time, #18
	.sect	"bss.sieve"
Begin_Time:
	.space	4
	.sect	"farbss.sieve"
	.align	4
	.global	Begin_Time
	.global	End_Time
	.global	flags
	.global	sieve
	.extern	(CODE) TC1775_ASC0_printf
	.extern	(CODE) clock
	.extern	(CODE) __rt_udivmod
	.calls	"sieve", "TC1775_ASC0_printf"
	.calls	"sieve", "clock"
