rif_xu@eds.ericsson.se (07/27/89)
/* I'm having some troubles with Think's LSC: a) The program below,which sorts primes out, doesn't give correct results - it even pops out some even numbers ! - when compiled using TLSC 3.01p4. I used the '020 setting and used the MacTraps and the Stdio libs. Includes was <stdio.h> of course. I have compiled the same program on our VAX and on MPW C 2.02 and they give the correct result. Why doesn't TLSC compile correctly ? b) I have translated the standard Whetstone benchmark into C. It worked when compiling with the MPW C 2.02 compiler (by the way, I got 830 000 Whets/s on a MACII- anyone beaten that ?) but in TLSC I get the link error 'Code segment too big <MacTraps>'. I used the math881,std881 and Mactraps libraries and had the settings for the '881 and '020 on. Can anybody help ? Please mail me... Thanks Sigge Ruschkowski Ericsson Components Sweden /* * Virtual sieve to find primes. Requires only O(sqrt(N)) space to * find primes up to N. * * WARNING: This code assumes that ints are 32 bits * * Arch D. Robison * University of Illinois at Urbana-Champaign * * UUCP: {pur-ee,convex}!uiucdcs!robison * Internet: robison@CS.UIUC.EDU */ #define SQRT_N 100 /* Program prints all primes less than SQRT_N*SQRT_N */ int multiple[SQRT_N/2]; int primes[SQRT_N/2]; int count; int numberofprimes; #define SIEVE_WORDS (1+(SQRT_N-1)/32) int sieve[SIEVE_WORDS]; #define WORD(i) sieve[(i)>>5] #define BIT(i) (1<<(i&0x1F)) #define test_bit(i) (WORD(i)&BIT(i)) #define set_bit(i) (WORD(i)|=BIT(i)) void clear_bits() { /* clear the sieve */ register int i; for( i=0; i<SIEVE_WORDS; i++ ) sieve[i] = 0; } void knock_out( i ) int i; { register int m,p = primes[i]; for(m = multiple[i]; m < SQRT_N; m+=p ) set_bit( m ); multiple[i] = m; } main () { int p_base = 0; int p_offset = 2; while( p_base < SQRT_N*SQRT_N ) { int p = p_base + p_offset; if( !test_bit( p_offset )) { numberofprimes++; printf( "%d\n", p ); if( p_base == 0 ) { multiple[count] = primes[count] = p_offset; knock_out( count++ ); } } if( ++p_offset >= SQRT_N ) { int i; clear_bits(); p_offset = 0; p_base += SQRT_N; for( i=0; i<count; i++ ) { multiple[i] -= SQRT_N; knock_out( i ); } } } printf("\n\n\n Primes %d",numberofprimes); }
ephraim@.COM (Ephraim Vishniac) (07/27/89)
In article <1814@eds.ericsson.se> rif_xu@eds.ericsson.se writes: >/* > I'm having some troubles with Think's LSC: > > a) The program below,which sorts primes out, doesn't give > correct results - it even pops out some even numbers ! - > when compiled using TLSC 3.01p4. I used the '020 setting > and used the MacTraps and the Stdio libs. Includes was > <stdio.h> of course. [more comments deleted] >/* > * Virtual sieve to find primes. Requires only O(sqrt(N)) space to > * find primes up to N. > * > * WARNING: This code assumes that ints are 32 bits As noted in the manual, LSC assumes that ints are 16 bits. So, you lose this one. The moral is that portable programs should *never* say "int" but should always say "short" or "long". In MPW and on the VAX, ints are 32 bits. That's why they give different results than LSC in this case. Enough verbiage yet? Our news software has the fascist line-counter feature to stop you from follow-ups without enough new material. Ephraim Vishniac ephraim@think.com ThinkingCorp@applelink.apple.com Thinking Machines Corporation / 245 First Street / Cambridge, MA 02142 One of the flaws in the anarchic bopper society was the ease with which such crazed rumors could spread.
siegel@endor.harvard.edu (Rich Siegel) (07/28/89)
In article <1814@eds.ericsson.se> rif_xu@eds.ericsson.se writes: > a) The program below,which sorts primes out, doesn't give > correct results - it even pops out some even numbers ! - > * WARNING: This code assumes that ints are 32 bits This is the problem; in LightspeedC, ints are 16 bits, not 32. R. ~~~~~~~~~~~~~~~ Rich Siegel Staff Software Developer Symantec Corporation, Language Products Group Internet: siegel@endor.harvard.edu UUCP: ..harvard!endor!siegel "When it comes to my health, I think of my body as a temple - or at least a moderately well-managed Presbyterian youth center." - Emo Phillips ~~~~~~~~~~~~~~~