From 618b612754ade1b87164f001e392fc4f83697181 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 14 Aug 2022 21:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=20kernel\common\math\pow.c=20?= =?UTF-8?q?=E7=9A=84=E6=B1=82=E5=B9=82=E8=BF=90=E7=AE=97=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=BA=E5=BF=AB=E9=80=9F=E5=B9=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- .vscode/settings.json | 3 ++- kernel/common/math/pow.c | 15 +++++++++++++-- kernel/filesystem/fat32/fat_ent.c | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2fff4a67..13b1f785 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ kernel/kernel serial_opt.txt user/sys_api_lib -docs/_build \ No newline at end of file +docs/_build +draft \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 413ca78d..f2f2e7e1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -120,7 +120,8 @@ "screen_manager.h": "c", "textui.h": "c", "atomic.h": "c", - "uart.h": "c" + "uart.h": "c", + "fat_ent.h": "c" }, "C_Cpp.errorSquiggles": "Enabled", "esbonio.sphinx.confDir": "" diff --git a/kernel/common/math/pow.c b/kernel/common/math/pow.c index 9d2ee308..9d61672c 100644 --- a/kernel/common/math/pow.c +++ b/kernel/common/math/pow.c @@ -3,8 +3,19 @@ int64_t pow(int64_t x, int y) { + if (y == 0) + return 1; + if (y == 1) + return x; + if (y == 2) + return x * x; int64_t res = 1; - for (int i = 0; i < y; ++i) - res *= x; + while (y != 0) + { + if (y & 1) + res *= x; + y >>= 1; + x *= x; + } return res; } \ No newline at end of file diff --git a/kernel/filesystem/fat32/fat_ent.c b/kernel/filesystem/fat32/fat_ent.c index c88ed8cd..559b6241 100644 --- a/kernel/filesystem/fat32/fat_ent.c +++ b/kernel/filesystem/fat32/fat_ent.c @@ -345,7 +345,7 @@ void fat32_fill_shortname(struct vfs_dir_entry_t *dEntry, struct fat32_Directory } else { - for(int j = 8;j<11;++j) + for (int j = 8; j < 11; ++j) { target->DIR_Name[j] = 'a'; }