• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión1843ee32105cd8d4243f5b5d0e1096d8a35a1a02 (tree)
Tiempo2014-07-20 01:23:03
Autorhikarupsp <hikarupsp@user...>
Commiterhikarupsp

Log Message

ビットカウント系アルゴリズムの追加。(ch4内部実装用)

Cambiar Resumen

Diferencia incremental

--- a/chncpu.xcodeproj/project.pbxproj
+++ b/chncpu.xcodeproj/project.pbxproj
@@ -13,9 +13,10 @@
1313 17478D041940B66700293791 /* opcode.c in Sources */ = {isa = PBXBuildFile; fileRef = 17478D031940B66700293791 /* opcode.c */; };
1414 1786B0941956C18800FD4F7B /* label.c in Sources */ = {isa = PBXBuildFile; fileRef = 1786B0931956C18800FD4F7B /* label.c */; };
1515 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 */; };
1618 17DD55BB1967992200DA7D82 /* args.c in Sources */ = {isa = PBXBuildFile; fileRef = 17DD55BA1967992200DA7D82 /* args.c */; };
1719 17E5092A1967F7B00091A22A /* src.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17E509291967F7770091A22A /* src.txt */; };
18- 17E50932196AD91D0091A22A /* debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 17E50931196AD91D0091A22A /* debug.c */; };
1920 17F95C01194C8DA70064E1B6 /* bios.c in Sources */ = {isa = PBXBuildFile; fileRef = 17F95C00194C8DA70064E1B6 /* bios.c */; };
2021 /* End PBXBuildFile section */
2122
@@ -43,10 +44,11 @@
4344 17478D031940B66700293791 /* opcode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = opcode.c; sourceTree = "<group>"; usesTabs = 1; };
4445 1786B0931956C18800FD4F7B /* label.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = label.c; sourceTree = "<group>"; };
4546 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>"; };
4649 17DD55BA1967992200DA7D82 /* args.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = args.c; sourceTree = "<group>"; };
4750 17E509291967F7770091A22A /* src.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = src.txt; sourceTree = "<group>"; };
4851 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>"; };
5052 17F95C00194C8DA70064E1B6 /* bios.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = bios.c; sourceTree = "<group>"; };
5153 /* End PBXFileReference section */
5254
@@ -83,8 +85,8 @@
8385 children = (
8486 17478CFC193E2A7800293791 /* chncpu.h */,
8587 17478CF3193E2A4900293791 /* chncpu.c */,
86- 17E50931196AD91D0091A22A /* debug.c */,
8788 17DD55BA1967992200DA7D82 /* args.c */,
89+ 17AE6FD1197AAA32006A5C2D /* debug.c */,
8890 17478D00193F3D0000293791 /* ch4.c */,
8991 17478D02193F586100293791 /* ch4.h */,
9092 17E50930196AD6BF0091A22A /* opcache.h */,
@@ -94,6 +96,7 @@
9496 1786B0931956C18800FD4F7B /* label.c */,
9597 17478CFD193E2ADA00293791 /* test.hex */,
9698 17E509291967F7770091A22A /* src.txt */,
99+ 17AE6FD4197AB834006A5C2D /* subfunc.c */,
97100 );
98101 path = chncpu;
99102 sourceTree = "<group>";
@@ -150,13 +153,14 @@
150153 buildActionMask = 2147483647;
151154 files = (
152155 1786B0941956C18800FD4F7B /* label.c in Sources */,
156+ 17AE6FD5197AB834006A5C2D /* subfunc.c in Sources */,
153157 17958C6F196C0E8000D7DBB4 /* data.c in Sources */,
154- 17E50932196AD91D0091A22A /* debug.c in Sources */,
155158 17F95C01194C8DA70064E1B6 /* bios.c in Sources */,
156159 17DD55BB1967992200DA7D82 /* args.c in Sources */,
157160 17478D041940B66700293791 /* opcode.c in Sources */,
158161 17478CF4193E2A4900293791 /* chncpu.c in Sources */,
159162 17478D01193F3D0000293791 /* ch4.c in Sources */,
163+ 17AE6FD2197AAA32006A5C2D /* debug.c in Sources */,
160164 );
161165 runOnlyForDeploymentPostprocessing = 0;
162166 };
--- a/chncpu/chncpu.c
+++ b/chncpu/chncpu.c
@@ -13,6 +13,12 @@ int main(int argc, const char *argv[])
1313 CHNCPU_RuntimeEnvironment *env;
1414 CHNCPU_VMArgs *vmArgs;
1515
16+
17+ unsigned int i;
18+ i = 0x0010f0ff;
19+ printf("0x%08X : %d, %d\n", i, GetBitCount32(i), GetNumberOfLeadingZero(i));
20+
21+
1622 vmArgs = bindVMArgs(argc, argv);
1723 env = CHNCPU_CreateRuntimeEnvironment(CHNCPU_CreateOpTableSet(), CHNCPU_CreateBIOS());
1824
@@ -46,6 +52,8 @@ int decodeHexString(char *src0, char *src1, unsigned char *dst0, unsigned char *
4652 // 1: second 4-bit
4753 // 2: in string literal (byte aligned)
4854 // 3: in string literal (not aligned)
55+ // []: unsigned raw value
56+ // (): signed raw value
4957 unsigned char d = 0;
5058 char c;
5159
--- a/chncpu/chncpu.h
+++ b/chncpu/chncpu.h
@@ -16,9 +16,9 @@
1616
1717 // DEBUG Flag
1818 #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
2222 #define DEBUG_PRINT_OP_EXECUTING 0
2323
2424 // VM flags
@@ -270,4 +270,9 @@ void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env);
270270 void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env);
271271 void CHNCPU_PrintErrorMessage(CHNCPU_RuntimeEnvironment *env);
272272
273+// @subfunc.c
274+int GetBitCount32(unsigned int val);
275+int GetNumberOfLeadingZero(unsigned int val);
276+
277+
273278 #endif
--- a/debug.c
+++ b/chncpu/debug.c
@@ -49,10 +49,16 @@ void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env)
4949
5050 for(i = 0; i < CHNCPU_NUMBER_OF_PREG; i++){
5151 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+ }
5258 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);
5460 } 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);
5662 }
5763 putchar('\n');
5864 regs++;
--- /dev/null
+++ b/chncpu/subfunc.c
@@ -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