Skip to content

RV64F Support - #22

Open
uslsteen wants to merge 20 commits into
masterfrom
issue-7-rv64f-support
Open

uslsteen wants to merge 20 commits into
masterfrom
issue-7-rv64f-support

Conversation

@uslsteen

@uslsteen uslsteen commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

doushe821 and others added 15 commits March 10, 2026 20:22
TODO: 1. softfloat lib integration
2. Emition
3. Tests
That's it
Also improved builder and encoding. Also integration of softfloat is questionable and I might have to look for better solution.

TODO:
1. Finish builder
2. Implement Emitter.
3. Test.
Optional: search for better building method. Current one is ugly, but it might be the optimal one, since softfloat doesn't provide cmake for some reason.
DONE:
1. Extra encoding formats needed for RV64F instructions.
2. Added some helper functions in scope.rb and cpp_gen.rb
3. Added emition of RV64F instrs.
TODO:
1. Need to fix types for floating point temporaries.
2. Write tests.
3. Might need to refactor dsl implementation of this extension. Most methods can be generalized by adding their size as an attribute. It goes even further for Conversion instructions, because they all can be merged into one isntruction with 4 attributes. But this might become tidious in debug phase, so in my opinion, tests first, and then this changes.
TODO:
1. Do neg correctly.
2. Add rounding mode everywhere, for that I also need to change cpu_state emitter a bit.
3. Move most fp-relateed functions in separate module of emitter.
4. Tests.
…ions, added NaN checks that do not use isNaN from softfloat.
Also fixed a small bug in decorder, also started to write proposals (getting ready for mr)
* Exit code are passing from the exit syscall now
* Introduced Control Status Register(s) read & write interfaces
@uslsteen uslsteen added help wanted Extra attention is needed dsl long-term labels Jul 2, 2026
This was linked to issues Jul 2, 2026
@uslsteen
uslsteen requested a review from egorshamshura July 2, 2026 22:10
Comment thread cmake/dependencies.cmake Outdated
Comment thread cmake/softfloat.cmake
# float-to-int saturation match the RISC-V F/D spec (e.g. default NaN
# 0x7FC00000, i32_fromNaN 0x7FFFFFFF) rather than the 8086/x86 semantics.
file(GLOB SOFTFLOAT_PLATFORM_SRC
${softfloat_SOURCE_DIR}/source/RISCV/*.c

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider architecture specific.

Comment thread code_gen/cpp_gen.rb
@emitter.emit_line("#{dst} = static_cast<#{Utility::HelperCpp.gen_small_type operation[:oprnds][0][:type]}>(#{src} << #{operation[:oprnds][3][:value]});")
when :sysCall
@emitter.emit_line('cpu.doExit();')
when :readCSR

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we accept it? @egorshamshura

@egorshamshura egorshamshura Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not good to create separate operation for every external call

I think we need to add something like "externCall" or just "call" operation

Comment thread code_gen/cpp_gen.rb Outdated
Comment thread lib/ADL/builder.rb Outdated
Comment thread lib/ADL/value.rb Outdated
Comment thread lib/ir_gen.rb
Comment on lines +6 to +7
require 'Target/RISC-V/64I'
require 'Target/RISC-V/64F'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I temporarily disabled RV 32 I, leaving only the 64-bit version for functional testing. How do we manage switching between 32/64-bit builds? @egorshamshura

emitter.emit_line('// Function to stop the CPU execution')
emitter.emit_line('void doExit() {')
emitter.increase_indent
emitter.emit_line('m_exit_code = static_cast<int>(m_XRegs[10]);')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave it as is.

Comment thread lib/Target/RISC-V/64I.rb
Comment on lines +373 to +432
Instruction(:csrrw) {
encoding(*format_csr(0b1110011, 0b001))
asm { "csrrw {rd}, {csr}, {rs1}" }
code {
t = readCSR(csr)
writeCSR(csr, rs1)
rd[] = t
}
}

Instruction(:csrrs) {
encoding(*format_csr(0b1110011, 0b010))
asm { "csrrs {rd}, {csr}, {rs1}" }
code {
t = readCSR(csr)
writeCSR(csr, t | rs1)
rd[] = t
}
}

Instruction(:csrrc) {
encoding(*format_csr(0b1110011, 0b011))
asm { "csrrc {rd}, {csr}, {rs1}" }
code {
t = readCSR(csr)
writeCSR(csr, t & (rs1 ^ -1))
rd[] = t
}
}

Instruction(:csrrwi) {
encoding(*format_csri(0b1110011, 0b101))
asm { "csrrwi {rd}, {csr}, {zimm}" }
code {
t = readCSR(csr)
writeCSR(csr, zimm)
rd[] = t
}
}

Instruction(:csrrsi) {
encoding(*format_csri(0b1110011, 0b110))
asm { "csrrsi {rd}, {csr}, {zimm}" }
code {
t = readCSR(csr)
writeCSR(csr, t | zimm)
rd[] = t
}
}

Instruction(:csrrci) {
encoding(*format_csri(0b1110011, 0b111))
asm { "csrrci {rd}, {csr}, {zimm}" }
code {
t = readCSR(csr)
writeCSR(csr, t & (zimm ^ -1))
rd[] = t
}
}
end

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay, @derzhavin3016 , @egorshamshura ?

Comment on lines +13 to +18
INT_INFO = {
i32: 'int32_t',
u32: 'uint32_t',
i64: 'int64_t',
u64: 'uint64_t'
}.freeze

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move into more generic part.

@uslsteen

Copy link
Copy Markdown
Collaborator Author

@doushe821 remove please all "PROPOSAL" comments.

Comment thread cmake/softfloat.cmake Outdated
Comment thread code_gen/cpp_gen.rb Outdated
Comment on lines +352 to +370
@emitter.emit_line("uint64_t v = #{src};")
@emitter.emit_line('uint64_t sign = v >> 63;')
@emitter.emit_line('uint64_t exp = (v >> 52) & 0x7FF;')
@emitter.emit_line('uint64_t frac = v & 0xFFFFFFFFFFFFFULL;')
@emitter.emit_line('uint32_t r = 0;')
@emitter.emit_line('')
@emitter.emit_line('if (exp == 0x7FF) {')
@emitter.emit_line(' if (frac == 0) r = sign ? (1u << 0) : (1u << 7);')
@emitter.emit_line(' else r = (frac & (1ULL << 51)) ? (1u << 9) : (1u << 8);')
@emitter.emit_line('}')
@emitter.emit_line('else if (exp == 0) {')
@emitter.emit_line(' if (frac == 0) r = sign ? (1u << 3) : (1u << 4);')
@emitter.emit_line(' else r = sign ? (1u << 2) : (1u << 5);')
@emitter.emit_line('}')
@emitter.emit_line('else {')
@emitter.emit_line(' r = sign ? (1u << 1) : (1u << 6);')
@emitter.emit_line('}')
@emitter.emit_line('')
@emitter.emit_line("#{dst} = r;")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this code should not be generated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, do you propose making a new file in sim_lib directory in which architecture specific implementations will be stored? Maybe it would be better to still generate it but move it to a separate .rb file and include this file conditionally. E.g. make a function f64_classify_general and make every file with architecture-specific implementation implement their own version and then require needed file based on architecture flag or something like that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but needs review, because I've modified quite a bit with the last commit. (decided to add interface for architecture-specific implementations to non-generated C++ code)

Removed generation of classify instructions from ruby files, moved them to riscv_arch_ops.cc. Implemented interface class arch_ops.hh. Added architecture specifying field to IR.yaml (was hardcoded previously).

@uslsteen uslsteen left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest moving the common FPU API to the Generic/ directory and the architecture-specific code to the corresponding directories.

Comment thread sim_lib/arch_ops.hh Outdated
This was referenced Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dsl help wanted Extra attention is needed long-term

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RV64F Support RV64I Support RV64 Support

4 participants