WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 179861
[WTF] Use system endianess information instead of relying CPU information
https://bugs.webkit.org/show_bug.cgi?id=179861
Summary
[WTF] Use system endianess information instead of relying CPU information
Yusuke Suzuki
Reported
2017-11-18 08:21:55 PST
[WTF] Use system endianess information instead of relying CPU information
Attachments
Patch
(4.87 KB, patch)
2017-11-18 08:23 PST
,
Yusuke Suzuki
no flags
Details
Formatted Diff
Diff
Patch
(4.75 KB, patch)
2017-11-18 08:32 PST
,
Yusuke Suzuki
jfbastien
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Yusuke Suzuki
Comment 1
2017-11-18 08:23:34 PST
Created
attachment 327313
[details]
Patch
Yusuke Suzuki
Comment 2
2017-11-18 08:24:57 PST
My goal is removing bunch of minor CPUs from Platform.h.
Yusuke Suzuki
Comment 3
2017-11-18 08:32:24 PST
Created
attachment 327314
[details]
Patch
JF Bastien
Comment 4
2017-11-18 10:29:06 PST
Comment on
attachment 327314
[details]
Patch Do we want something that’ll work with C++17?
http://en.cppreference.com/w/cpp/types/endian
Yusuke Suzuki
Comment 5
2017-11-18 14:27:04 PST
(In reply to JF Bastien from
comment #4
)
> Comment on
attachment 327314
[details]
> Patch > > Do we want something that’ll work with C++17? >
http://en.cppreference.com/w/cpp/types/endian
In our current use cases, we need preprocessor defines to switch implementation by ifdefs. But C++ enum would work well if we implement things and switch by it. template<std::endian> void implementation(); template<> void implementation<std::endian::little>() { ...; } template<> void implementation<std::endian::big>() { ...; } And layout change is like, template<std::endian> struct Layout; template<> struct Layout<std::endian::big> { uint8_t f0; uint8_t f1; }; template<> struct Layout<std::endian::little> { uint8_t f1; uint8_t f0; }; I'm not sure how to handle PDP endian (a.k.a. middle endian) in C++17.
JF Bastien
Comment 6
2017-11-18 21:01:41 PST
(In reply to Yusuke Suzuki from
comment #5
)
> (In reply to JF Bastien from
comment #4
) > > Comment on
attachment 327314
[details]
> > Patch > > > > Do we want something that’ll work with C++17? > >
http://en.cppreference.com/w/cpp/types/endian
> > In our current use cases, we need preprocessor defines to switch > implementation by ifdefs. But C++ enum would work well if we implement > things and switch by it.
Sounds like you'd rather do that separately? Sounds fine, I just figured I would ask! :) Shame that the proposal didn't have a feature test macro so we could conditionally use it when available :(
> I'm not sure how to handle PDP endian (a.k.a. middle endian) in C++17.
Can we just static_assert that we never get such endian? I don't think WebKit supports this type of platform? Otherwise r=me
Yusuke Suzuki
Comment 7
2017-11-18 23:43:01 PST
(In reply to JF Bastien from
comment #6
)
> (In reply to Yusuke Suzuki from
comment #5
) > > (In reply to JF Bastien from
comment #4
) > > > Comment on
attachment 327314
[details]
> > > Patch > > > > > > Do we want something that’ll work with C++17? > > >
http://en.cppreference.com/w/cpp/types/endian
> > > > In our current use cases, we need preprocessor defines to switch > > implementation by ifdefs. But C++ enum would work well if we implement > > things and switch by it. > > Sounds like you'd rather do that separately? Sounds fine, I just figured I > would ask! :) > > Shame that the proposal didn't have a feature test macro so we could > conditionally use it when available :(
Yeah, I think currently using CPU(LITTLE_ENDIAN) / CPU(BIG_ENDIAN) is enough for WebKit. But once C++17 is everywhere, we can consider using std::endian instead in our code base.
> > > I'm not sure how to handle PDP endian (a.k.a. middle endian) in C++17. > > Can we just static_assert that we never get such endian? I don't think > WebKit supports this type of platform? > > Otherwise r=me
Right, I think the current WebKit does not support middle endian well. And I don't think there are any stake holders using middle endian CPUs. I'll add `static_assert(!CPU(MIDDLE_ENDIAN), "");` to ensure this.
Yusuke Suzuki
Comment 8
2017-11-18 23:44:17 PST
(In reply to Yusuke Suzuki from
comment #7
)
> (In reply to JF Bastien from
comment #6
) > > (In reply to Yusuke Suzuki from
comment #5
) > > > (In reply to JF Bastien from
comment #4
) > > > > Comment on
attachment 327314
[details]
> > > > Patch > > > > > > > > Do we want something that’ll work with C++17? > > > >
http://en.cppreference.com/w/cpp/types/endian
> > > > > > In our current use cases, we need preprocessor defines to switch > > > implementation by ifdefs. But C++ enum would work well if we implement > > > things and switch by it. > > > > Sounds like you'd rather do that separately? Sounds fine, I just figured I > > would ask! :) > > > > Shame that the proposal didn't have a feature test macro so we could > > conditionally use it when available :( > > Yeah, I think currently using CPU(LITTLE_ENDIAN) / CPU(BIG_ENDIAN) is enough > for WebKit. But once C++17 is everywhere, we can consider using std::endian > instead in our code base. > > > > > > I'm not sure how to handle PDP endian (a.k.a. middle endian) in C++17. > > > > Can we just static_assert that we never get such endian? I don't think > > WebKit supports this type of platform? > > > > Otherwise r=me > > Right, I think the current WebKit does not support middle endian well. > And I don't think there are any stake holders using middle endian CPUs. > I'll add `static_assert(!CPU(MIDDLE_ENDIAN), "");` to ensure this.
Since it's macro, and we do not want to add any C++ things to Platform.h, I'll insert #if !CPU(LITTLE_ENDIAN) && !CPU(BIG_ENDIAN) #error Unsupported endian #endif
Yusuke Suzuki
Comment 9
2017-11-19 00:07:13 PST
Committed
r225032
: <
https://trac.webkit.org/changeset/225032
>
Radar WebKit Bug Importer
Comment 10
2017-11-19 00:08:28 PST
<
rdar://problem/35635902
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug