Skip to content

Commit

Permalink
Fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Dec 26, 2024
1 parent f8f6ea2 commit 3dc2531
Show file tree
Hide file tree
Showing 26 changed files with 2,376 additions and 2,513 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ clean:

STYLE := "{BasedOnStyle: Google, TabWidth: 4, IndentWidth: 4, UseTab: Never, SortIncludes: false, ColumnLimit: 120}"
fmt:
clang-format-18 -i -style=$(STYLE) src/*
clang-format-18 -i -style=$(STYLE) \
libc/*.h \
libc/internal/*.h \
libc/src/*.c \
libc/sys/*.h \
src/*

install:
wget 'https://github.com/nervosnetwork/ckb-standalone-debugger/releases/download/v0.119.0/ckb-debugger-linux-x64.tar.gz'
Expand Down
14 changes: 7 additions & 7 deletions libc/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#include "ckb_syscall_apis.h"

#define assert(s) \
do { \
if (!(s)) { \
printf("Failed at %s:%d: %s\n", __FILE__, __LINE__, (#s)); \
ckb_exit(-1); \
} \
} while (0)
#define assert(s) \
do { \
if (!(s)) { \
printf("Failed at %s:%d: %s\n", __FILE__, __LINE__, (#s)); \
ckb_exit(-1); \
} \
} while (0)

#endif // CKB_C_STDLIB_ASSERT_H_
32 changes: 16 additions & 16 deletions libc/ckb_cell_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
#define CKB_C_STDLIB_CKB_CELL_FS_H 1

typedef struct FSBlob {
uint32_t offset;
uint32_t length;
uint32_t offset;
uint32_t length;
} FSBlob;

typedef struct FSEntry {
FSBlob filename;
FSBlob content;
FSBlob filename;
FSBlob content;
} FSEntry;

typedef struct CellFileSystemNode {
uint32_t count;
FSEntry *files;
void *start;
uint32_t count;
FSEntry *files;
void *start;
} CellFileSystemNode;

typedef struct CellFileSystem {
CellFileSystemNode *current;
struct CellFileSystem *next;
CellFileSystemNode *current;
struct CellFileSystem *next;
} CellFileSystem;

typedef struct FSFile {
const char *filename;
const void *content;
uint32_t size;
// indicate how many active users there are, used to avoid excessive opening
// of the same file.
// Currently the only valid values are 1 and 0.
uint8_t rc;
const char *filename;
const void *content;
uint32_t size;
// indicate how many active users there are, used to avoid excessive opening
// of the same file.
// Currently the only valid values are 1 and 0.
uint8_t rc;
} FSFile;

int get_file(const CellFileSystem *fs, const char *filename, FSFile **f);
Expand Down
32 changes: 16 additions & 16 deletions libc/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

#ifndef __SHARED_LIBRARY__
__attribute__((visibility("default"))) __attribute__((naked)) void _start() {
asm volatile(
".option push\n"
".option norelax\n"
asm volatile(
".option push\n"
".option norelax\n"
#ifndef CKB_NO_ENTRY_GP
"1:auipc gp, %pcrel_hi(__global_pointer$)\n"
"addi gp, gp, %pcrel_lo(1b)\n"
".option pop\n"
"1:auipc gp, %pcrel_hi(__global_pointer$)\n"
"addi gp, gp, %pcrel_lo(1b)\n"
".option pop\n"
#endif
/*
* By default CKB VM initializes all memory to 0, there's no need
* to clear BSS segment again.
*/
"lw a0, 0(sp)\n"
"addi a1, sp, 8\n"
"li a2, 0\n"
"call main\n"
"li a7, 93\n"
"ecall");
/*
* By default CKB VM initializes all memory to 0, there's no need
* to clear BSS segment again.
*/
"lw a0, 0(sp)\n"
"addi a1, sp, 8\n"
"li a2, 0\n"
"call main\n"
"li a7, 93\n"
"ecall");
}
#endif /* __SHARED_LIBRARY__ */
#endif /* CKB_DECLARATION_ONLY*/
Expand Down
3 changes: 1 addition & 2 deletions libc/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#define _BSD_SOURCE 1
#endif

#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && \
!defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && \
#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) && \
!defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__)
#define _BSD_SOURCE 1
#define _XOPEN_SOURCE 700
Expand Down
152 changes: 74 additions & 78 deletions libc/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,76 +11,75 @@
#define LDBL_MAX __LDBL_MAX__

typedef union {
double value;
struct {
uint32_t lsw;
uint32_t msw;
} parts;
struct {
uint64_t w;
} xparts;
double value;
struct {
uint32_t lsw;
uint32_t msw;
} parts;
struct {
uint64_t w;
} xparts;
} ieee_double_shape_type;

/* Get two 32 bit ints from a double. */

#define EXTRACT_WORDS(ix0, ix1, d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)
#define EXTRACT_WORDS(ix0, ix1, d) \
do { \
ieee_double_shape_type ew_u; \
ew_u.value = (d); \
(ix0) = ew_u.parts.msw; \
(ix1) = ew_u.parts.lsw; \
} while (0)

/* Get the more significant 32 bit int from a double. */

#define GET_HIGH_WORD(i, d) \
do { \
ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)
#define GET_HIGH_WORD(i, d) \
do { \
ieee_double_shape_type gh_u; \
gh_u.value = (d); \
(i) = gh_u.parts.msw; \
} while (0)

/* Get the less significant 32 bit int from a double. */

#define GET_LOW_WORD(i, d) \
do { \
ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)
#define GET_LOW_WORD(i, d) \
do { \
ieee_double_shape_type gl_u; \
gl_u.value = (d); \
(i) = gl_u.parts.lsw; \
} while (0)

/* Set the more significant 32 bits of a double from an int. */

#define SET_HIGH_WORD(d, v) \
do { \
ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)
#define SET_HIGH_WORD(d, v) \
do { \
ieee_double_shape_type sh_u; \
sh_u.value = (d); \
sh_u.parts.msw = (v); \
(d) = sh_u.value; \
} while (0)

/* Set the less significant 32 bits of a double from an int. */

#define SET_LOW_WORD(d, v) \
do { \
ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)

static const double ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
huge = 1.0e+300, tiny = 1.0e-300,
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
#define SET_LOW_WORD(d, v) \
do { \
ieee_double_shape_type sl_u; \
sl_u.value = (d); \
sl_u.parts.lsw = (v); \
(d) = sl_u.value; \
} while (0)

static const double ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
huge = 1.0e+300, tiny = 1.0e-300, Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */

static const double zero = 0.0;

Expand All @@ -98,32 +97,29 @@ static const double bp[] =
{
0.0,
1.35003920212974897128e-08,
}, /* 0x3E4CFDEB, 0x43CFD006 */
one = 1.0, two = 2.0,
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
}, /* 0x3E4CFDEB, 0x43CFD006 */
one = 1.0, two = 2.0, two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
/* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l =
-7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
ivln2_l =
1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/

#endif
36 changes: 16 additions & 20 deletions libc/internal/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,27 @@
* https://git.musl-libc.org/cgit/musl/tree/src/internal/atomic.h?id=33338ebc853d37c80f0f236cc7a92cb0acc6aace
*/
static inline int a_ctz_32(uint32_t x) {
static const char debruijn32[32] = {
0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14};
return debruijn32[(x & -x) * 0x076be629 >> 27];
static const char debruijn32[32] = {0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14};
return debruijn32[(x & -x) * 0x076be629 >> 27];
}

static inline int a_ctz_64(uint64_t x) {
static const char debruijn64[64] = {
0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
if (sizeof(long) < 8) {
uint32_t y = x;
if (!y) {
y = x >> 32;
return 32 + a_ctz_32(y);
static const char debruijn64[64] = {0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28,
62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11,
63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10,
51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12};
if (sizeof(long) < 8) {
uint32_t y = x;
if (!y) {
y = x >> 32;
return 32 + a_ctz_32(y);
}
return a_ctz_32(y);
}
return a_ctz_32(y);
}
return debruijn64[(x & -x) * 0x022fdd63cc95386dull >> 58];
return debruijn64[(x & -x) * 0x022fdd63cc95386dull >> 58];
}

static inline int a_ctz_l(unsigned long x) {
return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x);
}
static inline int a_ctz_l(unsigned long x) { return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x); }

#endif /* CKB_C_STDLIB_INTERNAL_ATOMIC_H_ */
2 changes: 1 addition & 1 deletion libc/internal/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ typedef signed int int32_t;
typedef unsigned long uint64_t;
typedef signed long int64_t;

#endif /* CKB_C_STDLIB_INTERNAL_TYPES_H_ */
#endif /* CKB_C_STDLIB_INTERNAL_TYPES_H_ */
3 changes: 1 addition & 2 deletions libc/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@
/* Minimum and maximum values a `signed long int' can hold.
(Same as `int'). */
#ifndef __LONG_MAX__
#if defined(__alpha__) || (defined(__sparc__) && defined(__arch64__)) || \
defined(__sparcv9)
#if defined(__alpha__) || (defined(__sparc__) && defined(__arch64__)) || defined(__sparcv9)
#define __LONG_MAX__ 9223372036854775807L
#else
#define __LONG_MAX__ 2147483647L
Expand Down
Loading

0 comments on commit 3dc2531

Please sign in to comment.