- It seems like this should cause better code to be generated.
- However, on x86 at least, the resulting .o file is about 20%
- larger then the switch-statment version. I am leaving this
- code in because the results may be different on other
- platforms (e.g., PowerPC or x86-64)."""
-
- return 0
- count = 0
- for a in self.enums:
- count += 1
-
- # Determine if there is some mask M, such that M = (2^N) - 1,
- # that will generate unique values for all of the enums.
-
- mask = 0
- for i in [1, 2, 3, 4, 5, 6, 7, 8]:
- mask = (1 << i) - 1
-
- fail = 0;
- for a in self.enums:
- for b in self.enums:
- if a != b:
- if (a & mask) == (b & mask):
- fail = 1;
-
- if not fail:
- break;
- else:
- mask = 0
-
- if (mask != 0) and (mask < (2 * count)):
- masked_enums = {}
- masked_count = {}
-
- for i in range(0, mask + 1):
- masked_enums[i] = "0";
- masked_count[i] = 0;
-
- for c in self.count:
- for e in self.count[c]:
- i = e & mask
- masked_enums[i] = '0x%04x /* %s */' % (e, self.enums[e][0])
- masked_count[i] = c
-
-
- print ' static const GLushort a[%u] = {' % (mask + 1)
- for e in masked_enums:
- print ' %s, ' % (masked_enums[e])
- print ' };'
-
- print ' static const GLubyte b[%u] = {' % (mask + 1)
- for c in masked_count:
- print ' %u, ' % (masked_count[c])
- print ' };'
-
- print ' const unsigned idx = (e & 0x%02xU);' % (mask)
- print ''
- print ' return (e == a[idx]) ? (GLint) b[idx] : 0;'
- return 1;
- else:
- return 0;
-
- def PrintUsingSwitch(self):
- """Emit the body of the __gl*_size function using a
- switch-statement."""
-
- print ' switch( e ) {'
-
- for c in self.count:
- for e in self.count[c]:
- first = 1
-
- # There may be multiple enums with the same
- # value. This happens has extensions are
- # promoted from vendor-specific or EXT to
- # ARB and to the core. Emit the first one as
- # a case label, and emit the others as
- # commented-out case labels.
-
- for j in self.enums[e]:
- if first:
- print ' case %s:' % (j)
- first = 0
- else:
- print '/* case %s:*/' % (j)
-
- print ' return %u;' % (c)
-
- print ' default: return 0;'
- print ' }'