generated from schoeberl/chisel-empty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
62 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package vfrope | ||
|
||
import chisel3._ | ||
import chisel3.util._ | ||
|
||
class Int32ToIEEE754 extends Module { | ||
val io = IO(new Bundle { | ||
val inInt = Input(SInt(32.W)) | ||
val outIEEE = Output(UInt(32.W)) // IEEE 754 형식의 결과 출력 | ||
}) | ||
|
||
// 부호 비트 설정 | ||
val sign = io.inInt(31) | ||
val absVal = Mux(sign === 1.U, -io.inInt, io.inInt).asUInt() | ||
|
||
// Find the leading one position and adjust in one step | ||
val LeadingOne = 31.U - PriorityEncoder(Reverse(absVal)) | ||
|
||
// Corrected normalized mantissa calculation (combined in one step) | ||
val normalizedMantissa = (absVal << (23.U - LeadingOne))(22, 0) // Shift and extract 23 bits mantissa in one step | ||
|
||
// Corrected exponent calculation (combined in one step) | ||
val biasedExponent = (LeadingOne +& 127.U)(7, 0) // Calculate biased exponent in one line | ||
|
||
// Final IEEE 754 representation | ||
val outIEEE = Cat(sign, biasedExponent, normalizedMantissa) | ||
|
||
// Assign the result to the IO output | ||
io.outIEEE := outIEEE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package vfrope | ||
|
||
import chiseltest._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import chisel3._ | ||
|
||
class Int32ToIEEE754Test extends AnyFlatSpec with ChiselScalatestTester { | ||
"Int32ToIEEE754" should "convert integer to IEEE 754" in { | ||
test(new Int32ToIEEE754()) { dut => | ||
dut.io.inInt.poke(-15.S) // 0x41700000 | ||
dut.clock.step() | ||
println(s"Result: 0x${dut.io.outIEEE.peek().litValue.toString(16)}") | ||
} | ||
} | ||
} |