diff --git a/nac3standalone/demo/linalg/Cargo.lock b/nac3standalone/demo/linalg/Cargo.lock index a3385eac..fedc8fae 100644 --- a/nac3standalone/demo/linalg/Cargo.lock +++ b/nac3standalone/demo/linalg/Cargo.lock @@ -17,12 +17,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" -[[package]] -name = "cslice" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a" - [[package]] name = "libm" version = "0.2.8" @@ -33,7 +27,6 @@ checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" name = "linalg" version = "0.1.0" dependencies = [ - "cslice", "nalgebra", ] diff --git a/nac3standalone/demo/linalg/Cargo.toml b/nac3standalone/demo/linalg/Cargo.toml index 923faae5..d3ce20fb 100644 --- a/nac3standalone/demo/linalg/Cargo.toml +++ b/nac3standalone/demo/linalg/Cargo.toml @@ -8,6 +8,12 @@ crate-type = ["staticlib"] [dependencies] nalgebra = {version = "0.32.6", default-features = false, features = ["libm", "alloc"]} -cslice = "0.3.0" +#cslice = "0.3.0" + +#[dependencies.nalgebra] +#git = "https://git.m-labs.hk/M-labs/nalgebra.git" +#rev = "dd00f9b" +#default-features = false +#features = ["libm", "alloc"] [workspace] diff --git a/nac3standalone/demo/linalg/cross_shell.nix b/nac3standalone/demo/linalg/cross_shell.nix new file mode 100644 index 00000000..7b1bf2a1 --- /dev/null +++ b/nac3standalone/demo/linalg/cross_shell.nix @@ -0,0 +1,11 @@ +# cross-shell.nix +{ pkgs ? import {} }: + +pkgs.mkShell { + nativeBuildInputs = [ + pkgs.binutils + pkgs.gcc + pkgs.rustc.override { targets = ["i686-unknown-linux-gnu"]; } + pkgs.cargo.override { targets = ["i686-unknown-linux-gnu"]; } + ]; +} \ No newline at end of file diff --git a/nac3standalone/demo/linalg/default.nix b/nac3standalone/demo/linalg/default.nix new file mode 100644 index 00000000..510a6c66 --- /dev/null +++ b/nac3standalone/demo/linalg/default.nix @@ -0,0 +1,49 @@ +{ pkgs ? import {} }: + +let + fenix = import (fetchTarball "https://github.com/nix-community/fenix/archive/main.tar.gz") { + system = "x86_64-linux"; + }; + + targets = ["i686-unknown-linux-gnu" "x86_64-unknown-linux-gnu"]; + + fenixToolchain = fenix.stable.toolchain.overrideAttrs (old: { + inherit targets; + }); + +in +pkgs.rustPlatform.buildRustPackage { + name = "my-crate"; + src = ./.; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + nativeBuildInputs = with fenixToolchain; [ + rust + ] ++ (builtins.concatLists ( + map (target: [ + (rust.override { inherit targets; }) + ]) targets + )); + + buildAndTestSubdir = "."; + + buildPhase = '' + ${builtins.concatStringsSep "\n" (map (target: + '' + cargo build --release --target ${target} --locked + '' + ) targets)} + ''; + + installPhase = '' + mkdir -p $out/lib + ${builtins.concatStringsSep "\n" (map (target: + '' + cp target/${target}/release/libmy_crate.a $out/lib/libmy_crate-${target}.a + '' + ) targets)} + ''; +} \ No newline at end of file diff --git a/nac3standalone/demo/linalg/i686-unknown-linux-gnu.json b/nac3standalone/demo/linalg/i686-unknown-linux-gnu.json new file mode 100644 index 00000000..84adf9e2 --- /dev/null +++ b/nac3standalone/demo/linalg/i686-unknown-linux-gnu.json @@ -0,0 +1,21 @@ +{ + "llvm-target": "i686-unknown-none", + "data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128", + "arch": "x86", + "target-endian": "little", + "target-pointer-width": "32", + "target-c-int-width": "32", + "os": "none", + "executables": true, + "linker-flavor": "ld.lld", + "linker": "rust-lld", + "panic-strategy": "abort", + "disable-redzone": true, + "pre-link-args": { + "ld.lld": [ + "--script=linker.ld", + "--Map=target/linker.map" + ] + }, + "features": "-mmx,-sse,+soft-float" +} \ No newline at end of file diff --git a/nac3standalone/demo/linalg/linker.ld b/nac3standalone/demo/linalg/linker.ld new file mode 100644 index 00000000..313e487c --- /dev/null +++ b/nac3standalone/demo/linalg/linker.ld @@ -0,0 +1,58 @@ +ENTRY(_start_bootloader) + +SECTIONS { + . = 0x4000; + . = ALIGN(0x1000); + __smp_trampoline_start = .; + .smp_trampoline : + { + *(.smp_trampoline) + } + . = ALIGN(0x1000); + __smp_trampoline_end = .; + . = 1M; + + __bootloader_start = .; + .boot : ALIGN(2) + { + /* ensure that the multiboot header is at the beginning */ + KEEP(*(.multiboot_header)) + } + .bootloader : ALIGN(16) + { + *(.init_bootloader) + *(.text .text.*) + *(.rodata .rodata.*) + *(.data .data.*) + *(.bss .bss.*) + *(.got .got.*) + } + . = ALIGN(0x1000); + __bootloader_end = .; + + . = 2M; + __kernel_start = .; + .kernel : + { + KEEP(*(.kernel)) + } + . = ALIGN(0x1000); + __kernel_end = .; + + . = ALIGN(0x1000); + __page_table_start = .; + _p4 = .; + . += 0x1000; + _p3 = .; + . += 0x1000; + _p2_tables_start = .; + . += 0x4000; /* One p2 table equals 1Gb memory mapped */ + _p2_tables_end = .; + _p1_tables_start = .; + . += 0x1000; /* First p1 table to map 0-2Mb with 4Kb pages*/ + _p1_tss_tables_start = .; + . += 0x1000 * 128; /* 1Mb per core for interrupt stacks (max 256 cores) */ + _p1_tables_end = .; + __page_table_end = .; + __minimum_mem_requirement = .; +} \ No newline at end of file diff --git a/nac3standalone/demo/linalg/rust_lib/libaddr2line-6f8f7a9f9ab02f1e.rlib b/nac3standalone/demo/linalg/rust_lib/libaddr2line-6f8f7a9f9ab02f1e.rlib new file mode 100644 index 00000000..85749dc9 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libaddr2line-6f8f7a9f9ab02f1e.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libadler-03ad1dd3e47d9f69.rlib b/nac3standalone/demo/linalg/rust_lib/libadler-03ad1dd3e47d9f69.rlib new file mode 100644 index 00000000..850081ff Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libadler-03ad1dd3e47d9f69.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/liballoc-a7a7285145d6a429.rlib b/nac3standalone/demo/linalg/rust_lib/liballoc-a7a7285145d6a429.rlib new file mode 100644 index 00000000..5190d2b7 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/liballoc-a7a7285145d6a429.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libcfg_if-0ed54c1e24976f7b.rlib b/nac3standalone/demo/linalg/rust_lib/libcfg_if-0ed54c1e24976f7b.rlib new file mode 100644 index 00000000..d6f07e66 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libcfg_if-0ed54c1e24976f7b.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libcompiler_builtins-2bfd79c9f4a0f5d6.rlib b/nac3standalone/demo/linalg/rust_lib/libcompiler_builtins-2bfd79c9f4a0f5d6.rlib new file mode 100644 index 00000000..ff6d0bb6 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libcompiler_builtins-2bfd79c9f4a0f5d6.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libcore-d38b1ca52d3ead2b.rlib b/nac3standalone/demo/linalg/rust_lib/libcore-d38b1ca52d3ead2b.rlib new file mode 100644 index 00000000..c2ea64dc Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libcore-d38b1ca52d3ead2b.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libgetopts-aca44b4e81ca3ce9.rlib b/nac3standalone/demo/linalg/rust_lib/libgetopts-aca44b4e81ca3ce9.rlib new file mode 100644 index 00000000..d80c4412 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libgetopts-aca44b4e81ca3ce9.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libgimli-5e813e40280a6e57.rlib b/nac3standalone/demo/linalg/rust_lib/libgimli-5e813e40280a6e57.rlib new file mode 100644 index 00000000..f6294232 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libgimli-5e813e40280a6e57.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libhashbrown-f45e81b3e39d4909.rlib b/nac3standalone/demo/linalg/rust_lib/libhashbrown-f45e81b3e39d4909.rlib new file mode 100644 index 00000000..2ac829ba Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libhashbrown-f45e81b3e39d4909.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/liblibc-4206257746d7225c.rlib b/nac3standalone/demo/linalg/rust_lib/liblibc-4206257746d7225c.rlib new file mode 100644 index 00000000..6d1a97e5 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/liblibc-4206257746d7225c.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libmemchr-205cb0f2bde30f31.rlib b/nac3standalone/demo/linalg/rust_lib/libmemchr-205cb0f2bde30f31.rlib new file mode 100644 index 00000000..8bafd34e Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libmemchr-205cb0f2bde30f31.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libminiz_oxide-0bd048d5ce2aedf3.rlib b/nac3standalone/demo/linalg/rust_lib/libminiz_oxide-0bd048d5ce2aedf3.rlib new file mode 100644 index 00000000..7439c5c4 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libminiz_oxide-0bd048d5ce2aedf3.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libobject-14136f920723a212.rlib b/nac3standalone/demo/linalg/rust_lib/libobject-14136f920723a212.rlib new file mode 100644 index 00000000..adb5c5bd Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libobject-14136f920723a212.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libpanic_abort-e44486ce2b2a3289.rlib b/nac3standalone/demo/linalg/rust_lib/libpanic_abort-e44486ce2b2a3289.rlib new file mode 100644 index 00000000..02683518 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libpanic_abort-e44486ce2b2a3289.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libpanic_unwind-59cde83867be4981.rlib b/nac3standalone/demo/linalg/rust_lib/libpanic_unwind-59cde83867be4981.rlib new file mode 100644 index 00000000..ed17a86f Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libpanic_unwind-59cde83867be4981.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libproc_macro-8d05ffefb01cb870.rlib b/nac3standalone/demo/linalg/rust_lib/libproc_macro-8d05ffefb01cb870.rlib new file mode 100644 index 00000000..a595cb57 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libproc_macro-8d05ffefb01cb870.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libprofiler_builtins-9ecd2a12b192104a.rlib b/nac3standalone/demo/linalg/rust_lib/libprofiler_builtins-9ecd2a12b192104a.rlib new file mode 100644 index 00000000..d163cd6d Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libprofiler_builtins-9ecd2a12b192104a.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/librustc_demangle-98cb7cf4d5d97220.rlib b/nac3standalone/demo/linalg/rust_lib/librustc_demangle-98cb7cf4d5d97220.rlib new file mode 100644 index 00000000..02a3d734 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/librustc_demangle-98cb7cf4d5d97220.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_alloc-110e7e81a6b29c12.rlib b/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_alloc-110e7e81a6b29c12.rlib new file mode 100644 index 00000000..eb4a98ee Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_alloc-110e7e81a6b29c12.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_core-61e2c238f54a9f38.rlib b/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_core-61e2c238f54a9f38.rlib new file mode 100644 index 00000000..e76bae1f Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_core-61e2c238f54a9f38.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_std-5f54ff71f8cdbccf.rlib b/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_std-5f54ff71f8cdbccf.rlib new file mode 100644 index 00000000..02a771fd Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/librustc_std_workspace_std-5f54ff71f8cdbccf.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libstd-2b6165f6a223dabf.rlib b/nac3standalone/demo/linalg/rust_lib/libstd-2b6165f6a223dabf.rlib new file mode 100644 index 00000000..baf9cbf4 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libstd-2b6165f6a223dabf.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libstd-2b6165f6a223dabf.so b/nac3standalone/demo/linalg/rust_lib/libstd-2b6165f6a223dabf.so new file mode 100644 index 00000000..599683b4 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libstd-2b6165f6a223dabf.so differ diff --git a/nac3standalone/demo/linalg/rust_lib/libstd_detect-10ae6a79a91a271c.rlib b/nac3standalone/demo/linalg/rust_lib/libstd_detect-10ae6a79a91a271c.rlib new file mode 100644 index 00000000..2f629dee Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libstd_detect-10ae6a79a91a271c.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libsysroot-ad8d51246b9976e2.rlib b/nac3standalone/demo/linalg/rust_lib/libsysroot-ad8d51246b9976e2.rlib new file mode 100644 index 00000000..7b31e371 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libsysroot-ad8d51246b9976e2.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libtest-57e6f35ee807af13.rlib b/nac3standalone/demo/linalg/rust_lib/libtest-57e6f35ee807af13.rlib new file mode 100644 index 00000000..9bdacc02 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libtest-57e6f35ee807af13.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libunicode_width-9500bd91969ccf4b.rlib b/nac3standalone/demo/linalg/rust_lib/libunicode_width-9500bd91969ccf4b.rlib new file mode 100644 index 00000000..98d90adb Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libunicode_width-9500bd91969ccf4b.rlib differ diff --git a/nac3standalone/demo/linalg/rust_lib/libunwind-82ae2167b3602b33.rlib b/nac3standalone/demo/linalg/rust_lib/libunwind-82ae2167b3602b33.rlib new file mode 100644 index 00000000..d13128e3 Binary files /dev/null and b/nac3standalone/demo/linalg/rust_lib/libunwind-82ae2167b3602b33.rlib differ diff --git a/nac3standalone/demo/linalg/src/lib.rs b/nac3standalone/demo/linalg/src/lib.rs index c671e0b7..f7d34b3d 100644 --- a/nac3standalone/demo/linalg/src/lib.rs +++ b/nac3standalone/demo/linalg/src/lib.rs @@ -4,8 +4,9 @@ // * Both `nalgebra::Matrix` and `NDArray` require their content to be stored in row-major order // * `NDArray` data pointer can be directly read and converted to `nalgebra::Matrix` (row and column number must be known) // * `nalgebra::Matrix::as_slice` returns the content of matrix in column-major order and initial data needs to be transposed before storing it in `NDArray` data pointer +extern crate core; -use core::slice; +use std::slice; use nalgebra::DMatrix; fn report_error( @@ -19,7 +20,7 @@ fn report_error( panic!( "Exception {} from {} in {}:{}:{}, message: {}", error_name, fn_name, file_name, line_num, col_num, err_msg - ); + ) } pub struct InputMatrix { @@ -247,7 +248,10 @@ pub unsafe extern "C" fn np_linalg_matrix_power( let out_slice = unsafe { slice::from_raw_parts_mut(out.data, outdim[0] * outdim[1]) }; let data_slice1 = unsafe { slice::from_raw_parts_mut(mat1.data, dim1[0] * dim1[1]) }; - let abs_pow = power.abs(); + let mut abs_pow = power; + if abs_pow < 0.0 { + abs_pow = abs_pow * -1.0; + } let matrix1 = DMatrix::from_row_slice(dim1[0], dim1[1], data_slice1); let mut result = matrix1.pow(abs_pow as u32);