Skip to content

Commit 8ea63d6

Browse files
authored
Update code for fcvt.s.w, fcvt.s.wu, fadd and fsub (#461)
* Committing after removing trailing whitespace * Fix rm value to take from instruction encoding * autochange by end-of-file-fixer * Add missing close bracket
1 parent 4575bbe commit 8ea63d6

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

arch/inst/F/fadd.s.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ access:
2727
vu: always
2828
data_independent_timing: true
2929
operation(): |
30-
RoundingMode mode = rm_to_mode(X[rm], $encoding);
30+
check_f_ok($encoding);
31+
RoundingMode mode = rm_to_mode(rm, $encoding);
3132
X[fd] = f32_add(X[fs1], X[fs2], mode);
3233
3334
sail(): |

arch/inst/F/fcvt.s.w.yaml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,8 @@ access:
3434
data_independent_timing: false
3535
operation(): |
3636
check_f_ok($encoding);
37-
38-
Bits<32> int_value = X[rs1];
39-
40-
Bits<1> sign = int_value[31];
41-
4237
RoundingMode rounding_mode = rm_to_mode(rm, $encoding);
43-
44-
if ((int_value & 32'h7fff_ffff) == 0) {
45-
X[fd] = (sign == 1) ? packToF32UI(1, 0x9E, 0) : 0;
46-
} else {
47-
Bits<32> absA = (sign == 1) ? -int_value : int_value;
48-
X[fd] = softfloat_normRoundPackToF32( sign, 0x9C, absA, rounding_mode );
49-
}
50-
38+
X[fd] = i32_to_f32(X[rs1], rounding_mode);
5139
mark_f_state_dirty();
5240
5341
sail(): |

arch/inst/F/fcvt.s.wu.yaml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
$schema: "inst_schema.json#"
44
kind: instruction
55
name: fcvt.s.wu
6-
long_name: No synopsis available.
6+
long_name: Convert unsigned 32-bit integer to single-precision float
77
description: |
8-
No description available.
8+
Converts a 32-bit unsigned integer in integer register _rs1_ into a floating-point number in
9+
floating-point register _fd_.
10+
11+
All floating-point to integer and integer to floating-point conversion instructions round
12+
according to the _rm_ field.
13+
A floating-point register can be initialized to floating-point positive zero using
14+
`fcvt.s.w rd, x0`, which will never set any exception flags.
15+
16+
All floating-point conversion instructions set the Inexact exception flag if the rounded
17+
result differs from the operand value and the Invalid exception flag is not set.
918
definedBy: F
1019
assembly: fd, xs1, rm
1120
encoding:
@@ -24,7 +33,10 @@ access:
2433
vu: always
2534
data_independent_timing: true
2635
operation(): |
27-
36+
check_f_ok($encoding);
37+
RoundingMode rounding_mode = rm_to_mode(rm, $encoding);
38+
X[fd] = ui32_to_f32(X[rs1], rounding_mode);
39+
mark_f_state_dirty();
2840
sail(): |
2941
{
3042
assert(sizeof(xlen) >= 64);

arch/inst/F/fsub.s.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ access:
2727
vu: always
2828
data_independent_timing: true
2929
operation(): |
30-
RoundingMode mode = rm_to_mode(X[rm], $encoding);
30+
check_f_ok($encoding);
31+
RoundingMode mode = rm_to_mode(rm, $encoding);
3132
X[fd] = f32_sub(X[fs1], X[fs2], mode);
3233
sail(): |
3334
{

arch/isa/fp.idl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,3 +882,43 @@ function f32_sub {
882882
}
883883
}
884884
}
885+
886+
function i32_to_f32 {
887+
returns U32
888+
arguments
889+
U32 a,
890+
RoundingMode mode
891+
description {
892+
Converts 32-bit signed integer to 32-bit floating point
893+
}
894+
body {
895+
# sign of integer, it is 1 when negative
896+
Bits<1> sign = a[31];
897+
if ((a & 0x7FFFFFFF) == 0) {
898+
return (sign == 1) ? packToF32UI(1, 0x9E, 0) : packToF32UI(0, 0, 0);
899+
}
900+
U32 magnitude_of_A = returnMag(a);
901+
return softfloat_normRoundPackToF32(sign, 0x9C, magnitude_of_A, mode);
902+
}
903+
}
904+
905+
function ui32_to_f32 {
906+
returns U32
907+
arguments
908+
U32 a,
909+
RoundingMode mode
910+
description {
911+
Converts 32-bit unsigned integer to 32-bit floating point
912+
}
913+
body {
914+
# sign of integer, it is 1 when negative
915+
if (a == 0) {
916+
return a;
917+
}
918+
if (a[31] == 1) {
919+
return softfloat_roundPackToF32(0, 0x9D, a>>1 | (a & 1), mode);
920+
} else {
921+
return softfloat_normRoundPackToF32(0, 0x9C, a, mode);
922+
}
923+
}
924+
}

0 commit comments

Comments
 (0)