Skip to content

Commit

Permalink
Handle floats and sign extension in HLE logs.
Browse files Browse the repository at this point in the history
In some cases, we were previously logging sign-extended error codes.  This
handles that better using type_traits.
  • Loading branch information
unknownbrackets committed Feb 7, 2016
1 parent 609c8eb commit e75af43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Core/HLE/HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,15 @@ void hleDoLogInternal(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, u64 res,
retmask = latestSyscall->retmask;

const char *fmt;
// TODO: Floats and other types... move to another func (for return type?) Hmm.
if (retmask == 'x') {
fmt = "%08llx=%s(%s)%s";
// Truncate the high bits of the result (from any sign extension.)
res = (u32)res;
} else if (retmask == 'i' || retmask == 'I') {
fmt = "%lld=%s(%s)%s";
} else if (retmask == 'f') {
// TODO: For now, floats are just shown as bits.
fmt = "%08x=%s(%s)%s";
} else {
_assert_msg_(HLE, false, "Invalid return format: %c", retmask);
fmt = "%08llx=%s(%s)%s";
Expand Down
19 changes: 17 additions & 2 deletions Core/HLE/HLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#pragma once

#include <cstdarg>
#include <type_traits>
#include "Common/CommonTypes.h"
#include "Common/Log.h"
#include "Core/MIPS/MIPS.h"
Expand Down Expand Up @@ -166,7 +167,14 @@ T hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, T res, const char *
va_end(args);
}

hleDoLogInternal(t, level, res, file, line, reportTag, retmask, reason, formatted_reason);
u64 fmtRes = res;
if (std::is_floating_point<T>::value) {
// We reinterpret as the bits for now, so we can have a common helper.
fmtRes = *(const u32 *)&res;
} else if (std::is_signed<T>::value) {
fmtRes = (s64)res;
}
hleDoLogInternal(t, level, fmtRes, file, line, reportTag, retmask, reason, formatted_reason);
return res;
}

Expand All @@ -176,7 +184,14 @@ T hleDoLog(LogTypes::LOG_TYPE t, LogTypes::LOG_LEVELS level, T res, const char *
return res;
}

hleDoLogInternal(t, level, res, file, line, reportTag, retmask, nullptr, "");
u64 fmtRes = res;
if (std::is_floating_point<T>::value) {
// We reinterpret as the bits for now, so we can have a common helper.
fmtRes = *(const u32 *)&res;
} else if (std::is_signed<T>::value) {
fmtRes = (s64)res;
}
hleDoLogInternal(t, level, fmtRes, file, line, reportTag, retmask, nullptr, "");
return res;
}

Expand Down

0 comments on commit e75af43

Please sign in to comment.