Skip to content

Commit

Permalink
[v3i/simd]: Fold more statements using "return if"
Browse files Browse the repository at this point in the history
  • Loading branch information
haoyu-zc committed Nov 3, 2023
1 parent 6e6a157 commit dbcb9ca
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/engine/V3Eval.v3
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,7 @@ def I8_ADD_SAT_S(a: i8, b: i8) -> i8 {
}
def I8_ADD_SAT_U(a: u8, b: u8) -> u8 {
var sum = u16.view(a) + u16.view(b);
if (sum > 255) return 255;
else return u8.view(sum);
return if (sum > 255, 255, u8.view(sum));
}
def I8_SUB_SAT_S(a: i8, b: i8) -> i8 {
var dif = i16.view(a) - i16.view(b);
Expand All @@ -605,8 +604,7 @@ def I8_SUB_SAT_S(a: i8, b: i8) -> i8 {
}
def I8_SUB_SAT_U(a: u8, b: u8) -> u8 {
var dif = i16.view(a) - i16.view(b);
if (dif < 0) return u8.view(0);
else return u8.view(dif);
return if (dif < 0, u8.view(0), u8.view(dif));
}
def I16_ADD_SAT_S(a: i16, b: i16) -> i16 {
var sum = i32.view(a) + i32.view(b);
Expand All @@ -616,8 +614,7 @@ def I16_ADD_SAT_S(a: i16, b: i16) -> i16 {
}
def I16_ADD_SAT_U(a: u16, b: u16) -> u16 {
var sum = u32.view(a) + u32.view(b);
if (sum > u16.max) return u16.max;
else return u16.view(sum);
return if (sum > u16.max, u16.max, u16.view(sum));
}
def I16_SUB_SAT_S(a: i16, b: i16) -> i16 {
var dif = i32.view(a) - i32.view(b);
Expand All @@ -627,8 +624,7 @@ def I16_SUB_SAT_S(a: i16, b: i16) -> i16 {
}
def I16_SUB_SAT_U(a: u16, b: u16) -> u16 {
var dif = i32.view(a) - i32.view(b);
if (dif < 0) return u16.view(0);
else return u16.view(dif);
return if (dif < 0, u16.view(0), u16.view(dif));
}
def I16_Q15_MUL_SAT_S(a: i16, b: i16) -> i16 {
var prod = (i32.view(a) * i32.view(b) + 0x4000) >> 15;
Expand Down

0 comments on commit dbcb9ca

Please sign in to comment.