Revisão | 1843ee32105cd8d4243f5b5d0e1096d8a35a1a02 (tree) |
---|---|
Hora | 2014-07-20 01:23:03 |
Autor | hikarupsp <hikarupsp@user...> |
Commiter | hikarupsp |
ビットカウント系アルゴリズムの追加。(ch4内部実装用)
@@ -13,9 +13,10 @@ | ||
13 | 13 | 17478D041940B66700293791 /* opcode.c in Sources */ = {isa = PBXBuildFile; fileRef = 17478D031940B66700293791 /* opcode.c */; }; |
14 | 14 | 1786B0941956C18800FD4F7B /* label.c in Sources */ = {isa = PBXBuildFile; fileRef = 1786B0931956C18800FD4F7B /* label.c */; }; |
15 | 15 | 17958C6F196C0E8000D7DBB4 /* data.c in Sources */ = {isa = PBXBuildFile; fileRef = 17958C6E196C0E8000D7DBB4 /* data.c */; }; |
16 | + 17AE6FD2197AAA32006A5C2D /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 17AE6FD1197AAA32006A5C2D /* debug.c */; }; | |
17 | + 17AE6FD5197AB834006A5C2D /* subfunc.c in Sources */ = {isa = PBXBuildFile; fileRef = 17AE6FD4197AB834006A5C2D /* subfunc.c */; }; | |
16 | 18 | 17DD55BB1967992200DA7D82 /* args.c in Sources */ = {isa = PBXBuildFile; fileRef = 17DD55BA1967992200DA7D82 /* args.c */; }; |
17 | 19 | 17E5092A1967F7B00091A22A /* src.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17E509291967F7770091A22A /* src.txt */; }; |
18 | - 17E50932196AD91D0091A22A /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 17E50931196AD91D0091A22A /* debug.c */; }; | |
19 | 20 | 17F95C01194C8DA70064E1B6 /* bios.c in Sources */ = {isa = PBXBuildFile; fileRef = 17F95C00194C8DA70064E1B6 /* bios.c */; }; |
20 | 21 | /* End PBXBuildFile section */ |
21 | 22 |
@@ -43,10 +44,11 @@ | ||
43 | 44 | 17478D031940B66700293791 /* opcode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = opcode.c; sourceTree = "<group>"; usesTabs = 1; }; |
44 | 45 | 1786B0931956C18800FD4F7B /* label.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = label.c; sourceTree = "<group>"; }; |
45 | 46 | 17958C6E196C0E8000D7DBB4 /* data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = data.c; sourceTree = "<group>"; }; |
47 | + 17AE6FD1197AAA32006A5C2D /* debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = debug.c; sourceTree = "<group>"; }; | |
48 | + 17AE6FD4197AB834006A5C2D /* subfunc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = subfunc.c; sourceTree = "<group>"; }; | |
46 | 49 | 17DD55BA1967992200DA7D82 /* args.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = args.c; sourceTree = "<group>"; }; |
47 | 50 | 17E509291967F7770091A22A /* src.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = src.txt; sourceTree = "<group>"; }; |
48 | 51 | 17E50930196AD6BF0091A22A /* opcache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = opcache.h; sourceTree = "<group>"; }; |
49 | - 17E50931196AD91D0091A22A /* debug.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = debug.c; path = ../debug.c; sourceTree = "<group>"; }; | |
50 | 52 | 17F95C00194C8DA70064E1B6 /* bios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bios.c; sourceTree = "<group>"; }; |
51 | 53 | /* End PBXFileReference section */ |
52 | 54 |
@@ -83,8 +85,8 @@ | ||
83 | 85 | children = ( |
84 | 86 | 17478CFC193E2A7800293791 /* chncpu.h */, |
85 | 87 | 17478CF3193E2A4900293791 /* chncpu.c */, |
86 | - 17E50931196AD91D0091A22A /* debug.c */, | |
87 | 88 | 17DD55BA1967992200DA7D82 /* args.c */, |
89 | + 17AE6FD1197AAA32006A5C2D /* debug.c */, | |
88 | 90 | 17478D00193F3D0000293791 /* ch4.c */, |
89 | 91 | 17478D02193F586100293791 /* ch4.h */, |
90 | 92 | 17E50930196AD6BF0091A22A /* opcache.h */, |
@@ -94,6 +96,7 @@ | ||
94 | 96 | 1786B0931956C18800FD4F7B /* label.c */, |
95 | 97 | 17478CFD193E2ADA00293791 /* test.hex */, |
96 | 98 | 17E509291967F7770091A22A /* src.txt */, |
99 | + 17AE6FD4197AB834006A5C2D /* subfunc.c */, | |
97 | 100 | ); |
98 | 101 | path = chncpu; |
99 | 102 | sourceTree = "<group>"; |
@@ -150,13 +153,14 @@ | ||
150 | 153 | buildActionMask = 2147483647; |
151 | 154 | files = ( |
152 | 155 | 1786B0941956C18800FD4F7B /* label.c in Sources */, |
156 | + 17AE6FD5197AB834006A5C2D /* subfunc.c in Sources */, | |
153 | 157 | 17958C6F196C0E8000D7DBB4 /* data.c in Sources */, |
154 | - 17E50932196AD91D0091A22A /* debug.c in Sources */, | |
155 | 158 | 17F95C01194C8DA70064E1B6 /* bios.c in Sources */, |
156 | 159 | 17DD55BB1967992200DA7D82 /* args.c in Sources */, |
157 | 160 | 17478D041940B66700293791 /* opcode.c in Sources */, |
158 | 161 | 17478CF4193E2A4900293791 /* chncpu.c in Sources */, |
159 | 162 | 17478D01193F3D0000293791 /* ch4.c in Sources */, |
163 | + 17AE6FD2197AAA32006A5C2D /* debug.c in Sources */, | |
160 | 164 | ); |
161 | 165 | runOnlyForDeploymentPostprocessing = 0; |
162 | 166 | }; |
@@ -13,6 +13,12 @@ int main(int argc, const char *argv[]) | ||
13 | 13 | CHNCPU_RuntimeEnvironment *env; |
14 | 14 | CHNCPU_VMArgs *vmArgs; |
15 | 15 | |
16 | + | |
17 | + unsigned int i; | |
18 | + i = 0x0010f0ff; | |
19 | + printf("0x%08X : %d, %d\n", i, GetBitCount32(i), GetNumberOfLeadingZero(i)); | |
20 | + | |
21 | + | |
16 | 22 | vmArgs = bindVMArgs(argc, argv); |
17 | 23 | env = CHNCPU_CreateRuntimeEnvironment(CHNCPU_CreateOpTableSet(), CHNCPU_CreateBIOS()); |
18 | 24 |
@@ -46,6 +52,8 @@ int decodeHexString(char *src0, char *src1, unsigned char *dst0, unsigned char * | ||
46 | 52 | // 1: second 4-bit |
47 | 53 | // 2: in string literal (byte aligned) |
48 | 54 | // 3: in string literal (not aligned) |
55 | + // []: unsigned raw value | |
56 | + // (): signed raw value | |
49 | 57 | unsigned char d = 0; |
50 | 58 | char c; |
51 | 59 |
@@ -16,9 +16,9 @@ | ||
16 | 16 | |
17 | 17 | // DEBUG Flag |
18 | 18 | #define DEBUG_PRINT_APPBIN_BEFORE_EXECUTION 0 |
19 | -#define DEBUG_PRINT_IREG_AFTER_EXECUTION 1 | |
20 | -#define DEBUG_PRINT_PREG_AFTER_EXECUTION 1 | |
21 | -#define DEBUG_PRINT_OP_BINDING 1 | |
19 | +#define DEBUG_PRINT_IREG_AFTER_EXECUTION 0 | |
20 | +#define DEBUG_PRINT_PREG_AFTER_EXECUTION 0 | |
21 | +#define DEBUG_PRINT_OP_BINDING 0 | |
22 | 22 | #define DEBUG_PRINT_OP_EXECUTING 0 |
23 | 23 | |
24 | 24 | // VM flags |
@@ -270,4 +270,9 @@ void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env); | ||
270 | 270 | void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env); |
271 | 271 | void CHNCPU_PrintErrorMessage(CHNCPU_RuntimeEnvironment *env); |
272 | 272 | |
273 | +// @subfunc.c | |
274 | +int GetBitCount32(unsigned int val); | |
275 | +int GetNumberOfLeadingZero(unsigned int val); | |
276 | + | |
277 | + | |
273 | 278 | #endif |
@@ -49,10 +49,16 @@ void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env) | ||
49 | 49 | |
50 | 50 | for(i = 0; i < CHNCPU_NUMBER_OF_PREG; i++){ |
51 | 51 | if(env->pReg[i].type != CHNCPU_PType_Undefined){ |
52 | + printf("P%02X: ", i); | |
53 | + if(env->pReg[i].type == CHNCPU_PType_Label){ | |
54 | + printf("Type:Label "); | |
55 | + } else{ | |
56 | + printf("Type:%2X ", env->pReg[i].type); | |
57 | + } | |
52 | 58 | if(env->pReg[i].mindex != CHNCPU_MemoryIndex_INVALID){ |
53 | - printf("P%02X: Type:%2X mem[%d][%d]", i, env->pReg[i].type, env->pReg[i].mindex, env->pReg[i].pindex); | |
59 | + printf("mem[%d][%d]", env->pReg[i].mindex, env->pReg[i].pindex); | |
54 | 60 | } else{ |
55 | - printf("P%02X: Type:%2X %s[%d]\t(Len:%d)", i, env->pReg[i].type, env->pReg[i].data->filePath, env->pReg[i].pindex, env->pReg[i].data->count); | |
61 | + printf("%s[%d]\t(Len:%d)", env->pReg[i].data->filePath, env->pReg[i].pindex, env->pReg[i].data->count); | |
56 | 62 | } |
57 | 63 | putchar('\n'); |
58 | 64 | regs++; |
@@ -0,0 +1,34 @@ | ||
1 | +// | |
2 | +// subfunc.c | |
3 | +// chncpu | |
4 | +// | |
5 | +// Created by 西田 耀 on 2014/07/19. | |
6 | +// Copyright (c) 2014年 CHNOSProject. All rights reserved. | |
7 | +// | |
8 | + | |
9 | +#include "chncpu.h" | |
10 | + | |
11 | +int GetBitCount32(unsigned int val) | |
12 | +{ | |
13 | + // http://www.nminoru.jp/~nminoru/programming/bitcount.html | |
14 | + val = (val & 0x55555555) + ((val >> 1) & 0x55555555); | |
15 | + val = (val & 0x33333333) + ((val >> 2) & 0x33333333); | |
16 | + val = (val & 0x0f0f0f0f) + ((val >> 4) & 0x0f0f0f0f); | |
17 | + val = (val & 0x00ff00ff) + ((val >> 8) & 0x00ff00ff); | |
18 | + val = (val & 0x0000ffff) + ((val >>16) & 0x0000ffff); | |
19 | + return (int)val; | |
20 | +} | |
21 | + | |
22 | + | |
23 | +int GetNumberOfLeadingZero(unsigned int val) | |
24 | +{ | |
25 | + // 左側にあるゼロの個数を求める | |
26 | + // http://www.nminoru.jp/~nminoru/programming/bitcount.html | |
27 | + int c = 0; | |
28 | + c |= ((val << c) & 0xFFFF0000) ? 0 : 16; | |
29 | + c |= ((val << c) & 0xFF000000) ? 0 : 8; | |
30 | + c |= ((val << c) & 0xF0000000) ? 0 : 4; | |
31 | + c |= ((val << c) & 0xC0000000) ? 0 : 2; | |
32 | + c |= ((val << c) & 0x80000000) ? 0 : 1; | |
33 | + return c; | |
34 | +} | |
\ No newline at end of file |