Skip to content

Instantly share code, notes, and snippets.

@xypron
Created February 4, 2024 10:42
Show Gist options
  • Save xypron/b1c10073a321b2ca9afa433215ab74b6 to your computer and use it in GitHub Desktop.
Save xypron/b1c10073a321b2ca9afa433215ab74b6 to your computer and use it in GitHub Desktop.
Detect Zba, Zbc extensions
// SPDX-License-Identifier: 0BSD
#include <stdio.h>
int test_sh1add(void) {
long x = -1L;
__asm__ volatile (
"mv a0, zero\n"
"li t1, 0x30\n"
"li t2, 5\n"
// "sh1add a0, t1, t2\n"
".word 0x20732533\n"
"mv %0, a0\n"
: "=r" ( x ) );
return x == 0x65;
}
int test_ctz(void) {
long x = -1L;
__asm__ volatile (
"mv a0, zero\n"
"li t1, 0x100\n"
// "ctz a0, t1\n"
".word 0x60131513\n"
"mv %0, a0\n"
: "=r" ( x ) );
return x == 0x8;
}
int main()
{
printf("Zba sh1add is %ssupported\n", test_sh1add() ? "" : "not " );
printf("Zbb ctz is %ssupported\n", test_ctz() ? "" : "not " );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment