Bug 188716 - [WTF] Add WTF::unalignedLoad and WTF::unalignedStore
Summary: [WTF] Add WTF::unalignedLoad and WTF::unalignedStore
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-08-17 19:04 PDT by Yusuke Suzuki
Modified: 2018-08-20 20:38 PDT (History)
6 users (show)

See Also:


Attachments
Patch (10.39 KB, patch)
2018-08-17 19:10 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (12.75 KB, patch)
2018-08-17 19:18 PDT, Yusuke Suzuki
no flags Details | Formatted Diff | Diff
Patch (17.97 KB, patch)
2018-08-19 01:21 PDT, Yusuke Suzuki
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2018-08-17 19:04:26 PDT
[WTF] Add WTF::unalignedLoad and WTF::unalignedStore
Comment 1 Yusuke Suzuki 2018-08-17 19:10:40 PDT
Created attachment 347421 [details]
Patch
Comment 2 Yusuke Suzuki 2018-08-17 19:18:59 PDT
Created attachment 347423 [details]
Patch
Comment 3 Yusuke Suzuki 2018-08-19 01:21:51 PDT
Created attachment 347455 [details]
Patch
Comment 4 Darin Adler 2018-08-19 12:24:36 PDT
Comment on attachment 347455 [details]
Patch

How close does this put us to removing reinterpret_cast_ptr?
Comment 5 Yusuke Suzuki 2018-08-19 15:42:00 PDT
(In reply to Darin Adler from comment #4)
> Comment on attachment 347455 [details]
> Patch
> 
> How close does this put us to removing reinterpret_cast_ptr?

Nice catch. Currently, `reinterpret_cast_ptr<T>(ptr)` is used only when we ensure that the casted `ptr` has the expected alignment by `T`. It would be optimized way with CPUs without unaligned accesses support. But since the major CPUs like ARM64, X86, and X86_64 support unaligned accesses, always using `WTF::unalignedXXX` would be feasible. We should investigate each site of `reinterpret_cast_ptr` carefully to decide whether we can replace it with unalignedXXX helpers!
Comment 6 Yusuke Suzuki 2018-08-19 15:50:11 PDT
Committed r235018: <https://trac.webkit.org/changeset/235018>
Comment 7 Fujii Hironori 2018-08-20 06:58:37 PDT
I'm surprised. There are so many unaligned access.
I thought unaligned memory access is slow.
See https://github.com/spotify/linux/blob/master/Documentation/unaligned-memory-access.txt

Are they really unaligned memory access? Or, actually aligned?
Comment 8 Radar WebKit Bug Importer 2018-08-20 16:52:06 PDT
<rdar://problem/43534448>
Comment 9 Yusuke Suzuki 2018-08-20 20:38:26 PDT
(In reply to Fujii Hironori from comment #7)
> I'm surprised. There are so many unaligned access.
> I thought unaligned memory access is slow.
> See
> https://github.com/spotify/linux/blob/master/Documentation/unaligned-memory-
> access.txt
> 
> Are they really unaligned memory access? Or, actually aligned?

Unaligned accesses reported by UBSan. They are typically filling/extracting an value into/from X86 machine code stream.