[Chisel/Scala] Introduce decimal point data
What I want to do
I want to introduce decimal point data (float in other languages).
The background is that I'm trying to set up a performance counter in a self-designed CPU circuit, and I want to express it in a decimal instead of an integer. (For example, when measuring the "number of cycles per command," the meaning is completely different whether it is 1 or 1.9.)
Problem
It would be nice if Chisel had something like a floating point data type, but it doesn't currently exist.
There used to be a FixedPoint type that represented floating point numbers, and when I searched the internet I found this method, but it seems that it has now been deprecated ( reference ).
Countermeasure
Since there is no other choice, I tried with only integer types. This time, the purpose is to display the calculation results on the screen rather than to calculate decimal numbers, so
When calculating, store the value multiplied by 10 in an integer type.
When displaying, calculate and display the integer part and decimal part separately.
like this
val cpi10 = Mux(instCount === 0.U, 0.U, cycleCount * 10.U / instCount)
printf(p"CPI: ${cpi10/10.U}.${cpi10%10.U}\n")
Recent Posts
See AllPhenomenon There is an array Check whether the index variable is within the size of the array, and access the element only if it is...
Overview When communicating data using a Queue, the following operations are possible: Queue.io.enq.valid: When set to false, data will...
What I want to do There are multiple similar units Most of processes are the same, only some differences. Select an appropriate unit...
Comentários