Skip to content
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

FPU is not enabled in Newlib for ARC-V #633

Closed
kolerov opened this issue Jul 4, 2024 · 1 comment
Closed

FPU is not enabled in Newlib for ARC-V #633

kolerov opened this issue Jul 4, 2024 · 1 comment
Assignees
Labels
arc-v Issues related to RISC-V-based ARC-V processors component: newlib enhancement
Milestone

Comments

@kolerov
Copy link
Collaborator

kolerov commented Jul 4, 2024

FPU must be enabled before using floating point instructions. Newlib's crt0.S and arcv-crt0.S (our own custom crt0) does not do this. Here is an example of how it's done in Picolibc:

#ifdef __riscv_flen
	__asm__("csrr	t0, mstatus\n"
                "li	t1, 8192\n"     	// 1 << 13 = 8192
                "or	t0, t1, t0\n"
                "csrw	mstatus, t0\n"
                "csrwi	fcsr, 0");
#endif

Here is a piece of code that could be used as a quick workaround. It's placed in .init section and executed before main.

#ifdef __riscv_flen
__attribute__((naked)) __attribute__((used)) __attribute__((aligned(4))) __attribute__((constructor))
void enable_fpu(void)
{
        __asm__("csrr   t0, mstatus\n"
                "li     t1, 8192\n"             // 1 << 13 = 8192
                "or     t0, t1, t0\n"
                "csrw   mstatus, t0\n"
                "csrwi  fcsr, 0\n"
                "ret");
}
#endif

It would be better to add support of enabling FPU right in arcv-crt0.S. Maybe it's worth placing the same code to original crt0.S and push to upstream.

@kolerov kolerov added enhancement component: newlib arc-v Issues related to RISC-V-based ARC-V processors labels Jul 4, 2024
@kolerov kolerov added this to the 2024.06 milestone Jul 4, 2024
@kolerov kolerov self-assigned this Jul 4, 2024
@kolerov
Copy link
Collaborator Author

kolerov commented Jul 4, 2024

The fix is pushed in arc64 and arc-2024.06 branches of Newlib repository. Now FPU is enabled for configurations with f or d extensions.

@kolerov kolerov closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arc-v Issues related to RISC-V-based ARC-V processors component: newlib enhancement
Projects
None yet
Development

No branches or pull requests

1 participant