• Welcome to Dark Bit Factory & Gravity.
 

Coding 1k Intro

Started by va!n, March 20, 2008

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stonemonkey

I'm unsure how the compiler will deal with this:


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.

va!n

#21
@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

temp = (temp+=1)&2047;
- 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:

Stonemonkey

You're welcome, good that it helped but remember it will only work when it's powers of 2.

Stonemonkey

#23
I take it


temp = (temp+=1)&2047;


works out the same as


temp = (temp++)&2047;


EDIT:
why is it not

temp=(temp+1)&2047

?

va!n

changed it to:

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:

Jim

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.

temp = (temp+=1)&2047;
temp = (temp++)&2047;


You should do this:

temp++;
temp&=2047;


This expression is silly:

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

*buffer_ptr++ =


Jim
Challenge Trophies Won: