iter 23.3.1: runtime ail_str_compare + IR header declaration
This commit is contained in:
@@ -24,3 +24,17 @@
|
||||
bool ail_str_eq(const char *a, const char *b) {
|
||||
return strcmp(a, b) == 0;
|
||||
}
|
||||
|
||||
/* Three-way comparison of NUL-terminated strings. Normalises libc
|
||||
* strcmp's signed-int output to exactly -1 / 0 / +1 so the codegen
|
||||
* caller can branch on `icmp slt i32 result, 0` and
|
||||
* `icmp eq i32 result, 0` against constants directly without
|
||||
* worrying about strcmp implementations that return values outside
|
||||
* {-1, 0, +1}. Heap-Str ABI milestone will replace the body with
|
||||
* length-prefixed comparison without changing the signature. */
|
||||
int ail_str_compare(const char *a, const char *b) {
|
||||
int r = strcmp(a, b);
|
||||
if (r < 0) return -1;
|
||||
if (r > 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user