interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / tests / test_cpufeat.c

74 lines · 3396 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/* test_cpufeat.c -- host tests of core/cpufeat.c: every field at its Arm
18 * position, neighbours do not leak, signed FP/AdvSIMD (0xf = absent), line. */
19#include <string.h>
20#include "ck_test.h"
21#include "cpufeat.h"
22
23static struct ck_cpu_features dec(uint64_t a, uint64_t b, uint64_t p)
24{
25 struct ck_cpu_features f;
26 memset(&f, 0xAA, sizeof f);
27 ck_cpufeat_decode(a, b, p, &f);
28 return f;
29}
30
31int main(void)
32{
33 /* Boot record: all zero until kmain records the decode; nothing assumed. */
34 CHECK(!ck_cpufeat_boot()->dotprod && !ck_cpufeat_boot()->i8mm);
35 struct ck_cpu_features f = dec(0, 0, 0);
36 CHECK(!f.dotprod && !f.i8mm && !f.bf16 && !f.fhm && !f.sve && !f.rndr);
37 CHECK(!f.fp16); /* FP=0 AdvSIMD=0: implemented, no half precision */
38
39 f = dec(1ull << 44, 0, 0); CHECK(f.dotprod && !f.fhm && !f.rndr && !f.i8mm);
40 f = dec(1ull << 48, 0, 0); CHECK(f.fhm && !f.dotprod);
41 f = dec(1ull << 60, 0, 0); CHECK(f.rndr && !f.dotprod);
42 f = dec(0, 1ull << 52, 0); CHECK(f.i8mm && !f.bf16);
43 f = dec(0, 1ull << 44, 0); CHECK(f.bf16 && !f.i8mm);
44 f = dec(0, 0, 1ull << 32); CHECK(f.sve);
45 f = dec(0, 0, (1ull << 16) | (1ull << 20)); CHECK(f.fp16);
46 f = dec(0, 0, 1ull << 16); CHECK(!f.fp16); /* FP16 FP without AdvSIMD fp16 */
47 f = dec(0, 0, 0xfull << 16 | 1ull << 20); CHECK(!f.fp16); /* FP=-1: absent */
48 f = dec(0, 0, 0xfull << 20 | 1ull << 16); CHECK(!f.fp16);
49 /* Cortex-A76-like: DP=1 (bit 44), no I8MM, FP16 */
50 f = dec(0x0000100011111110ull, 0x0000000000100001ull, 0x0000000011212222ull | (1ull << 16 | 1ull << 20));
51 CHECK(f.dotprod && !f.i8mm && f.fp16 && !f.sve);
52 /* higher field values still count */
53 f = dec(2ull << 44, 2ull << 52, 0); CHECK(f.dotprod && f.i8mm);
54 /* adjacent fields do not leak: bits just outside each field */
55 f = dec(1ull << 43, (1ull << 51) | (1ull << 56), 1ull << 31 | 1ull << 36);
56 CHECK(!f.dotprod && !f.i8mm && !f.sve);
57 f = dec(1ull << 59 | 1ull << 43 | 1ull << 55, 1ull << 43 | 1ull << 56, 0); CHECK(!f.rndr && !f.fhm && !f.bf16 && !f.dotprod);
58
59 char buf[128];
60 f = dec(1ull << 44, 0, 1ull << 16 | 1ull << 20);
61 int n = ck_cpufeat_format(&f, buf, sizeof buf);
62 CHECK(n > 0 && strcmp(buf, "cpu_features: dotprod=1 i8mm=0 bf16=0 fhm=0 fp16=1 sve=0 rndr=0") == 0);
63 char small[8];
64 ck_cpufeat_format(&f, small, sizeof small);
65 CHECK(strlen(small) == 7);
66 /* The recorded boot decode is what core/infer.c hands the Rust unit. */
67 f = dec(1ull << 44, 0, 0);
68 ck_cpufeat_set_boot(&f);
69 CHECK(ck_cpufeat_boot()->dotprod == 1 && ck_cpufeat_boot()->i8mm == 0);
70 f = dec(0, 0, 0);
71 ck_cpufeat_set_boot(&f);
72 CHECK(ck_cpufeat_boot()->dotprod == 0);
73 return ck_t_verdict("test_cpufeat");
74}