projects
/
YACASL2.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e24285f
)
命令ハッシュ表周辺の調整
author
j8takagi
<j8takagi@nifty.com>
Sun, 28 Feb 2010 07:54:57 +0000
(16:54 +0900)
committer
j8takagi
<j8takagi@nifty.com>
Sun, 28 Feb 2010 07:56:50 +0000
(16:56 +0900)
実験の結果、命令ハッシュ表のサイズはcmdcodesize(=38)
include/casl2.h
patch
|
blob
|
history
include/hash.h
patch
|
blob
|
history
src/cmd.c
patch
|
blob
|
history
src/exec.c
patch
|
blob
|
history
src/hash.c
patch
|
blob
|
history
test/unit/hash/0.txt
patch
|
blob
|
history
test/unit/print_cmdtype_code/print_cmdtype_code.c
patch
|
blob
|
history
test/unit/print_cmdtype_code_hash/print_cmdtype_code.c
patch
|
blob
|
history
test/unit/print_code_type/print_code_type.c
patch
|
blob
|
history
test/unit/print_code_type_hash/print_code_type.c
patch
|
blob
|
history
diff --git
a/include/casl2.h
b/include/casl2.h
index
23607fd
..
9a2fc07
100644
(file)
--- a/
include/casl2.h
+++ b/
include/casl2.h
@@
-95,6
+95,7
@@
typedef struct _CMDCODETAB {
extern CMDCODETAB **cmdtype_code;
extern CMDCODETAB **code_type;
extern CMDCODETAB **cmdtype_code;
extern CMDCODETAB **code_type;
+extern int cmdtabsize;
/* 命令と命令タイプがキーのハッシュ表を作成する */
bool create_cmdtype_code();
/* 命令と命令タイプがキーのハッシュ表を作成する */
bool create_cmdtype_code();
diff --git
a/include/hash.h
b/include/hash.h
index
9821b44
..
caac5f1
100644
(file)
--- a/
include/hash.h
+++ b/
include/hash.h
@@
-1,6
+1,10
@@
#ifndef YACASL2_HASH_INCLUDED
#define YACASL2_HASH_INCLUDED
#ifndef YACASL2_HASH_INCLUDED
#define YACASL2_HASH_INCLUDED
+#ifndef ARRAYSIZE
+#define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
+#endif
+
/* ハッシュ共用体の型 */
typedef enum {
CHARS = 0,
/* ハッシュ共用体の型 */
typedef enum {
CHARS = 0,
@@
-16,6
+20,9
@@
typedef struct {
} val;
} HKEY;
} val;
} HKEY;
+/* ハッシュ表のサイズを決めるため、引数の数値未満で最大の素数を返す */
+int hashtabsize(int size);
+
/* ハッシュ値を取得する */
unsigned hash(int keyc, HKEY *keyv[], int tabsize);
/* ハッシュ値を取得する */
unsigned hash(int keyc, HKEY *keyv[], int tabsize);
diff --git
a/src/cmd.c
b/src/cmd.c
index
7c1e803
..
6bb749f
100644
(file)
--- a/
src/cmd.c
+++ b/
src/cmd.c
@@
-42,7
+42,7
@@
CMDCODEARRAY cmdcodearray[] = {
};
int cmdcodesize = ARRAYSIZE(cmdcodearray);
};
int cmdcodesize = ARRAYSIZE(cmdcodearray);
-int
hash
tabsize;
+int
cmd
tabsize;
CMDCODETAB **cmdtype_code, **code_type;
/* 命令と命令タイプからハッシュ値を生成する */
CMDCODETAB **cmdtype_code, **code_type;
/* 命令と命令タイプからハッシュ値を生成する */
@@
-58,7
+58,7
@@
unsigned hash_cmdtype(const char *cmd, CMDTYPE type) {
keys[1]->type = INT;
keys[1]->val.i = (int)(type & 070);
/* ハッシュ値を返す */
keys[1]->type = INT;
keys[1]->val.i = (int)(type & 070);
/* ハッシュ値を返す */
- return hash(2, keys, cmd
code
size);
+ return hash(2, keys, cmd
tab
size);
}
/* 命令と命令タイプがキーのハッシュ表を作成する */
}
/* 命令と命令タイプがキーのハッシュ表を作成する */
@@
-68,8
+68,8
@@
bool create_cmdtype_code()
unsigned hashval;
int i;
unsigned hashval;
int i;
-
hash
tabsize = cmdcodesize;
- cmdtype_code = malloc(cmd
code
size * sizeof(CMDCODETAB *));
+
cmd
tabsize = cmdcodesize;
+ cmdtype_code = malloc(cmd
tab
size * sizeof(CMDCODETAB *));
for(i = 0; i < cmdcodesize; i++) {
np = malloc(sizeof(CMDCODETAB));
if(np == NULL) {
for(i = 0; i < cmdcodesize; i++) {
np = malloc(sizeof(CMDCODETAB));
if(np == NULL) {
@@
-105,7
+105,7
@@
void free_cmdtype_code()
{
int i;
CMDCODETAB *np, *nq;
{
int i;
CMDCODETAB *np, *nq;
- for(i = 0; i < cmd
code
size; i++){
+ for(i = 0; i < cmd
tab
size; i++){
np = cmdtype_code[i];
while(np != NULL) {
nq = np->next;
np = cmdtype_code[i];
while(np != NULL) {
nq = np->next;
@@
-125,7
+125,7
@@
unsigned hash_code(WORD code)
keys[0]->type = INT;
keys[0]->val.i = (int)(code >> 8);
/* ハッシュ値を返す */
keys[0]->type = INT;
keys[0]->val.i = (int)(code >> 8);
/* ハッシュ値を返す */
- return hash(1, keys, cmd
code
size);
+ return hash(1, keys, cmd
tab
size);
}
/* 命令コードがキーのハッシュ表を作成する */
}
/* 命令コードがキーのハッシュ表を作成する */
@@
-135,8
+135,8
@@
bool create_code_type()
unsigned hashval;
int i;
unsigned hashval;
int i;
-
hashtabsize = cmdcodesize
;
- code_type = malloc(cmd
code
size * sizeof(CMDCODETAB *));
+
cmdtabsize = hashtabsize(cmdcodesize)
;
+ code_type = malloc(cmd
tab
size * sizeof(CMDCODETAB *));
for(i = 0; i < cmdcodesize; i++) {
if((np = malloc(sizeof(CMDCODETAB))) == NULL) {
setcerr(122, NULL); /* cannot create hash table */
for(i = 0; i < cmdcodesize; i++) {
if((np = malloc(sizeof(CMDCODETAB))) == NULL) {
setcerr(122, NULL); /* cannot create hash table */
@@
-170,7
+170,7
@@
void free_code_type()
{
int i;
CMDCODETAB *np, *nq;
{
int i;
CMDCODETAB *np, *nq;
- for(i = 0; i < cmd
code
size; i++){
+ for(i = 0; i < cmd
tab
size; i++){
np = code_type[i];
while(np != NULL) {
nq = np->next;
np = code_type[i];
while(np != NULL) {
nq = np->next;
diff --git
a/src/exec.c
b/src/exec.c
index
3e4b1b9
..
17ac66b
100644
(file)
--- a/
src/exec.c
+++ b/
src/exec.c
@@
-264,7
+264,7
@@
void reset()
}
}
}
}
-/*
コード
の実行 */
+/*
仮想マシンCOMET IIで
の実行 */
void exec()
{
WORD op, r_r1, x_r2, val;
void exec()
{
WORD op, r_r1, x_r2, val;
@@
-272,7
+272,7
@@
void exec()
char *errpr = malloc(CERRSTRSIZE + 1);
clock_t clock_begin, clock_end;
char *errpr = malloc(CERRSTRSIZE + 1);
clock_t clock_begin, clock_end;
- if(
(&execmode)->
trace) {
+ if(
execmode.
trace) {
fprintf(stdout, "\nExecuting machine codes\n");
}
/* フラグレジスタの初期値設定 */
fprintf(stdout, "\nExecuting machine codes\n");
}
/* フラグレジスタの初期値設定 */
@@
-300,7
+300,9
@@
void exec()
sprintf(errpr, "PR:#%04X", PR);
setcerr(205, errpr); /* Stack Pointer (SP) - cannot allocate stack buffer */
}
sprintf(errpr, "PR:#%04X", PR);
setcerr(205, errpr); /* Stack Pointer (SP) - cannot allocate stack buffer */
}
+ /* 命令の取り出し */
op = memory[PR] & 0xFF00;
op = memory[PR] & 0xFF00;
+ /* 命令の解読 */
cmdtype = getcmdtype(op);
r_r1 = (memory[PR] >> 4) & 0xF;
x_r2 = memory[PR] & 0xF;
cmdtype = getcmdtype(op);
r_r1 = (memory[PR] >> 4) & 0xF;
x_r2 = memory[PR] & 0xF;
@@
-308,19
+310,19
@@
void exec()
if(cerrno > 0) {
goto execerr;
}
if(cerrno > 0) {
goto execerr;
}
- if(
(&execmode)->
trace){
+ if(
execmode.
trace){
fprintf(stdout, "#%04X: Register::::\n", PR);
dspregister();
}
fprintf(stdout, "#%04X: Register::::\n", PR);
dspregister();
}
- if(
(&execmode)->
dump){
+ if(
execmode.
dump){
fprintf(stdout, "#%04X: Memory::::\n", PR);
dumpmemory();
}
fprintf(stdout, "#%04X: Memory::::\n", PR);
dumpmemory();
}
- if(
(&execmode)->dump || (&execmode)->
trace) {
+ if(
execmode.dump || execmode.
trace) {
fprintf(stdout, "\n");
}
PR++;
fprintf(stdout, "\n");
}
PR++;
- /*
å
\87
¦ç
\90
\86
対象ã
\81
®å
\80
¤ã
\82
\92
å
\8f
\96
å¾
\97
*/
+ /*
ã
\82
ªã
\83
\9a
ã
\83
©ã
\83
³ã
\83
\89
ã
\81
®å
\8f
\96
ã
\82
\8a
å
\87
ºã
\81
\97
*/
if(cmdtype == R1_R2) {
assert(x_r2 < REGSIZE);
val = GR[x_r2];
if(cmdtype == R1_R2) {
assert(x_r2 < REGSIZE);
val = GR[x_r2];
@@
-346,7
+348,7
@@
void exec()
if(op >= 0x1000 && op <= 0x4FFF) {
op &= 0xFB00;
}
if(op >= 0x1000 && op <= 0x4FFF) {
op &= 0xFB00;
}
- /* å
\91
½ä»¤ã
\81
\94
ã
\81
¨ã
\81
®å
\87
¦ç
\90
\86
ã
\82
\92
実行 */
+ /* å
\91
½ä»¤ã
\81
®
実行 */
switch(op)
{
case 0x0: /* NOP */
switch(op)
{
case 0x0: /* NOP */
diff --git
a/src/hash.c
b/src/hash.c
index
54f38ab
..
f63b3f5
100644
(file)
--- a/
src/hash.c
+++ b/
src/hash.c
@@
-1,5
+1,22
@@
#include "hash.h"
#include "hash.h"
+/* ハッシュ表のサイズを決めるため、引数の数値より大きい最小の素数を返す */
+int hashtabsize(int size)
+{
+ int i;
+ const int prime[] =
+ {2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
+ 31, 37, 41, 43, 47, 53, 59, 61, 67,
+ 71, 73, 79, 83, 89, 97,
+ };
+ for(i = 0; i < ARRAYSIZE(prime); i++) {
+ if(i > 0 && prime[i] >= size) {
+ break;
+ }
+ }
+ return prime[i];
+}
+
/* ハッシュ値を取得する */
unsigned hash(int keyc, HKEY *keyv[], int tabsize)
{
/* ハッシュ値を取得する */
unsigned hash(int keyc, HKEY *keyv[], int tabsize)
{
diff --git
a/test/unit/hash/0.txt
b/test/unit/hash/0.txt
index
f21e3f4
..
bc8892a
100644
(file)
--- a/
test/unit/hash/0.txt
+++ b/
test/unit/hash/0.txt
@@
-1,3
+1,3
@@
HASH VALUE: 20
HASH VALUE: 11
HASH VALUE: 20
HASH VALUE: 11
-HASH VALUE:
1
+HASH VALUE:
2
diff --git
a/test/unit/print_cmdtype_code/print_cmdtype_code.c
b/test/unit/print_cmdtype_code/print_cmdtype_code.c
index
a2dcf86
..
bb31614
100644
(file)
--- a/
test/unit/print_cmdtype_code/print_cmdtype_code.c
+++ b/
test/unit/print_cmdtype_code/print_cmdtype_code.c
@@
-21,7
+21,7
@@
void print_cmdtype_code()
CMDCODETAB *np;
CMDCODEARRAY **ar;
ar = malloc(sizeof(*ar) * cmdcodesize);
CMDCODETAB *np;
CMDCODEARRAY **ar;
ar = malloc(sizeof(*ar) * cmdcodesize);
- for(i = 0; i < cmd
code
size; i++) {
+ for(i = 0; i < cmd
tab
size; i++) {
np = cmdtype_code[i];
while(np != NULL) {
ar[j++] = np->cca;
np = cmdtype_code[i];
while(np != NULL) {
ar[j++] = np->cca;
diff --git
a/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c
b/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c
index
b10db02
..
71d56eb
100644
(file)
--- a/
test/unit/print_cmdtype_code_hash/print_cmdtype_code.c
+++ b/
test/unit/print_cmdtype_code_hash/print_cmdtype_code.c
@@
-5,7
+5,7
@@
void print_cmdtype_code()
{
int i;
CMDCODETAB *np;
{
int i;
CMDCODETAB *np;
- for(i = 0; i < cmd
code
size; i++){
+ for(i = 0; i < cmd
tab
size; i++){
np = cmdtype_code[i];
while(np != NULL) {
fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n",
np = cmdtype_code[i];
while(np != NULL) {
fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n",
diff --git
a/test/unit/print_code_type/print_code_type.c
b/test/unit/print_code_type/print_code_type.c
index
51abfd3
..
179160b
100644
(file)
--- a/
test/unit/print_code_type/print_code_type.c
+++ b/
test/unit/print_code_type/print_code_type.c
@@
-13,7
+13,7
@@
void print_code_type()
CMDCODETAB *np;
CMDCODEARRAY **ar;
ar = malloc(sizeof(*ar) * cmdcodesize);
CMDCODETAB *np;
CMDCODEARRAY **ar;
ar = malloc(sizeof(*ar) * cmdcodesize);
- for(i = 0; i < cmd
code
size; i++) {
+ for(i = 0; i < cmd
tab
size; i++) {
np = code_type[i];
while(np != NULL) {
ar[j++] = np->cca;
np = code_type[i];
while(np != NULL) {
ar[j++] = np->cca;
diff --git
a/test/unit/print_code_type_hash/print_code_type.c
b/test/unit/print_code_type_hash/print_code_type.c
index
c081888
..
a74fcca
100644
(file)
--- a/
test/unit/print_code_type_hash/print_code_type.c
+++ b/
test/unit/print_code_type_hash/print_code_type.c
@@
-6,7
+6,7
@@
void print_code_type()
{
int i;
CMDCODETAB *np;
{
int i;
CMDCODETAB *np;
- for(i = 0; i < cmd
code
size; i++){
+ for(i = 0; i < cmd
tab
size; i++){
for(np = code_type[i]; np != NULL; np = np->next) {
fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n", i, np->cca->code, np->cca->type, np->cca->cmd);
}
for(np = code_type[i]; np != NULL; np = np->next) {
fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n", i, np->cca->code, np->cca->type, np->cca->cmd);
}