RESOLVED FIXED 211328
Allow Bitmap to use up to a UCPURegister word size for internal bit storage.
https://bugs.webkit.org/show_bug.cgi?id=211328
Summary Allow Bitmap to use up to a UCPURegister word size for internal bit storage.
Mark Lam
Reported 2020-05-01 18:58:08 PDT
Previously, it was fixed at uint32_t. This patch also allows it to use smaller ints (uint8_t, and uint16_t) if they will suffice.
Attachments
proposed patch. (7.92 KB, patch)
2020-05-01 19:21 PDT, Mark Lam
no flags
proposed patch. (8.16 KB, patch)
2020-05-01 19:30 PDT, Mark Lam
no flags
proposed patch. (8.58 KB, patch)
2020-05-01 19:39 PDT, Mark Lam
ysuzuki: review+
patch for landing. (8.16 KB, patch)
2020-05-01 22:51 PDT, Mark Lam
no flags
proposed patch. (58.40 KB, patch)
2020-05-04 23:06 PDT, Mark Lam
no flags
proposed patch w/ Win build fixes. (58.40 KB, patch)
2020-05-04 23:44 PDT, Mark Lam
ysuzuki: review+
patch for landing. (59.03 KB, patch)
2020-05-05 00:25 PDT, Mark Lam
no flags
patch for landing. (59.03 KB, patch)
2020-05-05 08:41 PDT, Mark Lam
no flags
Radar WebKit Bug Importer
Comment 1 2020-05-01 18:58:46 PDT
Mark Lam
Comment 2 2020-05-01 19:21:40 PDT
Created attachment 398270 [details] proposed patch.
Mark Lam
Comment 3 2020-05-01 19:30:35 PDT
Created attachment 398271 [details] proposed patch.
Mark Lam
Comment 4 2020-05-01 19:39:16 PDT
Created attachment 398272 [details] proposed patch.
Yusuke Suzuki
Comment 5 2020-05-01 20:03:00 PDT
Comment on attachment 398272 [details] proposed patch. View in context: https://bugs.webkit.org/attachment.cgi?id=398272&action=review r=me > Source/WTF/wtf/Bitmap.h:51 > +template<size_t size, typename = std::true_type> > +struct BitmapWordType { > + using type = UCPURegister; > +}; > + > +template<size_t size> > +struct BitmapWordType<size, std::enable_if_t<(size <= 8), std::true_type>> { > + using type = uint8_t; > +}; > + > +template<size_t size> > +struct BitmapWordType<size, std::enable_if_t<(size > 8 && size <= 16), std::true_type>> { > + using type = uint16_t; > +}; > + > +template<size_t size> > +struct BitmapWordType<size, std::enable_if_t<(size > 16 && size <= 32 && sizeof(UCPURegister) > sizeof(uint32_t)), std::true_type>> { > + using type = uint32_t; > +}; > + > +template<size_t bitmapSize, typename WordType = typename BitmapWordType<bitmapSize>::type> You can use std::conditional<>. template<size_t size> using BitmapWordType = std::conditional_t<size <= 8, uint8_t, std::conditional_t<size <= 16, uint16_t, std::conditional_t<size <= 32 && sizeof(UCPURegister) > sizeof(uint32_t), uint32_t, UCPURegister>>>; And, template<size_t bitmapSize, typename WordType = BitmapWordType<bitmapSize>>
Yusuke Suzuki
Comment 6 2020-05-01 20:08:27 PDT
Also, can you ensure that using `uint8_t`, `uint16_t` is better than using `uint32_t` in ARM etc. in terms of performance? And is it OK to use `uint8_t` and `uint16_t` while Bitmap needs to support concurrentTestAndSet etc.?
Yusuke Suzuki
Comment 7 2020-05-01 20:10:50 PDT
Comment on attachment 398272 [details] proposed patch. View in context: https://bugs.webkit.org/attachment.cgi?id=398272&action=review >> Source/WTF/wtf/Bitmap.h:51 >> +template<size_t bitmapSize, typename WordType = typename BitmapWordType<bitmapSize>::type> > > You can use std::conditional<>. > > template<size_t size> > using BitmapWordType = std::conditional_t<size <= 8, > uint8_t, > std::conditional_t<size <= 16, > uint16_t, > std::conditional_t<size <= 32 && sizeof(UCPURegister) > sizeof(uint32_t), > uint32_t, > UCPURegister>>>; > > And, > > template<size_t bitmapSize, typename WordType = BitmapWordType<bitmapSize>> Because of concurrentTestAndSet etc. I think Bitmap is assuming WordSize for a default type. I think it is better that we just specialize Bitmap with UCPURegister only when we want and keep Bitmap's default parameter `uint32_t`. What do you think of?
Mark Lam
Comment 8 2020-05-01 21:37:10 PDT
(In reply to Yusuke Suzuki from comment #7) > Because of concurrentTestAndSet etc. I think Bitmap is assuming WordSize for > a default type. I think it is better that we just specialize Bitmap with > UCPURegister only when we want and keep Bitmap's default parameter > `uint32_t`. What do you think of? I talked to Yusuke offline. We'll stick with uint32_t for Bitmap of size 32 or under. We'll use UCPURegister for larger bitmaps.
Mark Lam
Comment 9 2020-05-01 22:51:21 PDT
Created attachment 398280 [details] patch for landing.
Mark Lam
Comment 10 2020-05-02 10:01:47 PDT
I can reproduce the editing/undo-manager/undo-manager-delete-stale-undo-items.html failure locally is without my patch. Filed https://bugs.webkit.org/show_bug.cgi?id=211340.
Mark Lam
Comment 11 2020-05-02 10:04:25 PDT
Thanks for the review. Landed in r261050: <http://trac.webkit.org/r261050>.
Mark Lam
Comment 12 2020-05-02 12:08:11 PDT
Landed missing file in r261051: <http://trac.webkit.org/r261051>.
Mark Lam
Comment 13 2020-05-02 14:24:07 PDT
Rolled out in r261055: <http://trac.webkit.org/r261055> while I investigate what's going on with editing/undo-manager/undo-manager-delete-stale-undo-items.html.
Saam Barati
Comment 14 2020-05-03 18:46:11 PDT
Comment on attachment 398280 [details] patch for landing. View in context: https://bugs.webkit.org/attachment.cgi?id=398280&action=review > Source/WTF/wtf/StdIntExtras.h:34 > +#if USE(JSVALUE64) > +using CPURegister = int64_t; > +using UCPURegister = uint64_t; nit: I know this is how things used to be, but it really doesn't feel like this should be keyed of JSVALUE64
Saam Barati
Comment 15 2020-05-03 18:47:08 PDT
Comment on attachment 398280 [details] patch for landing. View in context: https://bugs.webkit.org/attachment.cgi?id=398280&action=review > Source/WTF/wtf/Bitmap.h:33 > +template<size_t size> > +using BitmapWordType = std::conditional_t<(size <= 32 && sizeof(UCPURegister) > sizeof(uint32_t)), uint32_t, UCPURegister>; Why not have this inside the class?
Mark Lam
Comment 16 2020-05-03 18:50:29 PDT
Comment on attachment 398280 [details] patch for landing. View in context: https://bugs.webkit.org/attachment.cgi?id=398280&action=review >> Source/WTF/wtf/Bitmap.h:33 >> +using BitmapWordType = std::conditional_t<(size <= 32 && sizeof(UCPURegister) > sizeof(uint32_t)), uint32_t, UCPURegister>; > > Why not have this inside the class? Because it is used to provide the default type of the BitMap class. Or do you mean why not just use the std::conditional as the default value? Because it is a very long expression, and therefore makes the code less readable. >> Source/WTF/wtf/StdIntExtras.h:34 >> +using UCPURegister = uint64_t; > > nit: I know this is how things used to be, but it really doesn't feel like this should be keyed of JSVALUE64 Got any better suggestions?
Saam Barati
Comment 17 2020-05-04 11:00:33 PDT
Comment on attachment 398280 [details] patch for landing. View in context: https://bugs.webkit.org/attachment.cgi?id=398280&action=review >>> Source/WTF/wtf/Bitmap.h:33 >>> +using BitmapWordType = std::conditional_t<(size <= 32 && sizeof(UCPURegister) > sizeof(uint32_t)), uint32_t, UCPURegister>; >> >> Why not have this inside the class? > > Because it is used to provide the default type of the BitMap class. Or do you mean why not just use the std::conditional as the default value? Because it is a very long expression, and therefore makes the code less readable. I see, sorry. I misread the pre-existing code. >>> Source/WTF/wtf/StdIntExtras.h:34 >>> +using UCPURegister = uint64_t; >> >> nit: I know this is how things used to be, but it really doesn't feel like this should be keyed of JSVALUE64 > > Got any better suggestions? arm64 || x86_64?
Mark Lam
Comment 18 2020-05-04 23:06:38 PDT
Created attachment 398474 [details] proposed patch.
Mark Lam
Comment 19 2020-05-04 23:44:39 PDT
Created attachment 398478 [details] proposed patch w/ Win build fixes.
Yusuke Suzuki
Comment 20 2020-05-04 23:57:19 PDT
Comment on attachment 398474 [details] proposed patch. View in context: https://bugs.webkit.org/attachment.cgi?id=398474&action=review r=me with comment > Source/WTF/wtf/PlatformCPU.h:320 > +/* CPU general purpose register width. */ > +#if CPU(ARM64) || CPU(X86_64) || CPU(MIPS64) || CPU(PPC64) > +#define WTF_CPU_REGISTER64 1 > +#elif CPU(ARM) || CPU(X86) || CPU(MIPS) || CPU(PPC) > +#define WTF_CPU_REGISTER32 1 > +#else > +#error "Unknown register width" This does not work since we support CPU(UNKNOWN) too. I think that REGISTER64 and JSVALUE64 must be the same. If you define REGISTER64 here, I think we should define JSVALUE64 as, #if CPU(REGISTER64) #define WTF_USE_JSVALUE64 ... Can we just define this as, #if !defined(WTF_CPU_REGISTER64) && !defined(WTF_CPU_REGISTER32) #if CPU(ADDRESS64) || CPU(ARM64) #define WTF_CPU_REGISTER64 1 #else #define WTF_CPU_REGISTER32 1 #endif #endif And define USE_JSVALUE64 as, #if CPU(REGISTER64) #define USE_JSVALUE64 #else #define USE_JSVALUE32 #endif
Yusuke Suzuki
Comment 21 2020-05-04 23:58:15 PDT
Comment on attachment 398474 [details] proposed patch. View in context: https://bugs.webkit.org/attachment.cgi?id=398474&action=review >> Source/WTF/wtf/PlatformCPU.h:320 >> +#error "Unknown register width" > > This does not work since we support CPU(UNKNOWN) too. > I think that REGISTER64 and JSVALUE64 must be the same. If you define REGISTER64 here, I think we should define JSVALUE64 as, > > #if CPU(REGISTER64) > #define WTF_USE_JSVALUE64 > ... > > Can we just define this as, > > #if !defined(WTF_CPU_REGISTER64) && !defined(WTF_CPU_REGISTER32) > #if CPU(ADDRESS64) || CPU(ARM64) > #define WTF_CPU_REGISTER64 1 > #else > #define WTF_CPU_REGISTER32 1 > #endif > #endif > > And define USE_JSVALUE64 as, > > #if CPU(REGISTER64) > #define USE_JSVALUE64 > #else > #define USE_JSVALUE32 > #endif #if CPU(REGISTER64) #define USE_JSVALUE64 1 #else #define USE_JSVALUE32 1 #endif
Mark Lam
Comment 22 2020-05-05 00:25:07 PDT
Created attachment 398484 [details] patch for landing. Thanks for the review. I've applied the suggested change to the definition of CPU(REGISTER64) and CPU(REGISTER32).
Mark Lam
Comment 23 2020-05-05 08:41:53 PDT
Created attachment 398512 [details] patch for landing.
Mark Lam
Comment 24 2020-05-05 10:09:17 PDT
Note You need to log in before you can comment on or make changes to this bug.