I am building my own stdc and stdc++ libraries for my own kernel. Trying to do some optimization to enhance performance I noticed that calling C functions from C++ in the user mode is very slow!
I was able to isolate the problem in a separate case. I have the ctype library in the stdc:
Code: Select all
#ifndef CTYPE_H_
#define CTYPE_H_
#define _U 0x01
#define _L 0x02
#define _N 0x04
#define _S 0x08
#define _P 0x10
#define _C 0x20
#define _X 0x40
#define _B 0x80
extern "C" {
unsigned char isalnum(unsigned char);
unsigned char isalpha(unsigned char);
unsigned char iscntrl(unsigned char);
unsigned char isdigit(unsigned char);
unsigned char isgraph(unsigned char);
unsigned char islower(unsigned char);
unsigned char isprint(unsigned char);
unsigned char ispunct(unsigned char);
unsigned char isspace(unsigned char);
unsigned char isupper(unsigned char);
unsigned char isxdigit(unsigned char);
unsigned char tolower(unsigned char);
unsigned char toupper(unsigned char);
}
#endif
Code: Select all
#include <ctype.h>
unsigned char isalnum(unsigned char _c)
{
return (_c > 47 && _c < 58) || (_c > 64 && _c < 91) || (_c > 96 && _c < 123);
}
unsigned char isalpha(unsigned char _c)
{
return (_c > 64 && _c < 91) || (_c > 96 && _c < 123);
}
unsigned char iscntrl(unsigned char _c)
{
return (_c >= 0 && _c < 32) || (_c == 127);
}
unsigned char isdigit(unsigned char _c)
{
return (_c > 47 && _c < 58);
}
unsigned char isgraph(unsigned char _c)
{
return (_c > 32 && _c < 127);
}
unsigned char islower(unsigned char _c)
{
return (_c > 96 && _c < 123);
}
unsigned char isprint(unsigned char _c)
{
return (_c > 31 && _c < 127);
}
unsigned char ispunct(unsigned char _c)
{
return (_c > 32 && _c < 48) || (_c > 57 && _c < 65) || (_c > 90 && _c < 97) || (_c > 122 && _c < 127);
}
unsigned char isspace(unsigned char _c)
{
return ((_c > 8 && _c < 14) || (_c == 32));
}
unsigned char isupper(unsigned char _c)
{
return (_c > 64 && _c < 91);
}
unsigned char isxdigit(unsigned char _c)
{
return (_c > 47 && _c < 58) || (_c > 64 && _c < 71) || (_c > 96 && _c < 103);
}
unsigned char tolower(unsigned char _c)
{
return (_c > 64 && _c < 91) ? _c + 32 : _c;
}
unsigned char toupper(unsigned char _c)
{
return (_c > 96 && _c < 123) ? _c - 32 : _c;
}
Code: Select all
#ifndef CCTYPE_H_
#define CCTYPE_H_
#include <ctype.h>
namespace std{
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isalnum(int c)
{
return ::isalnum(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isalpha(int c)
{
return ::isalpha(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int iscntrl(int c)
{
return ::iscntrl(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isdigit(int c)
{
return ::isdigit(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isgraph(int c)
{
return ::isgraph(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int islower(int c)
{
return ::islower(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isprint(int c)
{
return ::isprint(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int ispunct(int c)
{
return ::ispunct(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isspace(int c)
{
return ::isspace (c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isupper(int c)
{
return ::isupper(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isxdigit(int c)
{
return ::isxdigit(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int tolower(int c)
{
return ::tolower(c);
}
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int toupper(int c)
{
return ::toupper(c);
}
};
#endif
Code: Select all
inline __attribute__ ((__visibility__("hidden"))) __attribute__ ((__always_inline__))
int isspace(int c)
{
return ((c > 8 && c < 14) || (c == 32));
}
Thanks,
Karim.