-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When adding the doubles I failed to reliaze that some floating point operations needed to be able to access the unboxed float value. I also missed that there were float to double conversion operations.
- Loading branch information
1 parent
696ef9e
commit 5675921
Showing
5 changed files
with
74 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package rars.riscv.instructions; | ||
|
||
import jsoftfloat.Environment; | ||
import jsoftfloat.types.Float32; | ||
import jsoftfloat.types.Float64; | ||
import rars.ProgramStatement; | ||
import rars.SimulationException; | ||
import rars.riscv.BasicInstruction; | ||
import rars.riscv.BasicInstructionFormat; | ||
import rars.riscv.hardware.FloatingPointRegisterFile; | ||
|
||
public class FCVTDS extends BasicInstruction { | ||
public FCVTDS() { | ||
super("fcvt.d.s t1, f1, dyn", "Convert a float to a double: Assigned the value of f2 to f1", | ||
BasicInstructionFormat.R4_FORMAT,"0100001 00000 sssss ttt fffff 1010011"); | ||
} | ||
|
||
public void simulate(ProgramStatement statement) throws SimulationException { | ||
int[] operands = statement.getOperands(); | ||
Environment e = new Environment(); | ||
e.mode = Floating.getRoundingMode(operands[3],statement); | ||
Float32 in = new Float32(FloatingPointRegisterFile.getValue(operands[1])); | ||
Float64 out = new Float64(0); | ||
out = FCVTSD.convert(in,out,e); | ||
Floating.setfflags(e); | ||
FloatingPointRegisterFile.updateRegisterLong(operands[0],out.bits); | ||
} | ||
} |
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,42 @@ | ||
package rars.riscv.instructions; | ||
|
||
import jsoftfloat.Environment; | ||
import jsoftfloat.types.Float32; | ||
import jsoftfloat.types.Float64; | ||
import rars.ProgramStatement; | ||
import rars.SimulationException; | ||
import rars.riscv.BasicInstruction; | ||
import rars.riscv.BasicInstructionFormat; | ||
import rars.riscv.hardware.FloatingPointRegisterFile; | ||
|
||
public class FCVTSD extends BasicInstruction { | ||
public FCVTSD() { | ||
super("fcvt.s.d t1, f1, dyn", "Convert a double to a float: Assigned the value of f2 to f1", | ||
BasicInstructionFormat.R4_FORMAT,"0100000 00001 sssss ttt fffff 1010011"); | ||
} | ||
|
||
public void simulate(ProgramStatement statement) throws SimulationException { | ||
int[] operands = statement.getOperands(); | ||
Environment e = new Environment(); | ||
e.mode = Floating.getRoundingMode(operands[3],statement); | ||
Float64 in = new Float64(FloatingPointRegisterFile.getValueLong(operands[1])); | ||
Float32 out = new Float32(0); | ||
out = convert(in,out,e); | ||
Floating.setfflags(e); | ||
FloatingPointRegisterFile.updateRegister(operands[0],out.bits); | ||
} | ||
// Kindof a long type, but removes duplicate code and would make it easy for quads to be implemented. | ||
public static <S extends jsoftfloat.types.Floating<S>,D extends jsoftfloat.types.Floating<D>> | ||
S convert(D toconvert, S constructor, Environment e){ | ||
if(toconvert.isInfinite()){ | ||
return toconvert.isSignMinus() ? constructor.NegativeInfinity() : constructor.Infinity(); | ||
} | ||
if(toconvert.isZero()){ | ||
return toconvert.isSignMinus() ? constructor.NegativeZero() : constructor.Zero(); | ||
} | ||
if(toconvert.isNaN()){ | ||
return constructor.NaN(); | ||
} | ||
return constructor.fromExactFloat(toconvert.toExactFloat(),e); | ||
} | ||
} |
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