Mercurial > hg > Game > Cerium
annotate TaskManager/kernel/memory/MemHash.cc @ 1546:61164c687b29 draft
fix GpuScheduler flip
author | Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 05 Feb 2013 13:15:46 +0900 |
parents | 801d57ae1e29 |
children |
rev | line source |
---|---|
1142
801d57ae1e29
cut compile CreatePolygonTask on spe side because not enough spe memory. We have to use code loading.
yutaka@localhost.localdomain
parents:
1132
diff
changeset
|
1 //#include <stdio.h> |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
2 #include <string.h> |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
3 #include <stdlib.h> |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
4 #include "MemHash.h" |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
5 |
874 | 6 unsigned int |
7 MemHash::hash(memaddr data0) | |
8 { | |
9 unsigned long data = (unsigned long)data0; | |
10 #if ABIBIT>32 | |
1123 | 11 int i_PeRlHaSh = 8; |
874 | 12 #else |
1123 | 13 int i_PeRlHaSh = 4; |
874 | 14 #endif |
1123 | 15 uint32 hash_PeRlHaSh = 0; |
874 | 16 while (i_PeRlHaSh--) { |
17 hash_PeRlHaSh += data & 0xff; | |
18 hash_PeRlHaSh += (hash_PeRlHaSh << 10); | |
19 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); | |
20 data >>= 8; | |
21 } | |
22 hash_PeRlHaSh += (hash_PeRlHaSh << 3); | |
23 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); | |
24 return (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); | |
25 } | |
26 | |
27 #if 0 | |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
28 static unsigned short PRIME[8] = { |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
29 0x002, 0x065, 0x0c7, 0x133, 0x191, 0x1f3, 0x259, 0x2bd, |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
30 }; |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
31 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
32 int |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
388
diff
changeset
|
33 MemHash::hash(memaddr data0) |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
34 { |
873
c50f39fbb6ca
fix hash problem ( unsigned int-> long overflow )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
625
diff
changeset
|
35 unsigned long data = (unsigned long)data0; |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
36 int value = 0; |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
37 int n = 0; |
625
94d82f2c842f
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
388
diff
changeset
|
38 long key; |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
39 |
380 | 40 for (uint32 i = 0; i < sizeof(memaddr) * 2; i ++) { |
352 | 41 key = data & 0xf; |
380 | 42 value += key * PRIME[n++ & 7]; |
352 | 43 data >>= 4; |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
44 } |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
45 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
46 return value % hashSize; |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
47 } |
874 | 48 #endif |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
49 |
388
3d1e86396d16
MemHash (OS X version)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
387
diff
changeset
|
50 MemHash::MemHash() |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
51 { |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
52 table = (MemorySegmentPtr*)malloc(tableSize); |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
53 clear(); |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
54 } |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
55 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
56 int |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
57 MemHash::put(memaddr key, MemorySegmentPtr data) |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
58 { |
1123 | 59 unsigned int hashval = hash(key); |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
60 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
61 for (int i = 0; i < hashSize/2; i++) { |
1132 | 62 unsigned int index = (hashval + i)%hashSize; |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
63 |
352 | 64 if (table[index] == 0) { // 空の table に入れる |
65 table[index] = data; | |
66 return index; | |
67 } | |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
68 } |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
69 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
70 return -1; |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
71 } |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
72 |
1123 | 73 |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
74 MemorySegmentPtr |
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
75 MemHash::get(memaddr key) |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
76 { |
878 | 77 unsigned int hashval = hash(key); |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
78 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
79 for (int i = 0; i < hashSize/2; i++) { |
1132 | 80 unsigned int index = (hashval + i)%hashSize; |
352 | 81 |
82 if (table[index] != NULL && | |
380 | 83 table[index]->address == key) { |
352 | 84 return table[index]; |
85 } | |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
86 } |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
87 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
88 return NULL; |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
89 } |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
90 |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
91 void |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
92 MemHash::remove(memaddr key) |
173 | 93 { |
878 | 94 unsigned int hashval = hash(key); |
173 | 95 |
96 for (int i = 0; i < hashSize/2; i++) { | |
1132 | 97 int index = (hashval + i)%hashSize; |
352 | 98 |
99 if (table[index] != NULL && | |
380 | 100 table[index]->address == key) { |
352 | 101 table[index] = NULL; |
102 } | |
173 | 103 } |
104 } | |
105 | |
106 void | |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
107 MemHash::clear(void) |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
108 { |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
109 bzero(table, tableSize); |
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff
changeset
|
110 } |
383
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
111 |
b3fb0013e6b2
fix header, MemHash in kernel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
380
diff
changeset
|
112 /* end */ |