Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/core/cpufeat.c # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / core / cpufeat.c` 63 lines ยท 2257 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* cpufeat.c -- see cpufeat.h for the register field positions. */ 18 #include "cpufeat.h" 19 #include "fmt.h" 20 21 static unsigned ufield(uint64_t v, unsigned hi, unsigned lo) 22 { 23 return (unsigned)((v >> lo) & ((1u << (hi - lo + 1u)) - 1u)); 24 } 25 26 /* Signed 4-bit field: 0b1000..0b1111 are negative (0xf = -1 = not implemented). */ 27 static int sfield(uint64_t v, unsigned hi, unsigned lo) 28 { 29 int x = (int)ufield(v, hi, lo); 30 return x >= 8 ? x - 16 : x; 31 } 32 33 void ck_cpufeat_decode(uint64_t isar0, uint64_t isar1, uint64_t pfr0, struct ck_cpu_features *out) 34 { 35 out->dotprod = ufield(isar0, 47, 44) >= 1u; 36 out->fhm = ufield(isar0, 51, 48) >= 1u; 37 out->rndr = ufield(isar0, 63, 60) >= 1u; 38 out->i8mm = ufield(isar1, 55, 52) >= 1u; 39 out->bf16 = ufield(isar1, 47, 44) >= 1u; 40 out->sve = ufield(pfr0, 35, 32) >= 1u; 41 out->fp16 = sfield(pfr0, 19, 16) >= 1 && sfield(pfr0, 23, 20) >= 1; 42 } 43 44 int ck_cpufeat_format(const struct ck_cpu_features *f, char *buf, size_t n) 45 { 46 return ck_snprintf(buf, n, "cpu_features: dotprod=%u i8mm=%u bf16=%u fhm=%u fp16=%u sve=%u rndr=%u", f->dotprod, 47 f->i8mm, f->bf16, f->fhm, f->fp16, f->sve, f->rndr); 48 } 49 50 /* The boot core's decode, kept for consumers that select code by feature 51 * (core/infer.c passes dotprod to the Rust inference unit). All zero until 52 * kmain records it, so nothing is ever assumed present. */ 53 static struct ck_cpu_features g_boot_features; 54 55 void ck_cpufeat_set_boot(const struct ck_cpu_features *f) 56 { 57 g_boot_features = *f; 58 } 59 60 const struct ck_cpu_features *ck_cpufeat_boot(void) 61 { 62 return &g_boot_features; 63 }