[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 The following chisel code causes the compilation error: val parts = new Module(new MyParts()) class Module is abstract; cannot be instantiated Causes and Solutions This is because I added "
What want to do As the title says, I want to add a chisel hardware array to a Bundle member. Situation is tat I want to implement multiple identical circuits and process them in parallel. It's easy if
What I want to do I have a class (parts) that I created and that inherits from Module. I want to place multiple instances (components) of this class in a circuit. What I tried I tried to create an arr