-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix admesh big-endian support #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix admesh big-endian support #534
Conversation
Partially revert 2085a48. This is in preparation for applying the upstream fix from admesh at admesh/admesh#26
Would you please list out the architectures for me that you would like getting fixed? From the performance point of view, it may make sense to keep my original code intact and then to flip a set of byte quads all at once. Thanks |
All the architectures listed as BE here: https://wiki.debian.org/ArchitectureSpecificsMemo, so these:
Are there really much performance gains to be had here? The original admesh STL binary output code was correct on big-endian architectures before you broke it in the same commit as your If you're really concerned about the performance here, I can rework it to do all the byteflipping operations using |
I have to admit I have no experience whatsoever with the big endian architectures. I used to work for SuSE in 2000 as a package manager, where I was responsible for packages being compiled on big endian architectures, but I don't remember the little / big endian issues and resolutions anymore.
I sketched a prototype already. I will make a branch for you to review.
Again, I am not sure what the correct handling of NaN, infinities and such should be. In my experience the STLs produced by various modeling software are often buggy and they contain some of these corner cases. For example, I have seen openscad producing some triangle normals with NaNs, and I have patched the admesh to gracefully handle the invalid normals. Taking the state of the STL generators into account, this seems to me the way to go. |
Would you please review the following? I tried to maintain the performance while keeping the changes minimal. Is this acceptable to you? Thanks |
On Tue, Oct 03, 2017 at 07:39:31AM +0000, bubnikv wrote:
I have to admit I have no experience whatsoever with the big endian
architectures. I used to work for SuSE in 2000 as a package manager, where I
was responsible for packages being compiled on big endian architectures, but I
don't remember the little / big endian issues and resolutions anymore.
> If you're really concerned about the performance here, I can rework it to do
> all the byteflipping operations using htole32 and memcpying them into a
> large buffer before fwrite()ing them all in one go,
I sketched a prototype already. I will make a branch for you to review.
> but I don't think we should byteflip the floats in the struct in place as it
> may end up as a signalling NaN which may then be silently rewritten into a
> quiet NaN (I think) on some architectures.
Again, I am not sure what the correct handling of NaN, infinities and such
should be.
I'm not entirely certain how they should be handled, but my point is that we
shouldn't inadvertently create signalling NaNs while byteflipping valid floats
into their LE counterparts or vice versa.
If you look at the changes I did to the open routine, you'll see that I made
sure to first read into a char array, memcpy'd it into uint32_t for the byteflip
operation and only when it's ready, memcpy it into an actual float. All this is
to avoid leaking a potentially invalid float (non-native endianness) into an FPU
by mistake, or falsely triggering any floating point errors while reading the
file.
In my experience the STLs produced by various modeling software are
often buggy and they contain some of these corner cases. For example, I have
seen openscad producing some triangle normals with NaNs, and I have patched
the admesh to gracefully handle the invalid normals. Taking the state of the
STL generators into account, this seems to me the way to go.
Sure, but that handling of invalid normals isn't done in the serialization or
deserialization routine, afaict, and so has nothing to do with this PR.
…--
Kind regards,
Loong Jin
|
I see you've already committed a52a045 onto master, so I'll close this PR. Please consider what I said in my previous post about byteflipping |
I'm not entirely certain how they should be handled, but my point is that
we
shouldn't inadvertently create signalling NaNs while byteflipping valid
floats
into their LE counterparts or vice versa.
I think it should be fine. My modified code accesses the data by char*
after loading before and during flipping, and the ints and floats are
copied to char* before flipping, so the floats will not be accessed in
reverse order as far as I can see.
Thanks for your effort.
…On Tue, Oct 3, 2017 at 11:23 AM, Chow Loong Jin ***@***.***> wrote:
Closed #534 <#534>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#534 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AFj5I3vjxFMNTjUv2uXQh58gPTmHME9Nks5sof0SgaJpZM4Pp9Sc>
.
|
On Tue, Oct 03, 2017 at 09:35:14AM +0000, bubnikv wrote:
> I'm not entirely certain how they should be handled, but my point is that
we
shouldn't inadvertently create signalling NaNs while byteflipping valid
floats
into their LE counterparts or vice versa.
I think it should be fine. My modified code accesses the data by char*
after loading before and during flipping, and the ints and floats are
copied to char* before flipping, so the floats will not be accessed in
reverse order as far as I can see.
Please read https://groups.google.com/d/msg/boost-list/DgB0DyiZeCE/xv_1S7BKCAAJ
for complications when it comes to byte swapping floats. I don't think you need
to actually access it as a float to cause issues. The way I understand it, just
playing around with the bytes of a char* that's aliased with a float can also
cause issues.
…--
Kind regards,
Loong Jin
|
Thanks. I believe my code should be fine. The only risk I see is in the reading routine, where in theory the compiler could access the facet floats before the byte swapping. I believe though, that a correct compiler should detect the aliasing on stlinit.cpp:277 before accessing the floating point data on line 362 and outside the function. |
This PR reenables big-endian support and fixes up the binary STL import in admesh by importing the fix from admesh/admesh#26.
Fixes #532