Skip to contentSkip to conversation

bitops.h: Add field32() and field64() functions to extract bitfields

PATCH Avi Kivity 2 participants 2 messages Jul 8, 2012 9 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAAu8pHuqj513DVNLXqsdD2Qg9+LwDHz6DzQxYn-HEnAA=0Unwg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAFEAcA-uHBFkfcwCtv0EKcJRNzYYf_jtTs1W9BECEeJo6gT+Xg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAAu8pHtcv6Z4Sa4FY53tA3zp3n8xBvQD_E1yYugaAVa-36eZow@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAFEAcA8_BXHb8VPf8sqfJs39JF-CagaHj92tzA6ijtgnSVhmcA@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAAu8pHtWt+aAaO-Vr_N5z7_qqzWknP+nRsxPg+iQAeoHdzmF4w@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAAu8pHv_CjT+bd_GA4eM9eG=1Sxz0EWF=nhSLTyixNjOXPMhTg@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

Avi Kivity

author
#9 lore raw
Quoted 8 lines · Markus Armbruster
Quoted 6 lines
Quoted 2 lines

Better code is an argument only if the effect can be demonstrated.

I don't know even for which compilers or CPUs this is true so it's unlikely I could demonstrate it. However, googling finds a few articles in defense of this.

Hearsay. Your honor, I rest my case :)

On x86_64, conversion from unsigned to unsigned long takes zero instructions, but conversion from int to long takes one instruction. So expressions like a[i] are one instruction shorter if the index is unsigned.

unsigned is also slightly safer from a security perspective, since you only need to consider overflow, not underflow.

I used to be an int fan but I have been converted. My fingers still prefer int though.

Signature · 1 line
error compiling committee.c: too many arguments to function
#10 lore raw
Quoted 8 lines · Avi Kivity
Quoted 7 lines · Markus Armbruster
Quoted 6 lines
Quoted 2 lines

Better code is an argument only if the effect can be demonstrated.

I don't know even for which compilers or CPUs this is true so it's unlikely I could demonstrate it. However, googling finds a few articles in defense of this.

Quoted 8 lines
Quoted 1 line

Hearsay. Your honor, I rest my case :)

On x86_64, conversion from unsigned to unsigned long takes zero instructions, but conversion from int to long takes one instruction. So expressions like a[i] are one instruction shorter if the index is unsigned.

unsigned is also slightly safer from a security perspective, since you only need to consider overflow, not underflow.

Q.E.D. Expect patches to convert bitops to unsigned shortly.

Quoted 8 lines

I used to be an int fan but I have been converted. My fingers still prefer int though.

--
error compiling committee.c: too many arguments to function