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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
6 unsigned int
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
7 MemHash::hash(memaddr data0)
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
8 {
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
9 unsigned long data = (unsigned long)data0;
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
10 #if ABIBIT>32
1123
2a63ba2c9506 bug fix.
yutaka@localhost.localdomain
parents: 878
diff changeset
11 int i_PeRlHaSh = 8;
874
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
12 #else
1123
2a63ba2c9506 bug fix.
yutaka@localhost.localdomain
parents: 878
diff changeset
13 int i_PeRlHaSh = 4;
874
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
14 #endif
1123
2a63ba2c9506 bug fix.
yutaka@localhost.localdomain
parents: 878
diff changeset
15 uint32 hash_PeRlHaSh = 0;
874
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
16 while (i_PeRlHaSh--) {
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
17 hash_PeRlHaSh += data & 0xff;
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
18 hash_PeRlHaSh += (hash_PeRlHaSh << 10);
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
19 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6);
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
20 data >>= 8;
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
21 }
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
22 hash_PeRlHaSh += (hash_PeRlHaSh << 3);
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
23 hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11);
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
24 return (hash_PeRlHaSh + (hash_PeRlHaSh << 15));
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
25 }
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
26
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
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
fcd53a8b777c ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
40 for (uint32 i = 0; i < sizeof(memaddr) * 2; i ++) {
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
41 key = data & 0xf;
380
fcd53a8b777c ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
42 value += key * PRIME[n++ & 7];
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
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
188e8bc16aca new hash function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 873
diff changeset
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
2a63ba2c9506 bug fix.
yutaka@localhost.localdomain
parents: 878
diff changeset
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
4f16fad0dd09 Open hash fix. i*i -> i.
yutaka@localhost.localdomain
parents: 1123
diff changeset
62 unsigned int index = (hashval + i)%hashSize;
167
508beb59e0eb DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
diff changeset
63
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
64 if (table[index] == 0) { // 空の table に入れる
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
65 table[index] = data;
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
66 return index;
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
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
2a63ba2c9506 bug fix.
yutaka@localhost.localdomain
parents: 878
diff changeset
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
2919078d069f hash bug fixed(?)
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 874
diff changeset
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
4f16fad0dd09 Open hash fix. i*i -> i.
yutaka@localhost.localdomain
parents: 1123
diff changeset
80 unsigned int index = (hashval + i)%hashSize;
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
81
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
82 if (table[index] != NULL &&
380
fcd53a8b777c ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
83 table[index]->address == key) {
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
84 return table[index];
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
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
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
93 {
878
2919078d069f hash bug fixed(?)
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 874
diff changeset
94 unsigned int hashval = hash(key);
173
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
95
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
96 for (int i = 0; i < hashSize/2; i++) {
1132
4f16fad0dd09 Open hash fix. i*i -> i.
yutaka@localhost.localdomain
parents: 1123
diff changeset
97 int index = (hashval + i)%hashSize;
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
98
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
99 if (table[index] != NULL &&
380
fcd53a8b777c ps3 fix
e065701@localhost.localdomain
parents: 352
diff changeset
100 table[index]->address == key) {
352
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
101 table[index] = NULL;
9738837c225c add global_alloc.h
admin@mb22-no-macbook-2.local
parents: 210
diff changeset
102 }
173
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
103 }
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
104 }
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
105
1e62bd02f820 add scale
gongo@localhost.localdomain
parents: 167
diff changeset
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 */