Where I can find Computerarchitecture in source files

Where can I find the places in the source files that I need to adjust for my PC? This is a rust program. Compiling the previous version works. The exe file works. I use a PC with the ARCH=x86-64.

Where can I find the places in the source files that I need to adjust for my older PC?

This seems like a strange question. Can you explain why you think something needs adjusting?

I have already compiled some programs under MSVS as well as under the console using GCC, Clang etc, and also with Rust under Windows and Linux.

The supplied Exe files don't work for me because my old PC only has SSE, SSE2, SSE3, SSE4A and therefore I have to adapt it.

You've a Rust program that invokes machine code (object files), is that it?

Yes

The definitions of what gets passed to LLVM to select a CPU architecture are in files like https://github.com/rust-lang/rust/blob/stable/compiler/rustc_target/src/spec/x86_64_pc_windows_msvc.rs. Unlike on 32-bit architectures, there’s not so much variation between target CPUs on 64-bit, though the macOS definition is more complex.

That’s all a bit complicated, though. Do you just want to pass target-cpu=native or something like that?

RUSTFLAGS="-C target-cpu=native" cargo build --release

yes

vailable CPUs for this target:
native - Select the CPU of the current host (currently amdfam10).
alderlake
amdfam10
athlon
athlon-4
athlon-fx
athlon-mp
athlon-tbird
athlon-xp
athlon64
athlon64-sse3
atom
barcelona
bdver1
bdver2
bdver3
bdver4
bonnell
broadwell
btver1
btver2
c3
c3-2
cannonlake
cascadelake
cooperlake
core-avx-i
core-avx2
core2
corei7
corei7-avx
emeraldrapids
generic
geode
goldmont
goldmont-plus
grandridge
graniterapids
haswell
i386
i486
i586
i686
icelake-client
icelake-server
ivybridge
k6
k6-2
k6-3
k8
k8-sse3
knl
knm
lakemont
meteorlake
nehalem
nocona
opteron
opteron-sse3
penryn
pentium
pentium-m
pentium-mmx
pentium2
pentium3
pentium3m
pentium4
pentium4m
pentiumpro
prescott
raptorlake
rocketlake
sandybridge
sapphirerapids
sierraforest
silvermont
skx
skylake
skylake-avx512
slm
tigerlake
tremont
westmere
winchip-c6
winchip2
x86-64 - This is the default target CPU for the current build target (currently x86_64-pc-windows-msvc).
x86-64-v2
x86-64-v3
x86-64-v4
yonah
znver1
znver2
znver3
znver4

I see under config.toml this:

[build]
rustflags = ["-Ctarget-cpu=native", "-Cinline-threshold=500"]

Is this the right position?

With -Ctarget-cpu=native, it will be optimized for the CPU where you're running the compiler, and that may include using new CPU instructions. If you're going to run on a different machine, you may need to choose an older corresponding target, or just remove that option and run with the default.

That looks right, with config.toml in a .cargo directory.

I would prefer to use a specific target to avoid more confusion when I forget what I’ve done in a few months:

[target.x86_64-pc-windows-gnu]
rustflags = ["-C", "target-cpu=core2"]

When I do that, I can see that it’s used with rustc when running cargo --verbose.

With:
[build]
rustflags = [ "-C", "target-cpu=core2", "-Cinline-threshold=500"]

and:
cargo --verbose build --release

I get these errors:

 Running `C:\Users\Privat\Desktop\velvet-chess-5.2.1\velvet-chess-5.2.1\target\release\build\generic-array-ac54937ef237f6e7\build-script-build`

Compiling quote v1.0.23
Running rustc --crate-name build_script_build --edition=2018 C:\Users\Privat\.cargo\registry\src\index.crates.io-6f17d22bba15001f\quote-1.0.23\build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=156 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg "feature=\"default\"" --cfg "feature=\"proc-macro\"" -C metadata=231b0a5b524fea22 -C extra-filename=-231b0a5b524fea22 --out-dir C:\Users\Privat\Desktop\velvet-chess-5.2.1\velvet-chess-5.2.1\target\release\build\quote-231b0a5b524fea22 -L dependency=C:\Users\Privat\Desktop\velvet-chess-5.2.1\velvet-chess-5.2.1\target\release\deps --cap-lints allow -C target-cpu=core2 -Cinline-threshold=500
error: failed to run custom build command for proc-macro2 v1.0.49

Caused by:
process didn't exit successfully: C:\Users\Privat\Desktop\velvet-chess-5.2.1\velvet-chess-5.2.1\target\release\build\proc-macro2-3554e81a17608834\build-script-build (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
--- stdout
cargo:rerun-if-changed=build.rs
warning: build failed, waiting for other jobs to finish...

sorry, this was the wrong version of velvet

Here the right version of the compiled, the *exe file ist created, but not working

Velvet Chess Engine v5.3.0
uci
id name Velvet v5.3.0
id author Martin Honert
option name Clear Hash type button
option name Hash type spin default 32 min 1 max 262144
option name MultiPV type spin default 1 min 1 max 218
option name Ponder type check default false
option name SyzygyPath type string default
option name SyzygyProbeDepth type spin default 0 min 0 max 127
option name Threads type spin default 1 min 1 max 256
option name UCI_Chess960 type check default false
option name UCI_EngineAbout type string default Velvet Chess Engine (GitHub - mhonert/velvet-chess: ♟ Velvet Chess Engine - written in Rust)
uciok

If i say go, then the console is closed.

here the other old version output:

Velvet Chess Engine v5.2.1
uci
id name Velvet v5.2.1
id author Martin Honert
option name Clear Hash type button
option name Hash type spin default 32 min 1 max 262144
option name MultiPV type spin default 1 min 1 max 218
option name Ponder type check default false
option name SyzygyPath type string default
option name SyzygyProbeDepth type spin default 0 min 0 max 127
option name Threads type spin default 1 min 1 max 256
option name UCI_Chess960 type check default false
option name UCI_EngineAbout type string default Velvet Chess Engine (GitHub - mhonert/velvet-chess: ♟ Velvet Chess Engine - written in Rust)
uciok
go depht 5
info depth 1 seldepth 1 multipv 1 score cp 22 nodes 20 nps 181818 tbhits 0 hashfull 0 time 0 pv d2d4
info depth 2 seldepth 4 multipv 1 score cp 17 nodes 136 nps 3057 tbhits 0 hashfull 0 time 44 pv e2e4 e7e5
info depth 3 seldepth 5 multipv 1 score cp 18 nodes 685 nps 2232 tbhits 0 hashfull 0 time

This output is ok!

 Running `C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0\target\release\build\quote-c7e162360d371299\build-script-build`

Compiling zstd-sys v2.0.8+zstd.1.5.5
Running rustc --crate-name build_script_build --edition=2018 C:\Users\Privat\.cargo\registry\src\index.crates.io-6f17d22bba15001f\zstd-sys-2.0.8+zstd.1.5.5\build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=156 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debug-assertions=off --cfg "feature=\"legacy\"" --cfg "feature=\"std\"" --cfg "feature=\"zdict_builder\"" -C metadata=68f5a0e343163e9f -C extra-filename=-68f5a0e343163e9f --out-dir C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0\target\release\build\zstd-sys-68f5a0e343163e9f -L dependency=C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0\target\release\deps --extern cc=C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0\target\release\deps\libcc-e065c6dc17dffad3.rlib --extern pkg_config=C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0\target\release\deps\libpkg_config-138ddf24956e50c9.rlib --cap-lints allow -C target-cpu=core2 -Cinline-threshold=500
error: failed to run custom build command for proc-macro2 v1.0.65

Caused by:
process didn't exit successfully: C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0\target\release\build\proc-macro2-5c30343c4d453867\build-script-build (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
--- stdout
cargo:rerun-if-changed=build.rs
warning: build failed, waiting for other jobs to finish...

C:\Users\Privat\Desktop\velvet-chess-5.3.0\velvet-chess-5.3.0>

core2 is just a fairly old processor that I tried; if Rust itself is generating the wrong code, then something much older like athlon might work better. Unfortunately I have a Ryzen 7 so I can’t easily test if that’s the problem.

As another way to solve this kind of problem, I might see whether I could use 32-bit Rust to compile a 32-bit executable. It could end up being more compatible.

From what I understand an ud2 instruction could trigger the same error. Could this be UB that is only visible when compiling for an older target?

1 Like

Rust on Windows will use an illegal instruction with panic=abort set (in cargo.toml generally) - is there any chance that's set and there's some other panic happening on the older computer?

It could be that std itself is compiled against a newer instruction set, but I can't imagine anything too interesting happening there if you're on x86-64.

1 Like

I learned that a compiler converts a program programmed in a high-level language into an executable program for the corresponding hardware. So I see it as a bug in rust.

Note:

Tomorrow I have the opportunity to test my program on a newer PC to see if it works there.

On Windows 8 and later it will use the __fastfail mechanism instead:

And even then there should be a panic message.

1 Like