Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

detectNativeCpuAndFeatures

Public Function
std.zig.system.linux.detectNativeCpuAndFeatures
pub fn detectNativeCpuAndFeatures(io: Io) ?Target.Cpu

Params

File

zig/system/linux.zig:586
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
pub fn detectNativeCpuAndFeatures(io: Io) ?Target.Cpu {
    var file = Io.Dir.openFileAbsolute(io, "/proc/cpuinfo", .{}) catch |err| switch (err) {
        else => return null,
    };
    defer file.close(io);

    var buffer: [4096]u8 = undefined; // "flags" lines can get pretty long.
    var file_reader = file.reader(io, &buffer);

    const current_arch = builtin.cpu.arch;
    return switch (current_arch) {
        .aarch64, .aarch64_be => b: {
            const registers = [12]u64{
                getAArch64CpuFeature("MIDR_EL1"),
                getAArch64CpuFeature("ID_AA64PFR0_EL1"),
                getAArch64CpuFeature("ID_AA64PFR1_EL1"),
                getAArch64CpuFeature("ID_AA64DFR0_EL1"),
                getAArch64CpuFeature("ID_AA64DFR1_EL1"),
                getAArch64CpuFeature("ID_AA64AFR0_EL1"),
                getAArch64CpuFeature("ID_AA64AFR1_EL1"),
                getAArch64CpuFeature("ID_AA64ISAR0_EL1"),
                getAArch64CpuFeature("ID_AA64ISAR1_EL1"),
                getAArch64CpuFeature("ID_AA64MMFR0_EL1"),
                getAArch64CpuFeature("ID_AA64MMFR1_EL1"),
                getAArch64CpuFeature("ID_AA64MMFR2_EL1"),
            };

            break :b @import("arm.zig").aarch64.detectNativeCpuAndFeatures(current_arch, registers);
        },
        .arm, .armeb, .thumb, .thumbeb => ArmCpuinfoParser.parse(current_arch, &file_reader.interface) catch null,
        .powerpc, .powerpcle, .powerpc64, .powerpc64le => PowerpcCpuinfoParser.parse(current_arch, &file_reader.interface) catch null,
        .riscv64, .riscv32 => b: {
            var cpu = (RiscvCpuinfoParser.parse(current_arch, &file_reader.interface) catch null) orelse cpu: {
                const model = Target.Cpu.Model.generic(current_arch);
                break :cpu Target.Cpu{
                    .arch = current_arch,
                    .model = model,
                    .features = model.features,
                };
            };

            riscv.detectCpuFeatures(&cpu);
            cpu.features.populateDependencies(cpu.arch.allFeaturesList());

            break :b cpu;
        },
        .s390x => S390xCpuinfoParser.parse(current_arch, &file_reader.interface) catch null,
        .sparc, .sparc64 => SparcCpuinfoParser.parse(current_arch, &file_reader.interface) catch null,
        else => null,
    };
}