Giter Site home page Giter Site logo

Comments (5)

japaric avatar japaric commented on June 24, 2024

I think this is how the disassembly was produced:

$ cargo new --bin app && cd $_
$ edit src/main.rs && cat $_
#![feature(compiler_builtins_lib)]
#![feature(lang_items)]
#![no_main]
#![no_std]

extern crate compiler_builtins;

use core::ptr;

#[no_mangle]
pub fn _start() -> ! {
    let x = unsafe {
        ptr::read_volatile(0x0 as *const u32)
    };
    let y = x * (48000000 / 1000000) / 3;

    loop {}
}

#[lang = "panic_fmt"]
#[no_mangle]
fn panic_fmt() {}

#[no_mangle]
pub fn __aeabi_unwind_cpp_pr0() {}
$ xargo rustc --target thumbv6m-none-eabi -- -C link-arg=-nostartfiles

from compiler-builtins.

seeday avatar seeday commented on June 24, 2024

@japaric correct. For completeness here's the full function.

pub fn udelay(us: u32) {
    if us == 0 {
        return;
    }

    let n = us * (48_000_000 / 1_000_000) / 3;
    unsafe {
        asm!("1:
          subs $0, #1
          bne 1b
         " :: "r" (n));
    }
}

from compiler-builtins.

parched avatar parched commented on June 24, 2024

I had a look at the LLVM IR on playground and it seems that rustc calls the intrinsic @llvm.umul.with.overflow.i32 for all the normal multiplications in __muldi3 here in debug mode. That instrinic calls __aeabi_lmul as @seeday spotted which calls __muldi3 and hence the infinite recursion. Replacing the normal multiplications with wrapping_mul should solve the problem I believe.

from compiler-builtins.

nezza avatar nezza commented on June 24, 2024

@parched Hi, thanks for taking the time to look at this! Do you happen to have a rough patch idea for that? I am unfortunately not yet deep enough into the compiler-rt code but am facing the same issue.
Thanks in advance!

from compiler-builtins.

nezza avatar nezza commented on June 24, 2024

@parched Wow, thanks for the fast patch. I can confirm this works for me and stops the infinite recursion from happening.

from compiler-builtins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.