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

OPTIMIZED ENTERPRISE ANONIX

Name: Anonymous 2011-07-07 0:31

#ifndef OMG_OPTIMIZED_CTYPE_H_
#define OMG_OPTIMIZED_CTYPE_H_

/**
 *                        __ _   _  ____  _   _ _ _  _
 *                       /  |  \| |/ __ \|  \| | | \/ /
 *                      /   |   \ | |  | |   \ | |\  /
 *                     /  . | |\  | |__| | |\  | |/  \
 *                    /__/|_|_| \_|\____/|_| \_|_|_/\_\
 *       
 *                       OPTIMIZED ANONIX INTERFACES
 *
 *  -------------------------------------------------------------------------
 *
 *  Optimized branchless ctype facilities using bitwise operations. Assumes a
 *  fixed ASCII (ANSI_X3.110-1983) code page. Functions are ISO/IEC 9899:1999
 *  (C99) compliant. Requires an ISO/IEC 9899:1999 (C99) compliant compiler.
 * 
 *  Version: 1.666alpha
 *  Bug Reports: strawberryshake [at] 1337 [dot] jp
 */
 
inline int isblank(int c) { return (c == ' ') | (c == '\t') | (c == '\v'); }
inline int iscntrl(int c) { return (c <= 0x1F) | (c == 0x7F); }
inline int isdigit(int c) { return (((unsigned int)c) - ((unsigned int)'0')) <= ((unsigned int)('9' - '0')); }
inline int isgraph(int c) { return (((unsigned int)c) - ((unsigned int)'!')) <= ((unsigned int)('~' - '!')); }
inline int islower(int c) { return (((unsigned int)c) - ((unsigned int)'a')) <= ((unsigned int)('z' - 'a')); }
inline int isprint(int c) { return (((unsigned int)c) - ((unsigned int)' ')) <= ((unsigned int)('~' - ' ')); }
inline int isupper(int c) { return (((unsigned int)c) - ((unsigned int)'A')) <= ((unsigned int)('Z' - 'A')); }
inline int isalpha(int c) { return ::hrc::islower(c) | ::hrc::isupper(c); }
inline int isalnum(int c) { return ::hrc::islower(c) | ::hrc::isupper(c) | ::hrc::isdigit(c); }
inline int ispunct(int c) { return ~(::hrc::islower(c) | ::hrc::isupper(c) | ::hrc::isdigit(c)); }
inline int isspace(int c) { return ::hrc::isblank(c) | (c == '\f') | (c == '\n') | (c == '\r'); }

inline int isxdigit(int c) {
    return ::hrc::isdigit(c) |
        ((((unsigned int)c) - ((unsigned int)'a')) <= ((unsigned int)('f' - 'a'))) |
        ((((unsigned int)c) - ((unsigned int)'A')) <= ((unsigned int)('F' - 'A')));
}

inline int tolower(int c) {
    unsigned int upper = (unsigned int)::hrc::isupper(c);
    return (int)((((~upper) + 1) & ((unsigned int)(c - 'A' + 'a'))) | ((~(upper - 1)) & ((unsigned int)c)));
}

inline int toupper(int c) {
    unsigned int lower = (unsigned int)::hrc::islower(c);
    return (int)((((~lower) + 1) & ((unsigned int)(c - 'a' + 'A'))) | ((~(lower - 1)) & ((unsigned int)c)));
}

#endif

Name: Anonymous 2011-07-07 5:17

>>14
I'm working on it. I actually need to write my own vsnprintf and vsnwprintf soon, along with non-standard vsnu16printf, and vsnu32printf implementations. The default printf in most Standard C libraries, including glibc/eglibc, are terribly slow, locking global mutexes to obtain access to global locale tables, causing cache misses, as well as allocating temporary buffers on the heap, even when such allocations are small and could be safely done on the stack in most cases. If you really need locale specific stuff, much better use the thread-safe POSIX-2008.1 locale variants of functions with the _l suffix.

I just finished my own <clocale>, <cstring>, <cwchar>[code], [code]<cuchar>, <cctype>, <cwctype> headers with POSIX-2008.1 conformance support on Linux, Windows, OS X, and Playstation 3. In most cases, I'm just importing the Standard C library functions into our project's namespace with using declarations, providing implementations for missing functions where needed, as well as rewriting ANY and ALL functions that touch the global locale to not do so which also entailed writing string functions for UTF-8, UTF-16, and UTF-32.

I'm laying the foundations for our next-gen multi-platform engine code-base.

I have an XBox 360 dev kit too, but we've decided to drop support for the 360 going forward as they're planning on announcing new shit next year and we'll probably get in early as partners. PS3 will probably still be Sony's primary console until 2014, given Sony's financial troubles, and the costs involved in launching a new platform.

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