top of page

[Chisel/Scala] Introduce decimal point data

  • Writer: M.R
    M.R
  • Mar 9, 2024
  • 1 min read

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 All
[Chisel] Don't use polymorphism

What I want to do There are multiple similar units Most of processes are the same, only some differences. Select an appropriate unit...

 
 
 

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Inquiries: Please contact us on Twitter

  • Twitter
bottom of page