-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add type-specialized vectorized hash table container #100386
Changes from all commits
6df2ffc
2f41984
059705b
0017d53
2cc6a91
6cf488d
368c076
ebc7b97
335b32e
12487c8
9bfc7b6
5b8fec5
5408f27
8cbf1db
a3d8622
53ef795
0d57f12
4a194da
e6e29ef
406614b
9c1ed15
69cd351
58045c1
f354798
4fa00c8
48faef8
ab63d5f
ee87e52
bcf8be0
f9db166
8c3efe5
ece1efe
65862c1
0aaffc2
24cf824
5a1af2e
ff3678a
66b8a19
9f15f25
5011da6
0eb125e
fde9544
4949c53
c5ce9b2
f99f2cc
c848322
c1a8001
d4031a1
b00cd4a
24d4b84
df8d8f4
e13f48e
cb2eb95
ef9a132
5923050
099a953
d6f2bb7
6504f19
a47fea2
8fb0a5a
e86c5c4
7b2c15d
c22b3d7
9708bfa
e11fa7d
5525995
3f84231
441079a
480432f
ffbfd0f
1ca0206
4685237
6548031
14155c8
dbad5d6
6ffe793
c3ea833
4169252
338b23c
f17bd49
d62c7c2
31eb0ba
4d0150f
18806f3
27ac09f
39747d0
c11823d
e08be1b
391a5d8
0a1936e
e388a1d
b4d07d7
703a607
73c505d
97a3b25
391fdeb
ae69695
f543c20
07c398b
44a7bd3
9572863
bf03cca
57e6aa2
9107045
3d066cc
06efeeb
8d798f8
253d920
d90828a
5f49036
1f2b89f
5083f40
af63c5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3037,18 +3037,22 @@ mono_image_init_name_cache (MonoImage *image) | |
const char *name; | ||
const char *nspace; | ||
guint32 visib, nspace_index; | ||
GHashTable *name_cache2, *nspace_table, *the_name_cache; | ||
dn_simdhash_u32_ptr_t *name_cache2; | ||
dn_simdhash_string_ptr_t *nspace_table, *the_name_cache; | ||
|
||
if (image->name_cache) | ||
return; | ||
|
||
the_name_cache = g_hash_table_new (g_str_hash, g_str_equal); | ||
// TODO: Figure out a good initial capacity for this table by doing a scan, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can estimate a very good guess for corelib (by the time this is first called, I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense. I suspect the current default (11-12 items) might be right for smaller images |
||
// or just pre-reserve a reasonable amount of space based on how many nspaces | ||
// an image typically has | ||
the_name_cache = dn_simdhash_string_ptr_new (0, NULL); | ||
|
||
if (image_is_dynamic (image)) { | ||
mono_image_lock (image); | ||
if (image->name_cache) { | ||
/* Somebody initialized it before us */ | ||
g_hash_table_destroy (the_name_cache); | ||
dn_simdhash_free (the_name_cache); | ||
} else { | ||
mono_atomic_store_release (&image->name_cache, the_name_cache); | ||
} | ||
|
@@ -3057,7 +3061,7 @@ mono_image_init_name_cache (MonoImage *image) | |
} | ||
|
||
/* Temporary hash table to avoid lookups in the nspace_table */ | ||
name_cache2 = g_hash_table_new (NULL, NULL); | ||
name_cache2 = dn_simdhash_u32_ptr_new (0, NULL); | ||
|
||
/* FIXME: metadata-update */ | ||
int rows = table_info_get_rows (t); | ||
|
@@ -3074,14 +3078,13 @@ mono_image_init_name_cache (MonoImage *image) | |
nspace = mono_metadata_string_heap (image, cols [MONO_TYPEDEF_NAMESPACE]); | ||
|
||
nspace_index = cols [MONO_TYPEDEF_NAMESPACE]; | ||
nspace_table = (GHashTable *)g_hash_table_lookup (name_cache2, GUINT_TO_POINTER (nspace_index)); | ||
if (!nspace_table) { | ||
nspace_table = g_hash_table_new (g_str_hash, g_str_equal); | ||
g_hash_table_insert (the_name_cache, (char*)nspace, nspace_table); | ||
g_hash_table_insert (name_cache2, GUINT_TO_POINTER (nspace_index), | ||
nspace_table); | ||
if (!dn_simdhash_u32_ptr_try_get_value (name_cache2, nspace_index, (void **)&nspace_table)) { | ||
// FIXME: Compute an appropriate capacity for this table to avoid growing it | ||
nspace_table = dn_simdhash_string_ptr_new (0, NULL); | ||
dn_simdhash_string_ptr_try_add (the_name_cache, nspace, nspace_table); | ||
dn_simdhash_u32_ptr_try_add (name_cache2, nspace_index, nspace_table); | ||
} | ||
g_hash_table_insert (nspace_table, (char *) name, GUINT_TO_POINTER (i)); | ||
dn_simdhash_string_ptr_try_add (nspace_table, name, GUINT_TO_POINTER (i)); | ||
} | ||
|
||
/* Load type names from EXPORTEDTYPES table */ | ||
|
@@ -3102,23 +3105,22 @@ mono_image_init_name_cache (MonoImage *image) | |
nspace = mono_metadata_string_heap (image, exptype_cols [MONO_EXP_TYPE_NAMESPACE]); | ||
|
||
nspace_index = exptype_cols [MONO_EXP_TYPE_NAMESPACE]; | ||
nspace_table = (GHashTable *)g_hash_table_lookup (name_cache2, GUINT_TO_POINTER (nspace_index)); | ||
if (!nspace_table) { | ||
nspace_table = g_hash_table_new (g_str_hash, g_str_equal); | ||
g_hash_table_insert (the_name_cache, (char*)nspace, nspace_table); | ||
g_hash_table_insert (name_cache2, GUINT_TO_POINTER (nspace_index), | ||
nspace_table); | ||
if (!dn_simdhash_u32_ptr_try_get_value (name_cache2, nspace_index, (void **)&nspace_table)) { | ||
// FIXME: Compute an appropriate capacity for this table to avoid growing it | ||
nspace_table = dn_simdhash_string_ptr_new (0, NULL); | ||
dn_simdhash_string_ptr_try_add (the_name_cache, nspace, nspace_table); | ||
dn_simdhash_u32_ptr_try_add (name_cache2, nspace_index, nspace_table); | ||
} | ||
g_hash_table_insert (nspace_table, (char *) name, GUINT_TO_POINTER (mono_metadata_make_token (MONO_TABLE_EXPORTEDTYPE, i + 1))); | ||
dn_simdhash_string_ptr_try_add (nspace_table, name, GUINT_TO_POINTER (mono_metadata_make_token (MONO_TABLE_EXPORTEDTYPE, i + 1))); | ||
} | ||
} | ||
|
||
g_hash_table_destroy (name_cache2); | ||
dn_simdhash_free (name_cache2); | ||
|
||
mono_image_lock (image); | ||
if (image->name_cache) { | ||
/* Somebody initialized it before us */ | ||
g_hash_table_destroy (the_name_cache); | ||
dn_simdhash_free (the_name_cache); | ||
} else { | ||
mono_atomic_store_release (&image->name_cache, the_name_cache); | ||
} | ||
|
@@ -3133,23 +3135,19 @@ void | |
mono_image_add_to_name_cache (MonoImage *image, const char *nspace, | ||
const char *name, guint32 index) | ||
{ | ||
GHashTable *nspace_table; | ||
GHashTable *name_cache; | ||
guint32 old_index; | ||
dn_simdhash_string_ptr_t *nspace_table, *name_cache; | ||
|
||
mono_image_init_name_cache (image); | ||
mono_image_lock (image); | ||
|
||
name_cache = image->name_cache; | ||
if (!(nspace_table = (GHashTable *)g_hash_table_lookup (name_cache, nspace))) { | ||
nspace_table = g_hash_table_new (g_str_hash, g_str_equal); | ||
g_hash_table_insert (name_cache, (char *)nspace, (char *)nspace_table); | ||
if (!dn_simdhash_string_ptr_try_get_value (name_cache, nspace, (void **)&nspace_table)) { | ||
nspace_table = dn_simdhash_string_ptr_new (0, NULL); | ||
dn_simdhash_string_ptr_try_add (name_cache, nspace, nspace_table); | ||
} | ||
|
||
if ((old_index = GPOINTER_TO_UINT (g_hash_table_lookup (nspace_table, (char*) name)))) | ||
g_error ("overrwritting old token %x on image %s for type %s::%s", old_index, image->name, nspace, name); | ||
|
||
g_hash_table_insert (nspace_table, (char *) name, GUINT_TO_POINTER (index)); | ||
if (!dn_simdhash_string_ptr_try_add (nspace_table, name, GUINT_TO_POINTER (index))) | ||
g_error ("overrwritting old token ? on image %s for type %s::%s", image->name, nspace, name); | ||
|
||
mono_image_unlock (image); | ||
} | ||
|
@@ -3160,9 +3158,8 @@ typedef struct { | |
} FindAllUserData; | ||
|
||
static void | ||
find_all_nocase (gpointer key, gpointer value, gpointer user_data) | ||
find_all_nocase (const char *name, gpointer value, gpointer user_data) | ||
{ | ||
char *name = (char*)key; | ||
FindAllUserData *data = (FindAllUserData*)user_data; | ||
if (mono_utf8_strcasecmp (name, (char*)data->key) == 0) | ||
data->values = g_slist_prepend (data->values, value); | ||
|
@@ -3174,9 +3171,8 @@ typedef struct { | |
} FindUserData; | ||
|
||
static void | ||
find_nocase (gpointer key, gpointer value, gpointer user_data) | ||
find_nocase (const char *name, gpointer value, gpointer user_data) | ||
{ | ||
char *name = (char*)key; | ||
FindUserData *data = (FindUserData*)user_data; | ||
|
||
if (!data->value && (mono_utf8_strcasecmp (name, (char*)data->key) == 0)) | ||
|
@@ -3303,7 +3299,7 @@ search_modules (MonoImage *image, const char *name_space, const char *name, gboo | |
static MonoClass * | ||
mono_class_from_name_checked_aux (MonoImage *image, const char* name_space, const char *name, GHashTable* visited_images, gboolean case_sensitive, MonoError *error) | ||
{ | ||
GHashTable *nspace_table = NULL; | ||
dn_simdhash_string_ptr_t *nspace_table = NULL; | ||
MonoImage *loaded_image = NULL; | ||
guint32 token = 0; | ||
MonoClass *klass; | ||
|
@@ -3350,23 +3346,24 @@ mono_class_from_name_checked_aux (MonoImage *image, const char* name_space, cons | |
mono_image_lock (image); | ||
|
||
if (case_sensitive) { | ||
nspace_table = (GHashTable *)g_hash_table_lookup (image->name_cache, name_space); | ||
|
||
if (nspace_table) | ||
token = GPOINTER_TO_UINT (g_hash_table_lookup (nspace_table, name)); | ||
if (dn_simdhash_string_ptr_try_get_value (image->name_cache, name_space, (void **)&nspace_table)) { | ||
void * temp; | ||
if (dn_simdhash_string_ptr_try_get_value (nspace_table, name, &temp)) | ||
token = GPOINTER_TO_UINT(temp); | ||
} | ||
} else { | ||
FindAllUserData all_user_data = { name_space, NULL }; | ||
FindUserData user_data = { name, NULL }; | ||
GSList *values; | ||
|
||
// We're forced to check all matching namespaces, not just the first one found, | ||
// because our desired type could be in any of the ones that match case-insensitively. | ||
g_hash_table_foreach (image->name_cache, find_all_nocase, &all_user_data); | ||
dn_simdhash_string_ptr_foreach (image->name_cache, find_all_nocase, &all_user_data); | ||
|
||
values = all_user_data.values; | ||
while (values && !user_data.value) { | ||
nspace_table = (GHashTable*)values->data; | ||
g_hash_table_foreach (nspace_table, find_nocase, &user_data); | ||
nspace_table = (dn_simdhash_string_ptr_t *)values->data; | ||
dn_simdhash_string_ptr_foreach (nspace_table, find_nocase, &user_data); | ||
values = values->next; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kg I /think/ just using
set_source_file_properties
to set compile flags would work:under the appropriate
if()/endif()
.It's possible this won't work if we're doing something weird with paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is we need to conditionally build with/without simd based on the msbuild property. Right now that's handled by building simd and non simd modules that get linked in dynamically at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, sorry, I misunderstood what you're doing. I thought this was predicated on requiring simd support in all wasm builds.
If you need conditional builds, you will need to create two separate
.a
files for the whole runtime (or maybe just two different .a files for anything that depends on the hash containers) and then letting the logic insrc/mono/wasm/build
select which one to link in.conceptually our build here is:
dotnet.native.wasm
for users who don't need to do native compilation on their dev machinesIf you need step 3 or step 2 to do different things based on msbuild properties, but you need to choose different outputs from step 1, then step 1 needs to produce multiple artifacts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think we could move the hash containers and stuff into their own object that gets linked late? i tried putting these things in our existing simd/no-simd objects, but i got link errors earlier in the build because it seems like we have a linking tree, i.e.
ab = a + b
cd = c + d
mono-sgen = ab + cd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be possible to build the hash containers in their own object library (modulo anything inlined in headers). I suspect it wouldn't work if you just do it in src/native/containers but src/mono/mono could probably do something.