tint/hlsl: fix frexp always returning positive values for fractional part

Bug: tint:1876
Change-Id: Ic56b37918fd1a2a42442b517985a49f10d85159d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/124501
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano
2023-03-16 21:31:15 +00:00
parent 8cf01eef04
commit 52cd8caa07
23 changed files with 25 additions and 65 deletions

View File

@@ -2045,7 +2045,7 @@ bool GeneratorImpl::EmitFrexpCall(utils::StringStream& out,
}
line(b) << member_type << " exp;";
line(b) << member_type << " fract = frexp(" << in << ", exp);";
line(b) << member_type << " fract = sign(" << in << ") * frexp(" << in << ", exp);";
{
auto l = line(b);
if (!EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined,

View File

@@ -606,7 +606,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Scalar_f32) {
};
frexp_result_f32 tint_frexp(float param_0) {
float exp;
float fract = frexp(param_0, exp);
float fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f32 result = {fract, int(exp)};
return result;
}
@@ -635,7 +635,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Scalar_f16) {
};
frexp_result_f16 tint_frexp(float16_t param_0) {
float16_t exp;
float16_t fract = frexp(param_0, exp);
float16_t fract = sign(param_0) * frexp(param_0, exp);
frexp_result_f16 result = {fract, int(exp)};
return result;
}
@@ -662,7 +662,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Vector_f32) {
};
frexp_result_vec3_f32 tint_frexp(float3 param_0) {
float3 exp;
float3 fract = frexp(param_0, exp);
float3 fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f32 result = {fract, int3(exp)};
return result;
}
@@ -691,7 +691,7 @@ TEST_F(HlslGeneratorImplTest_Builtin, Runtime_Frexp_Vector_f16) {
};
frexp_result_vec3_f16 tint_frexp(vector<float16_t, 3> param_0) {
vector<float16_t, 3> exp;
vector<float16_t, 3> fract = frexp(param_0, exp);
vector<float16_t, 3> fract = sign(param_0) * frexp(param_0, exp);
frexp_result_vec3_f16 result = {fract, int3(exp)};
return result;
}