Skip to content

Support 128-bit integers on platforms without native support #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b092e8d
Use sized integer types
antoyo Oct 19, 2021
d4c3c87
WIP: add support for integer types not supported on some platforms
antoyo Oct 22, 2021
763ad8c
Implement integer cast for unsupported integer types
antoyo Oct 24, 2021
c221198
Add support for non native integer types in some operations
antoyo Oct 25, 2021
e2f4a47
Fix shifts in order to make the addition work
antoyo Nov 14, 2021
6964415
Fix endianness in shift operations
antoyo Nov 14, 2021
d15c42b
Add dump to file
antoyo Nov 20, 2021
67bc1c8
WIP: fix shift by 64 bits
antoyo Dec 11, 2021
b1fb5d9
Fix shift and addition
antoyo Dec 20, 2021
897f230
Continue tests
antoyo Dec 21, 2021
70451ef
Fix left shift and subtraction
antoyo Dec 24, 2021
b95b70e
Fix multiplication
antoyo Dec 24, 2021
c138440
Add tests for division
antoyo Dec 24, 2021
ea301ac
Non-native integers: Add support for some float casts, count trailing…
antoyo Dec 25, 2021
5ca3898
Fix count leading zeroes
antoyo Dec 27, 2021
7046a05
Implement and fix many operations on non-native integers
antoyo Dec 27, 2021
27f4e9b
Fix left shift by more than 64 bits
antoyo Dec 29, 2021
231db46
Add feature to test non-native integers in CI
antoyo Dec 30, 2021
51284e1
Checkout compiler-rt in CI
antoyo Dec 30, 2021
b65aefe
Fix scope of env var
antoyo Dec 30, 2021
210e5f0
Check if 128-bit integers are supported
antoyo Dec 30, 2021
6c50303
Make many new operations work on non-native integers
antoyo Dec 31, 2021
c52bee8
Cleanup
antoyo Dec 31, 2021
e8d4442
Fix artifact download
antoyo Dec 31, 2021
fa1666f
Use correct filename for libgccjit
antoyo Dec 31, 2021
0970216
Temporarily disable int test
antoyo Dec 31, 2021
2cd2d6c
Test CI
antoyo Jan 1, 2022
3319202
Fix to not require more files than libgccjit.so
antoyo Jan 1, 2022
8f8cbae
Re-enable tests
antoyo Jan 1, 2022
162a2d7
Fix wrong cast
antoyo Jan 1, 2022
9114139
Add more debugging options
antoyo Jan 2, 2022
5123742
Add cli argument to test.sh
antoyo Jan 6, 2022
9786cfe
Cleanup before fixing right shift
antoyo Jan 6, 2022
54dbc74
Start fixing right shift for value more than 64 and fix mask used to …
antoyo Jan 6, 2022
5027748
Fix right shift of values more than 64
antoyo Jan 6, 2022
55bcf84
Handle the sign in a few operations of non-native integers
antoyo Jan 7, 2022
430afbd
Use git gccjit
antoyo Jan 7, 2022
6ccf923
Fix left shift by 0
antoyo Jan 8, 2022
b14f331
Fix type used by non-native i128 to differentiate from u128
antoyo Jan 9, 2022
d6afddd
Fix saturating sub
antoyo Jan 9, 2022
b6a5378
Fix logical shift by casting to unsigned type
antoyo Jan 9, 2022
2c869df
Hide stderr log to not show an error when 128-bit integers are not su…
antoyo Jan 9, 2022
43efb6a
Fix to keep the sign in right shifts
antoyo Jan 11, 2022
66cd8e4
Fix bswap and some casts for 128-bit integers
antoyo Jan 11, 2022
cc295a6
Fix comment
antoyo Jan 13, 2022
6436092
Switch to the new set_print_errors_to_stderr API
antoyo Jan 25, 2022
9f0d167
Simplify gcc_and and gcc_or
antoyo Jan 27, 2022
5659f14
Simplify gcc_int_cast
antoyo Jan 27, 2022
60d78c4
Refactor int division, simplify xor and and integer creation
antoyo Jan 28, 2022
bdeaab5
Simplify big integer creation, zero creation, integer cast, float to …
antoyo Jan 29, 2022
00c79e7
Refactor bitwise operations
antoyo Jan 29, 2022
6231747
Refactor rem and div
antoyo Jan 29, 2022
f14550b
Simplify not, stop handling non-native 64-bit types
antoyo Jan 29, 2022
d783dff
Refaction add, sub and mul
antoyo Jan 29, 2022
c6d97ff
Refactor icmp
antoyo Jan 29, 2022
8d37286
Simplify shifts
antoyo Jan 30, 2022
04fb247
Remove native_int_types
antoyo Jan 30, 2022
ede4e5c
Remove non native int types
antoyo Jan 30, 2022
66285c9
Refactor by making a function from_low_high
antoyo Jan 30, 2022
0bb5ff7
More cleanup
antoyo Jan 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions .github/workflows/main.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,43 @@ jobs:

strategy:
fail-fast: false
matrix:
libgccjit_version: ["libgccjit.so", "libgccjit_without_int128.so"]

steps:
- uses: actions/checkout@v2

- uses: actions/checkout@v2
with:
repository: llvm/llvm-project
path: llvm

- name: Install packages
run: sudo apt-get install ninja-build ripgrep

- name: Download artifact
uses: dawidd6/action-download-artifact@v2
with:
workflow: main.yml
name: libgccjit.so
name: ${{ matrix.libgccjit_version }}
path: gcc-build
repo: antoyo/gcc
search_artifacts: true # Because, instead, the action only check the last job ran and that won't work since we want multiple artifacts.

- name: Setup path to libgccjit
run: |
echo $(readlink -f gcc-build) > gcc_path
# NOTE: the filename is still libgccjit.so even when the artifact name is different.
ln gcc-build/libgccjit.so gcc-build/libgccjit.so.0

- name: Set LIBRARY_PATH
- name: Set env
run: |
echo "LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$(cat gcc_path)" >> $GITHUB_ENV
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV

- name: Set RUST_COMPILER_RT_ROOT
run: echo "RUST_COMPILER_RT_ROOT="${{ env.workspace }}/llvm/compiler-rt >> $GITHUB_ENV

# https://github.com/actions/cache/issues/133
- name: Fixup owner of ~/.cargo/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ gimple*
res
test-backend
gcc_path
benchmarks
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ Or add a breakpoint to `add_error` in gdb and print the line number using:

```
p loc->m_line
p loc->m_filename->m_buffer
```

To print a debug representation of a tree:

```c
debug_tree(expr);
```

To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo build`.
Expand All @@ -134,4 +141,5 @@ To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo b
* Set `linker='-Clinker=m68k-linux-gcc'`.
* Set the path to the cross-compiling libgccjit in `gcc_path`.
* Disable the 128-bit integer types if the target doesn't support them by using `let i128_type = context.new_type::<i64>();` in `context.rs` (same for u128_type).
* Comment the line: `context.add_command_line_option("-masm=intel");` in src/base.rs.
* (might not be necessary) Disable the compilation of libstd.so (and possibly libcore.so?).
14 changes: 11 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#set -x
set -e

if [ -f ./gcc_path ]; then
if [ -f ./gcc_path ]; then
export GCC_PATH=$(cat gcc_path)
else
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
Expand All @@ -13,13 +13,21 @@ fi
export LD_LIBRARY_PATH="$GCC_PATH"
export LIBRARY_PATH="$GCC_PATH"

features=

if [[ "$1" == "--features" ]]; then
shift
features="--features $1"
shift
fi

if [[ "$1" == "--release" ]]; then
export CHANNEL='release'
CARGO_INCREMENTAL=1 cargo rustc --release
CARGO_INCREMENTAL=1 cargo rustc --release $features
else
echo $LD_LIBRARY_PATH
export CHANNEL='debug'
cargo rustc
cargo rustc $features
fi

source config.sh
Expand Down
2 changes: 1 addition & 1 deletion build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ "$1" == "--release" ]]; then
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release
else
sysroot_channel='debug'
cargo build --target $TARGET_TRIPLE
cargo build --target $TARGET_TRIPLE --features compiler_builtins/c
fi

# Copy files to sysroot
Expand Down
7 changes: 6 additions & 1 deletion src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
if env::var("CG_GCCJIT_DUMP_MODULE_NAMES").as_deref() == Ok("1") {
println!("Module {}", module.name);
}
if env::var("CG_GCCJIT_DUMP_MODULE").as_deref() == Ok(&module.name) {
if env::var("CG_GCCJIT_DUMP_ALL_MODULES").as_deref() == Ok("1") || env::var("CG_GCCJIT_DUMP_MODULE").as_deref() == Ok(&module.name) {
println!("Dumping reproducer {}", module.name);
let _ = fs::create_dir("/tmp/reproducers");
// FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
Expand All @@ -54,6 +54,11 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, _diag_han
context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
println!("Dumped reproducer {}", module.name);
}
if env::var("CG_GCCJIT_DUMP_TO_FILE").as_deref() == Ok("1") {
let _ = fs::create_dir("/tmp/gccjit_dumps");
let path = &format!("/tmp/gccjit_dumps/{}.c", module.name);
context.dump_to_file(path, true);
}
context.compile_to_file(OutputKind::ObjectFile, obj_out.to_str().expect("path to str"));
}

Expand Down
8 changes: 4 additions & 4 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ pub fn linkage_to_gcc(linkage: Linkage) -> FunctionType {
}
}

pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (ModuleCodegen<GccContext>, u64) {
pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol, supports_128bit_integers: bool) -> (ModuleCodegen<GccContext>, u64) {
let prof_timer = tcx.prof.generic_activity("codegen_module");
let start_time = Instant::now();

let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
let (module, _) = tcx.dep_graph.with_task(
dep_node,
tcx,
cgu_name,
(cgu_name, supports_128bit_integers),
module_codegen,
Some(dep_graph::hash_result),
);
Expand All @@ -71,7 +71,7 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
// the time we needed for codegenning it.
let cost = time_to_codegen.as_secs() * 1_000_000_000 + time_to_codegen.subsec_nanos() as u64;

fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<GccContext> {
fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, supports_128bit_integers): (Symbol, bool)) -> ModuleCodegen<GccContext> {
let cgu = tcx.codegen_unit(cgu_name);
// Instantiate monomorphizations without filling out definitions yet...
//let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
}

{
let cx = CodegenCx::new(&context, cgu, tcx);
let cx = CodegenCx::new(&context, cgu, tcx, supports_128bit_integers);

let mono_items = cgu.items_in_deterministic_order(tcx);
for &(mono_item, (linkage, visibility)) in &mono_items {
Expand Down
Loading