blob: b57dfd7753fed34aabf3536aa48ec3de629caa10 [file] [log] [blame]
Denys Vlasenko8f8ee532010-10-24 03:07:18 +02001 smalluint i = index_in_str_array(params, name) + 1;
2 if (i == 0)
3 return 0;
4 if (!(i == 4 || i == 5))
5 i |= 0x80;
6
7 return i;
8
9I think that this optimization is wrong.
10index_in_str_array returns int. At best, compiler will use it as-is.
Denys Vlasenko738e4de2010-10-24 03:23:59 +020011At worst, compiler will try to make sure that it is properly cast
Denys Vlasenko8f8ee532010-10-24 03:07:18 +020012into a byte, which probably results in "n = n & 0xff" on many architectures.
13
14You save nothing on space here because i is not stored on-stack,
Denys Vlasenko738e4de2010-10-24 03:23:59 +020015gcc will keep it in register. And even if it *is* stored,
Denys Vlasenko8f8ee532010-10-24 03:07:18 +020016it is *stack* storage, which is cheap (unlike data/bss).
17
18small[u]ints are useful _mostly_ for:
Denys Vlasenko738e4de2010-10-24 03:23:59 +020019
Denys Vlasenko8f8ee532010-10-24 03:07:18 +020020(a) flag variables
21 (a1) global flag variables - make data/bss smaller
22 (a2) local flag variables - "a = 5", "a |= 0x40" are smaller
23 for bytes than for full integers.
24 Example:
25 on i386, there is no widening constant store instruction
26 for some types of address modes, thus
27 movl $0x0,(%eax) is "c7 00 00 00 00 00"
28 movb $0x0,(%eax) is "c6 00 00"
29(b) small integer structure members, when you have many such
Denys Vlasenko738e4de2010-10-24 03:23:59 +020030 structures allocated,
Denys Vlasenko8f8ee532010-10-24 03:07:18 +020031 or when these are global objects of this structure type
32
33small[u]ints are *NOT* useful for:
Denys Vlasenko738e4de2010-10-24 03:23:59 +020034
Denys Vlasenko8f8ee532010-10-24 03:07:18 +020035(a) function parameters and return values -
36 they are pushed on-stack or stored in registers, bytes here are *harder*
37 to deal with than ints
38(b) "computational" variables - "a++", "a = b*3 + 7" may take more code to do
39 on bytes than on ints on some architectires.