1
#ifndef _KVI_STRASM_H_INCLUDED_
2
#define _KVI_STRASM_H_INCLUDED_
4
// =============================================================================
6
// --- kvi_strasm.h ---
8
// This file is part of the KVIrc IRC client distribution
9
// Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
11
// This program is FREE software. You can redistribute it and/or
12
// modify it under the terms of the GNU General Public License
13
// as published by the Free Software Foundation; either version 2
14
// of the License, or (at your opinion) any later version.
16
// This program is distributed in the HOPE that it will be USEFUL,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
// See the GNU General Public License for more details.
21
// You should have received a copy of the GNU General Public License
22
// along with this program. If not, write to the Free Software Foundation,
23
// Inc, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
// =============================================================================
28
// Inline assembly implementations of the commonly used string functions
29
// These will work only on i386 based machines and can be compiled
33
extern inline bool kvi_strEqualCS(const char *str1, const char *str2)
35
// An instruction pattern is really useful in this case.
36
// When inlining, GCC can optimize to load esi and edi
37
// directly with the strings, without pushing and getting it
40
__asm__ __volatile__ (
43
" lodsb %%ds:(%%esi),%%al\n"
44
" scasb %%es:(%%edi),%%al\n"
53
: "=a" (eax), "=&S" (str1), "=&D" (str2)
54
: "1" (str1), "2" (str2)
59
extern inline bool kvi_strEqualCSN(const char *str1, const char *str2, int len)
62
__asm__ __volatile__ (
79
: "=a" (eax), "=r" (str1), "=r" (str2), "=r" (len)
80
: "1" (str1), "2" (str2), "3" (len)
86
// The following two functions are used to compare a variable string with one in that
87
// only A-Z <-> a-z case insensivity is significant.
89
// kvi_strEqualNoLocalCI("a string that does not contain any strange char", str2)
90
// will always give the correct result
91
// These will NOT work with localizable characters:
92
// 'a' with umlaut will be not equal to 'A' with umlaut
93
extern inline bool kvi_strEqualNoLocaleCI(const char *str1, const char *str2)
95
// Trivial implementation
96
// Completely ignores locale. Only A-Z chars are transformed to a-z
97
// Anyway, it will work for IRC :)
100
__asm__ __volatile__ (
125
" xorl %%eax,%%eax\n"
127
: "=a" (eax), "=q" (reg), "=r" (str1), "=r" (str2)
128
: "2" (str1), "3" (str2)
133
extern inline bool kvi_strEqualNoLocaleCIN(const char *str1, const char *str2, int len)
137
__asm__ __volatile__ (
165
" xorl %%eax,%%eax\n"
167
: "=a" (eax), "=q" (reg), "=r" (str1), "=r" (str2), "=r" (len)
168
: "2" (str1), "3" (str2), "4" (len)
173
extern inline int kvi_strLen(const char *str)
176
__asm__ __volatile__(
182
: "=c" (ecx), "=&D" (str)
183
: "0" (0xffffffff), "1" (str), "a" (0)
188
#endif // _KVI_STRASM_H_INCLUDED_