8000 [Homework 7] Floating point calling convention. · Issue #209 · kaist-cp/cs420 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Homework 7] Floating point calling convention. #209

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

Closed
Pusnow opened this issue Jun 12, 2020 · 5 comments
Closed

[Homework 7] Floating point calling convention. #209

Pusnow opened this issue Jun 12, 2020 · 5 comments
Labels
homework - asmgen src/asmgen/mod.rs

Comments

@Pusnow
Copy link
Pusnow commented Jun 12, 2020

GotBolt maps floating point arguments to integer argument registers (a0-a7).

However, there are separate floating point registers (fa0-fa7).

RISC-V ABI also uses them:

If argument i < 8 is a floating-point type, it is passed in floating-point register fai; otherwise, it is passed in integer register ai.

So, which one should we use?

@jeehoonkang
Copy link
Member

(continuing the discussion of #211 2.)

There are 2 ways to call a function: (1) allocating stack & (2) passing through a0, a1, a2, ... (if argument <= 8). And we know that if the function has Call Instruction, we must use the (1).
To satisfy hw7 (generate correct RISC-V code), is it possible to somehow "generalize" to only use only the (1)?

@cmpark0126
Copy link
Collaborator
cmpark0126 commented Jun 14, 2020

Please refer to this link: https://godbolt.org/z/mkZvYQ

Godbolt provides two compilers using RISC-V: RISC-V gcc 8.2.0 and RISC-V rv64gc clang.

As can be seen in the above link, RISC-V gcc 8.2.0 follows the calling convention of the RISC-V ABI, while RISC-V rv64gc clang not to follow.

So, please implement asmgen by referring to the behavior of RISC-V gcc 8.2.0.

FYI, for the final project, riscv64-linux-gnu-gcc-10 will be used to link your solution and test driver.
(riscv64-linux-gnu-gcc-10 shows similar behavior to RISC-V gcc 8.2.0)

@cmpark0126 cmpark0126 assigned jeehoonkang and unassigned cmpark0126 Jun 15, 2020
@jeehoonkang
Copy link
Member
jeehoonkang commented Jun 15, 2020

RISC-V has multiple calling conventions regarding floating-point numbers: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/44f98e0fd8104def00f2a5a8d94b23dd647d18fb/riscv-elf.md#named-abis Conventions differ on the use of floating-point registers. In particular, the LP64 ABI doesn't use fa? registers, while LP64D does.

It seems clang uses LP64 by default, which I think is bug because LP64D is the default ABI for RV64GC (on which KECC is targeting). If you add -mabi=lp64d to the compiler flag, then you'll get the expected result (i.e., using fa? registers for arguments and returns).

The specification for the assignments was confusing, so I'd like to declare:

  • For homework 7, you don't need to observe the calling convention. All test functions have the signature () -> (), for which calling conventions don't matter at all.

  • For project,you need to observe the LP64D calling convention. Benchmark will ask whether you correctly implemented the calling convention.

@Pusnow
Copy link
Author
Pusnow commented Jun 19, 2020

Great! I will keep open this issue for other students.

@jeehoonkang
Copy link
Member

I believe this issue is now sufficiently advertised :) Thank you all for making such a wonderful discussion thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
homework - asmgen src/asmgen/mod.rs
Projects
None yet
Development

No branches or pull requests

4 participants
0