[lore] C hacks

Adrian Chadd adrian at ucc.gu.uwa.edu.au
Fri Mar 28 10:33:50 WST 2008


And on that note, I can quote some passages from CPU optimisation
guides - explaining how modern intel-based architectures differ from
what you're being taught in introductory CS, and what you can do to
fix it.

Hm, an article on modern CPU architectures .. how many pages do I get?
Is 2 ok?



Adrian

On Fri, Mar 28, 2008, David Basden wrote:
> I was thinking that maybe people are just writing C that is either
> too readable, too inefficient or both. Maybe a connect-the-equivilent-
> code puzzle or something?
> 
> Here is just a quick one 'cause I'm beyond tired, but please add to it;
> I don't know if the third works, and might not be a good idea to let out
> in public even if it does...
> 
> while (*a++ == *b++);	 strcpy(b,a);
> 
> a ^= b ^= a;			int tmp = a;
>                                 a = b;
>                                 b = a;
> 
> a >> 1;				a = a / 2;
> 
> b = (((a - b) & (1<<(sizeof(int)-1))) && b) || a; 	if (a > b) b = a;
> 
> a << 3;				a =  a * 8;
> 
> 1 << a;				(int) pow((int) a, 2);
> 
> a & 1;				a % 2;
> 
> a & 7;				a % 8;
> 
> (a & 15) || ++b;		if (a % 16 == 0) 
> 					b = b + 1;
> 
> _______________________________________________
> lore mailing list
> lore at ucc.gu.uwa.edu.au
> http://lists.ucc.gu.uwa.edu.au/mailman/listinfo/lore


More information about the lore mailing list