|
@@ -104,3 +104,41 @@ void * __memmove ( void *dest, const void *src, size_t len ) {
|
104
|
104
|
return __memcpy_reverse ( dest, src, len );
|
105
|
105
|
}
|
106
|
106
|
}
|
|
107
|
+
|
|
108
|
+/**
|
|
109
|
+ * Compare strings (up to a specified length)
|
|
110
|
+ *
|
|
111
|
+ * @v str1 First string
|
|
112
|
+ * @v str2 Second string
|
|
113
|
+ * @v len Maximum length
|
|
114
|
+ * @ret diff Difference
|
|
115
|
+ */
|
|
116
|
+int strncmp ( const char *str1, const char *str2, size_t len ) {
|
|
117
|
+ const void *discard_S;
|
|
118
|
+ const void *discard_D;
|
|
119
|
+ size_t discard_c;
|
|
120
|
+ int diff;
|
|
121
|
+
|
|
122
|
+ __asm__ __volatile__ ( "\n1:\n\t"
|
|
123
|
+ "dec %2\n\t"
|
|
124
|
+ "js 2f\n\t"
|
|
125
|
+ "lodsb\n\t"
|
|
126
|
+ "scasb\n\t"
|
|
127
|
+ "jne 3f\n\t"
|
|
128
|
+ "testb %b3, %b3\n\t"
|
|
129
|
+ "jnz 1b\n\t"
|
|
130
|
+ /* Equal */
|
|
131
|
+ "\n2:\n\t"
|
|
132
|
+ "xor %3, %3\n\t"
|
|
133
|
+ "jmp 4f\n\t"
|
|
134
|
+ /* Not equal; CF indicates difference */
|
|
135
|
+ "\n3:\n\t"
|
|
136
|
+ "sbb %3, %3\n\t"
|
|
137
|
+ "orb $1, %b3\n\t"
|
|
138
|
+ "\n4:\n\t"
|
|
139
|
+ : "=&S" ( discard_S ), "=&D" ( discard_D ),
|
|
140
|
+ "=&c" ( discard_c ), "=&a" ( diff )
|
|
141
|
+ : "0" ( str1 ), "1" ( str2 ), "2" ( len ) );
|
|
142
|
+
|
|
143
|
+ return diff;
|
|
144
|
+}
|