fmt c test code

This commit is contained in:
Urjasvi Suthar
2026-07-14 10:37:20 +05:30
parent b27f28d1ea
commit 65591fad4e

View File

@@ -1,26 +1,26 @@
#include <stdint.h>
#include <stdbool.h>
#include <stdbool.h>
// Clang compiles this to a single 32-bit register comparison:
// cmp w0, #-1
// If the caller failed to sign-extend the 8-bit -1 (0xFF) to 32-bit (0xFFFFFFFF),
// the comparison fails.
bool test_i8(int8_t val) {
return val == -1;
}
// Clang compiles this to a single 32-bit register comparison:
// cmp w0, #-1
// If the caller failed to sign-extend the 8-bit -1 (0xFF) to 32-bit (0xFFFFFFFF),
// the comparison fails.
bool test_i8(int8_t val) {
return val == -1;
}
// Clang compiles this to:
// cmp w0, #200
// If the caller did not zero-extend 200 (0xC8) to 32-bit, leaving garbage
// in the upper bits of w0, this comparison fails.
bool test_u8(uint8_t val) {
return val == 200;
}
// Clang compiles this to:
// cmp w0, #200
// If the caller did not zero-extend 200 (0xC8) to 32-bit, leaving garbage
// in the upper bits of w0, this comparison fails.
bool test_u8(uint8_t val) {
return val == 200;
}
// Clang compiles this to:
// cmp w0, #1
// If the caller did not zero-extend the boolean true (1) to 32-bit,
// leaving garbage in the upper bits of w0, this comparison fails.
bool test_bool(bool val) {
return val == true;
}
// Clang compiles this to:
// cmp w0, #1
// If the caller did not zero-extend the boolean true (1) to 32-bit,
// leaving garbage in the upper bits of w0, this comparison fails.
bool test_bool(bool val) {
return val == true;
}