Skip to content
New issue

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

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

Already on GitHub? # to your account

Problem of using function printf for 32bits compiler. #51

Open
hyf6661669 opened this issue Apr 5, 2019 · 0 comments
Open

Problem of using function printf for 32bits compiler. #51

hyf6661669 opened this issue Apr 5, 2019 · 0 comments

Comments

@hyf6661669
Copy link

I'm trying to use rv8 to run codes that are compiled by 32bits compiler. My 32bits compiler is built using --with-arch=rv32gc and --with-abi=ilp32d. And the version of my compiler is 7.2.0. I find the output of rv8/src/test/test-fpu-printf.c is not correct.

The content of test-fpu-printf.c:

#include <stdio.h>

int main()
{
	float f1 = 1.0f;
	float f2 = 3.0f;
	float f3 = f1 / f2;
	printf("%.9ef ÷ %.9ef = %.9ef\n", f1, f2, f3);
}

I set RISCV as the path of the 32bits compiler, and run make test-build-rv32 to compile codes.

I also use objdump to see the generated assembly instructions:

test-fpu-printf:     file format elf32-littleriscv


Disassembly of section .text:

00010074 <main>:
   10074:	1101                	addi	sp,sp,-32
   10076:	0000b797          	auipc	a5,0xb
   1007a:	37a7b787          	fld	fa5,890(a5) # 1b3f0 <__clzsi2+0x40>
   1007e:	a43e                	fsd	fa5,8(sp)
   10080:	0000b797          	auipc	a5,0xb
   10084:	3787b787          	fld	fa5,888(a5) # 1b3f8 <__clzsi2+0x48>
   10088:	4822                	lw	a6,8(sp)
   1008a:	48b2                	lw	a7,12(sp)
   1008c:	a43e                	fsd	fa5,8(sp)
   1008e:	0000b697          	auipc	a3,0xb
   10092:	3726b787          	fld	fa5,882(a3) # 1b400 <__clzsi2+0x50>
   10096:	4722                	lw	a4,8(sp)
   10098:	47b2                	lw	a5,12(sp)
   1009a:	a43e                	fsd	fa5,8(sp)
   1009c:	4622                	lw	a2,8(sp)
   1009e:	46b2                	lw	a3,12(sp)
   100a0:	0000b517          	auipc	a0,0xb
   100a4:	36850513          	addi	a0,a0,872 # 1b408 <__clzsi2+0x58>
   100a8:	ce06                	sw	ra,28(sp)
   100aa:	24bd                	jal	10318 <printf>
   100ac:	40f2                	lw	ra,28(sp)
   100ae:	4501                	li	a0,0
   100b0:	6105                	addi	sp,sp,32
   100b2:	8082                	ret


But the otuput is:
image

Besides, I don't know why the compiler emits fld and fsd instructions. Since the variables f1 and f2 are float, the compiler should use flw and fsw.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant