Repository navigation
Conversation
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.
Safety commit
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
| # 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 |
There was a problem hiding this comment.
Consider architecture specific.
| @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 |
There was a problem hiding this comment.
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
| require 'Target/RISC-V/64I' | ||
| require 'Target/RISC-V/64F' |
There was a problem hiding this comment.
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]);') |
There was a problem hiding this comment.
Let's leave it as is.
| 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 |
There was a problem hiding this comment.
Is it okay, @derzhavin3016 , @egorshamshura ?
| INT_INFO = { | ||
| i32: 'int32_t', | ||
| u32: 'uint32_t', | ||
| i64: 'int64_t', | ||
| u64: 'uint64_t' | ||
| }.freeze |
There was a problem hiding this comment.
Let's move into more generic part.
|
@doushe821 remove please all "PROPOSAL" comments. |
… changes in value.rb and builder.rb
| @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;") |
There was a problem hiding this comment.
Seems like this code should not be generated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
I suggest moving the common FPU API to the Generic/ directory and the architecture-specific code to the corresponding directories.
…ded fpu everywhere)
No description provided.