Author Topic: Coding 1k Intro  (Read 11085 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Coding 1k Intro
« Reply #20 on: April 18, 2008 »
I'm unsure how the compiler will deal with this:

Code: [Select]
temp = (temp+1)%2048;

As I don't think there's an ASM Mod instruction, you could try &2047 instead since it's a power of 2 which will do the same thing but the compiler might already be doing that.

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Coding 1k Intro
« Reply #21 on: April 18, 2008 »
@Stonemonkey:
thanks for the great & instead using % trick... it really saved me 21 bytes in the packed version! O.O   *kewl*  :goodpost:


Edited:
Atm i am using
Code: [Select]
temp = (temp+=1)&2047;
« Last Edit: April 18, 2008 by va!n »
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Coding 1k Intro
« Reply #22 on: April 18, 2008 »
You're welcome, good that it helped but remember it will only work when it's powers of 2.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Coding 1k Intro
« Reply #23 on: April 18, 2008 »
I take it

Code: [Select]
temp = (temp+=1)&2047;

works out the same as

Code: [Select]
temp = (temp++)&2047;

EDIT:
why is it not
Code: [Select]
temp=(temp+1)&2047
?
« Last Edit: April 18, 2008 by Stonemonkey »

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Coding 1k Intro
« Reply #24 on: April 18, 2008 »
changed it to:
Code: [Select]
temp = (temp+=1)&2047;

... but seems there is no size different between temp+1 and temp++
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Coding 1k Intro
« Reply #25 on: April 19, 2008 »
You mustn't use either of these two lines.  It's invalid C because the value of temp is modified twice in the same expression (ie, temp+=1 is an assignment, and so is temp=).  The compiler might well compile it, and it might well do what you want, but it's wrong.
Code: [Select]
temp = (temp+=1)&2047;
temp = (temp++)&2047;

You should do this:
Code: [Select]
temp++;
temp&=2047;

This expression is silly:
Code: [Select]
buffer[x+ ((y+70)*640) ]=

Because x only ever goes up by 1, you can have outside the loop.
unsigned int *buffer_ptr = buffer+70*640;
Then, inside the loop, you can just do
Code: [Select]
*buffer_ptr++ =

Jim
Challenge Trophies Won: