Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Which will be faster [C]

Name: Anonymous 2009-05-08 17:12

Bitfields (struct s { unsigned char w:1, x:1, y:2, z:4; };)
or bit operations (#define get_y(s) ((s >> 4) & 3))?

Yes, I'm a premature optimizer.

Name: Anonymous 2009-05-08 17:15

WHY DON‘T YOU FUCKING TEST IT?

Name: Anonymous 2009-05-08 17:25

I'm a premature optimizer.
Funny you should say that, because I'm a premature ejaculator

Name: Anonymous 2009-05-08 17:25

I suggest you think for half a second about the assembly code that will be generated by manipulating the bitfield.

Name: Anonymous 2009-05-08 17:59

>>2
Because I want to get advice from EXPERT C PROGRAMMERS with 20+ years of experience .

>>4
I have no idea, this is my first real C project and I've never done any assembly before (it's on my to-do list, though). I suppose it would involve bitwise operations, but I wonder which version will get more optimized/be more portable.

Name: Anonymous 2009-05-08 18:07

man time
http://google.com/search?q=c+profiler (experts only)

Name: Anonymous 2009-05-08 18:11

>>6
oh yeah. that's right. it's that time again. man time.

Name: Anonymous 2009-05-08 18:22

I'd guess they'd be the same (and that the compiler would turn a reference to the structure into the macro during compilation), but again it is smartest to test it because it is also compiler-dependent one what will actually be done.

Name: Anonymous 2009-05-08 18:27

Actually you're right guys, I'll test it myself.

Name: Anonymous 2009-05-08 19:12

>>9
What about our are right?

Name: Anonymous 2009-05-08 19:16

>>10
It's wrong

Name: Anonymous 2009-05-08 19:59

id like have to sex but im totally sad

Name: Anonymous 2009-05-09 10:50

Macros will almost always produce better code, there is no way in which C bitfields do not suck.

If you worry about this, you're by definition doing it wrong.

Name: Anonymous 2009-05-09 11:04

>>13
there is no way in which C bitfields do not suck
If you worry about this, you're by definition doing it wrong.

:(
What do you mean?

Name: Anonymous 2009-05-09 11:53

>>14
Anus.

Name: Anonymous 2009-05-09 11:59

Bitfields are usually accessed using simple and/test/sh*/jcc operations(for x86*). You are using a 'shr' and 'and', either way it'll be very fast, but if you want, examing the compiled code and  get the intel processor manuals to decide which will be slightly faster than the other for the specific compiler(and the used settings) and target architecture.

Name: Anonymous 2009-05-09 12:03

>>16
+4, Insightful
Thanks.

Name: Anonymous 2009-05-09 12:11

>>17
Go back to /pr/, everything about >>16 was wrong.

Name: Anonymous 2009-05-09 12:41

>>18
Stop bullying me :<

Name: Anonymous 2011-02-02 23:18

Name: Anonymous 2011-02-04 15:12

Name: Anonymous 2011-02-17 19:25

check 'em

Don't change these.
Name: Email:
Entire Thread Thread List