| ... | ... | @@ -3396,88 +3396,8 @@ test "fds" { |
| 3396 | 3396 | gimmeMoreOfThoseSweetSweetFileDescriptors(); |
| 3397 | 3397 | } |
| 3398 | 3398 | |
| 3399 | | fn detectNativeCpuWithLLVM( |
| 3400 | | arch: std.Target.Cpu.Arch, |
| 3401 | | llvm_cpu_name_z: ?[*:0]const u8, |
| 3402 | | llvm_cpu_features_opt: ?[*:0]const u8, |
| 3403 | | ) !std.Target.Cpu { |
| 3404 | | var result = std.Target.Cpu.baseline(arch); |
| 3405 | | |
| 3406 | | if (llvm_cpu_name_z) |cpu_name_z| { |
| 3407 | | const llvm_cpu_name = mem.spanZ(cpu_name_z); |
| 3408 | | |
| 3409 | | for (arch.allCpuModels()) |model| { |
| 3410 | | const this_llvm_name = model.llvm_name orelse continue; |
| 3411 | | if (mem.eql(u8, this_llvm_name, llvm_cpu_name)) { |
| 3412 | | // Here we use the non-dependencies-populated set, |
| 3413 | | // so that subtracting features later in this function |
| 3414 | | // affect the prepopulated set. |
| 3415 | | result = std.Target.Cpu{ |
| 3416 | | .arch = arch, |
| 3417 | | .model = model, |
| 3418 | | .features = model.features, |
| 3419 | | }; |
| 3420 | | break; |
| 3421 | | } |
| 3422 | | } |
| 3423 | | } |
| 3424 | | |
| 3425 | | const all_features = arch.allFeaturesList(); |
| 3426 | | |
| 3427 | | if (llvm_cpu_features_opt) |llvm_cpu_features| { |
| 3428 | | var it = mem.tokenize(mem.spanZ(llvm_cpu_features), ","); |
| 3429 | | while (it.next()) |decorated_llvm_feat| { |
| 3430 | | var op: enum { |
| 3431 | | add, |
| 3432 | | sub, |
| 3433 | | } = undefined; |
| 3434 | | var llvm_feat: []const u8 = undefined; |
| 3435 | | if (mem.startsWith(u8, decorated_llvm_feat, "+")) { |
| 3436 | | op = .add; |
| 3437 | | llvm_feat = decorated_llvm_feat[1..]; |
| 3438 | | } else if (mem.startsWith(u8, decorated_llvm_feat, "-")) { |
| 3439 | | op = .sub; |
| 3440 | | llvm_feat = decorated_llvm_feat[1..]; |
| 3441 | | } else { |
| 3442 | | return error.InvalidLlvmCpuFeaturesFormat; |
| 3443 | | } |
| 3444 | | for (all_features) |feature, index_usize| { |
| 3445 | | const this_llvm_name = feature.llvm_name orelse continue; |
| 3446 | | if (mem.eql(u8, llvm_feat, this_llvm_name)) { |
| 3447 | | const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize); |
| 3448 | | switch (op) { |
| 3449 | | .add => result.features.addFeature(index), |
| 3450 | | .sub => result.features.removeFeature(index), |
| 3451 | | } |
| 3452 | | break; |
| 3453 | | } |
| 3454 | | } |
| 3455 | | } |
| 3456 | | } |
| 3457 | | |
| 3458 | | result.features.populateDependencies(all_features); |
| 3459 | | return result; |
| 3460 | | } |
| 3461 | | |
| 3462 | 3399 | fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !std.zig.system.NativeTargetInfo { |
| 3463 | | var info = try std.zig.system.NativeTargetInfo.detect(gpa, cross_target); |
| 3464 | | if (info.cpu_detection_unimplemented) { |
| 3465 | | const arch = std.Target.current.cpu.arch; |
| 3466 | | |
| 3467 | | // We want to just use detected_info.target but implementing |
| 3468 | | // CPU model & feature detection is todo so here we rely on LLVM. |
| 3469 | | // https://github.com/ziglang/zig/issues/4591 |
| 3470 | | if (!build_options.have_llvm) |
| 3471 | | fatal("CPU features detection is not yet available for {s} without LLVM extensions", .{@tagName(arch)}); |
| 3472 | | |
| 3473 | | const llvm = @import("codegen/llvm/bindings.zig"); |
| 3474 | | const llvm_cpu_name = llvm.GetHostCPUName(); |
| 3475 | | const llvm_cpu_features = llvm.GetNativeFeatures(); |
| 3476 | | info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features); |
| 3477 | | cross_target.updateCpuFeatures(&info.target.cpu.features); |
| 3478 | | info.target.cpu.arch = cross_target.getCpuArch(); |
| 3479 | | } |
| 3480 | | return info; |
| 3400 | return std.zig.system.NativeTargetInfo.detect(gpa, cross_target); |
| 3481 | 3401 | } |
| 3482 | 3402 | |
| 3483 | 3403 | /// Indicate that we are now terminating with a successful exit code. |