   Fast double word toupper
  I've been looking for a way to apply toupper() to every byte in a dword, presumably 4 bytes. OR'ing together the bytes after separating them and passing them to toupper is too slow, and simply AND'ing the dword with 0xDFDFDFDF doesn't work because if the individual bytes aren't characters, their values are lost. Anyone have a solution?   
  Pointer manipulation ftw.It's been a while since I've needed to do anything this low level, but this should do what you need:void dwordupper(DWORD *word){    char *charptr = (char*)word; for(int ix = 0; ix < 4; ++ix){   charptr[ix] = (char)toupper((int)charptr[ix]);    }}Dunno about speed, but...   ;  While that would be feasible, speed is the top priority in this case, and this is too slow for my purposes. This is to be done maybe 10 times, maybe hundreds or thousands of times in a tight loop.   ;Quote:Original post by EctaraWhile that would be feasible, speed is the top priority in this case, and this is too slow for my purposes. This is to be done maybe 10 times, maybe hundreds or thousands of times in a tight loop.And...?Given your requirements as stated, I'm not sure you're going to find a faster way to upcase arbitrary characters that happen to be packed into dwords.[edit:though I suppose you could build some sort of abomination that does the up-case logic on dwords directly...Though I also can't imagine that speed is *that* important, or the process can't be alleviated by process rather than technology...]   ;  Thank you for your help. I'll keep looking.   ;  Unsurprisingly, searching came up inconclusive elsewhere. This is the best "abomination" I can come up with off the top of my head. Not sure about the efficiency, but it's the closest I'm going to get.#define TOUPPERCHAR(x) ((0xE0 & (x)) == 0x60) ? (x) & 0xDF : (x))#define TOUPPERDWORD(x) (TOUPPERCHAR((x)>>24)|TOUPPERCHAR(((x)>>16) & 0xFF)|TOUPPERCHAR(((x)>>8) & 0xFF)|TOUPPERCHAR((x) & 0xFF));  Make a char look-up table of the upper case values in the locale you're interested in.Then:char lut[255];void upper_range(unsigned *b, unsigned *e){    for (char *bc = reinterpret_cast<char *>(b), *ec = reinterpret_cast<char *>(e);    bc != ec;    ++bc)    {   *bc = lut[*bc];    }}You could also use a 16bit look-up to do 2 chars at a time. But that would involve shifting and/or dodgy aliasing.Do you really have profiling data to suggest toupper is a bottleneck?   ;  The look up table is a viable option, but I worry that may not be a good choice for my current implementation. Right now, I'm writing a fast stricmp function, and it speeds up the comparison by aligning on a 4 byte boundary, then doing the comparison 4 bytes at a time. I write my own also because the target platform might not have it. toupper() need not be the bottleneck, and I've already heard the usual speech about avoiding micro-optimization, but the goal here is micro-optimization.   ;  ZOMG:int toUpper(int i) {  return i & ~((i-1) & (i+5) & (i >> 1) & (~i >> 2) & 538976288);}Quote:I'm writing a fast stricmp functionWon't really work, for many reasons.But still, good times...   ;Quote:Original post by AntheusZOMG:int toUpper(int i) {  return i & ~((i-1) & (i+5) & (i >> 1) & (~i >> 2) & 538976288);}Quote:I'm writing a fast stricmp functionWon't really work, for many reasons.But still, good times...I love code like that. The scribblings of a madman. I'll test it out in a bit, thanks.   