LCC v1.31 (Nov 23 2010 16:35:08) generates bad code

Using VSDSP legacy command line tools.
Post Reply
victor
User
Posts: 19
Joined: Wed 2011-01-19 9:36
Contact:

LCC v1.31 (Nov 23 2010 16:35:08) generates bad code

Post by victor » Sat 2011-01-29 8:45

A simple benchmark program fails to compile on LCC v1.31 (Nov 23 2010 16:35:08), because LCC generates a bad instruction. Here is the C code:

Code: Select all

#include <stdlib.h>
#include <stdio.h>

register __a unsigned long fast_divide32unsigned(register __b unsigned long dividend, register __a unsigned long divisor);
register __a unsigned long fast1_divide32unsigned(register __b unsigned long dividend, register __a unsigned long divisor);

main(void) {
	srand(39238);
	printf("starting benchmark...\n");
	while(1)
	{
		unsigned long j,k;
		unsigned long r1,r2,r3;
		j = (((unsigned long)rand() & 0xffl) << 24) | (((unsigned long)rand() & 0x0fffl) << 12) | ((unsigned long)rand() & 0x0fffl);
		j >>= (rand() & 0x03);							// generate random dividend
		k = (((unsigned long)rand() & 0xffl) << 24) | (((unsigned long)rand() & 0x0fffl) << 12) | ((unsigned long)rand() & 0x0fffl);
		k >>= (rand() & 0x1f);							// generate random divisor
		r1 = j / k; 									// old library routine
		r2 = fast_divide32unsigned(j,k);				// optimized version
		r3 = fast1_divide32unsigned(j,k);				// further optimized version
		if(r1 != r2 || r1 != r3)
		{
			printf("error : %lu / %lu = %lu, = %lu, = %lu\n",j,k,r1,r2,r3);
		}
	}
	return 0;
}

The following wrong assembly code is generated by LCC:

Code: Select all

......
	stx A0,(I4) ; sty A1,(I4)+1	// A0 spills to #0
// 		r1 = j / k;
	call divide32unsigned
	ldx (I4)+3,NULL ; ldy (I4)-3,B1	//The same index register used as a target register (load or post-modification) more than once
// jumped away
	add A,NULL,D ; ldx (I4),B0	// A -> 'r1'
......
The subroutine "fast_divide32unsigned" and "fast1_divide32unsigned" are written in assembly.They can be found at viewtopic.php?f=8&t=231
Attachments
main.c
(1.17 KiB) Downloaded 422 times
main.a.c
The extension ".a" is not allowed, so I have to change it to ".a.c"
(4.81 KiB) Downloaded 396 times

Lasse
VLSI Staff
Posts: 27
Joined: Tue 2010-06-22 13:30

Re: LCC v1.31 (Nov 23 2010 16:35:08) generates bad code

Post by Lasse » Mon 2011-01-31 13:46

Just to let you know -- I was able to reproduce that issue. Indeed, seems like a compiler bug. We will look into it, thanks for letting us know!

Edit: I think we now have a fix for this. The updated compiler will be included in the new VSIDE release (v. 2.08) which should be ready to go public very soon. Stay tuned ;)
Software Designer
VLSI Solution

Post Reply