Skip to content

Commit 992bb87

Browse files
authored
Merge pull request #79 from afxgroup/beta8
Beta8
2 parents 2278f45 + 4e7c59d commit 992bb87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2444
-314
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.lha
66
*.bak
77
/library/compiler.log
8+
compiler.log
89
*.map
910
.vscode
1011
build/

GNUmakefile.os4

+9-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ WARNINGS := \
5858
-Wall -W -Wextra -Wpointer-arith -Wsign-compare -Wmissing-prototypes \
5959
-Wundef -Wmissing-declarations -Wunused -Wwrite-strings -Wno-array-bounds -Wno-missing-braces -Wno-unused-value -Wno-comment \
6060
-Wno-deprecated-declarations -Wno-sign-compare -Wno-cast-function-type -Wno-unused-variable -Wno-parentheses -Wno-missing-prototypes \
61-
-Wstrict-aliasing -Wno-shadow -Wno-implicit-fallthrough # -Werror -Wbad-function-cast -Wconversion -Wformat
61+
-Wstrict-aliasing -Wno-shadow -Wno-implicit-fallthrough -Wno-prio-ctor-dtor # -Werror -Wbad-function-cast -Wconversion -Wformat
6262

6363
PIC := -fPIC
6464
INCLUDES := -I$(LIB_DIR)/include \
@@ -91,11 +91,12 @@ INCLUDES := -I$(LIB_DIR)/include \
9191
SHARED := $(if $(SHARED),$(SHARED),yes)
9292
STATIC := $(if $(STATIC),$(STATIC),yes)
9393

94-
OPTIONS := -msdata=data -DHAVE_SYSV -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__CLIB2__ -Wa,-mregnames -fno-builtin -nostdlib -D_GNU_SOURCE -D_XOPEN_SOURCE -D_USE_GNU
95-
OPTIMIZE := -O2 -mmultiple -mupdate -mstrict-align
94+
LARGEDATA := -msdata=data
95+
OPTIONS := $(LARGEDATA) -DHAVE_SYSV -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D__CLIB2__ -Wa,-mregnames -fno-builtin -nostdlib -D_GNU_SOURCE -D_XOPEN_SOURCE -D_USE_GNU
96+
OPTIMIZE := -O3 -mmultiple -mupdate -mstrict-align
9697

9798
ifndef DEBUG
98-
OPTIMIZE := $(OPTIMIZE) -DNDEBUG
99+
OPTIMIZE := $(OPTIMIZE) -gstabs -DNDEBUG
99100
else
100101
OPTIMIZE := $(OPTIMIZE) -gstabs -DDEBUG
101102
endif
@@ -151,6 +152,7 @@ clean:
151152
-$(DELETE) $(BUILD_DIR)/compiler.log
152153
-$(DELETE) clib2.lha
153154
-$(DELETE) clib2.bak
155+
-cd test_programs; make clean
154156

155157
##############################################################################
156158

@@ -259,6 +261,9 @@ $(VERBOSE)echo -e "\rMaking Shared \033[0;31m$@\033[0m"
259261
$(VERBOSE)$(CC) -mcrt=clib2 -shared -use-dynld -o $@ $^ $(LOG_COMMAND) -Lbuild/lib -lc
260262
endef
261263

264+
compile-tests:
265+
cd $(LIB_ROOT)/test_programs; CC="$(CC)" CXX="$(CXX)" COPY="$(COPY)" DELETE="$(DELETE)" MAKEDIR="$(MAKEDIR)" && make
266+
262267
install:
263268
$(DELETE) $(INSTALL_PREFIX)/include/*
264269
$(DELETE) $(INSTALL_PREFIX)/lib/*

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you want to use `dlopen`/`dlsym` with shared objects:
2929
**DON'T TRY TO USE** newlib shared objects because it will crash badly!
3030
**DON'T USE** static libraries otherwise you could have undefined symbols!
3131

32-
The plain `libc.a` now contains also `libnet.a`, `libunix.a`. Socket support and floating point support are always enabled
32+
The plain `libc.a` now contains also `libnet.a`, `libunix.a`. Socket support and floating point support are always enabled.
3333
Soft float version is no longer available.
3434

3535
Clib2 define `__THREAD_SAFE` used to check if the library is thread safe
@@ -162,6 +162,7 @@ Don't call `exit()` function in an `alarm()` handler otherwise your program will
162162
- Try to use Microsoft <a href="https://github.com/microsoft/mimalloc">`mimalloc`</a> as memory allocator that should be faster and more better when there are multiple cores.
163163
- Create a shared library
164164
- Add a test suite
165+
- Try to use some functions/headers from https://github.com/attractivechaos/klib to improve speed
165166

166167
## Legal status
167168

libc.gmk

+5
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ C_STDIO := \
335335
stdio/change_fd_user_data.o \
336336
stdio/clearerr.o \
337337
stdio/ctermid.o \
338+
stdio/dprintf.o \
338339
stdio/dropiobreadbuffer.o \
339340
stdio/duplicate_fd.o \
340341
stdio/err.o \
@@ -427,6 +428,7 @@ C_STDIO := \
427428
stdio/unlockfile.o \
428429
stdio/vasprintf.o \
429430
stdio/vasprintf_hook_entry.o \
431+
stdio/vdprintf.o \
430432
stdio/vfprintf.o \
431433
stdio/vfscanf.o \
432434
stdio/vsscanf.o \
@@ -543,6 +545,8 @@ C_STDLIB := \
543545

544546
C_STRING := \
545547
string/strings_ffs.o \
548+
string/strings_ffsl.o \
549+
string/strings_ffsll.o \
546550
string/strings_strcasecmp.o \
547551
string/strings_strncasecmp.o \
548552
string/bcmp.o \
@@ -715,6 +719,7 @@ C_UNISTD := \
715719
unistd/getlogin_r.o \
716720
unistd/getopt.o \
717721
unistd/getopt_long.o \
722+
unistd/getpagesize.o \
718723
unistd/getpid.o \
719724
unistd/getppid.o \
720725
unistd/getwd.o \

libm.gmk

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ C_MATH := \
123123
math/erff.o \
124124
math/erfl.o \
125125
math/exp.o \
126+
math/exp10.o \
127+
math/exp10f.o \
128+
math/exp10l.o \
126129
math/exp2.o \
127130
math/exp2f.o \
128131
math/exp2l.o \
@@ -236,6 +239,9 @@ C_MATH := \
236239
math/nexttowardf.o \
237240
math/nexttowardl.o \
238241
math/pow.o \
242+
math/pow10.o \
243+
math/pow10f.o \
244+
math/pow10l.o \
239245
math/powf.o \
240246
math/powl.o \
241247
math/remainder.o \

library/cpu/4xx/memchr440.S

+13-13
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ function_prolog(__memchr440)
6161
beq- ret_null /* Branch to return NULL if so */
6262

6363

64-
addi r12,0,8 /* Byte count of 8 into XER for 'load */
65-
mtxer r12 /* string' instruction later */
64+
addi r12,0,8 /* Byte count of 8 into XER for 'load */
65+
mtxer r12 /* string' instruction later */
6666

67-
xor r12,r12,r12 /* Clear offset from the start */
67+
xor r12,r12,r12 /* Clear offset from the start */
6868

6969
rlwimi r4,r4,8,16,23 /* Set up 'c' in all bytes of word. */
7070
rlwimi. r4,r4,16,0,15 /* Remember 'c' in LSB of int */
@@ -76,8 +76,8 @@ function_prolog(__memchr440)
7676

7777
addic. r9,r8,-8 /* If byte count = 8, we are DW aligned */
7878
beq again /* So branch straight to fast loop */
79-
/* Otherwise, handle initial bytes one at */
80-
/* a time. */
79+
/* Otherwise, handle initial bytes one at */
80+
/* a time. */
8181
andi. r9,r4,255 /* Get search char only in low byte */
8282
addi r10,r3,-1 /* Preset base pointer for auto incr */
8383

@@ -92,17 +92,17 @@ next_byte:
9292
addic. r8,r8,-1 /* Decrement the DW byte count */
9393
bne+ next_byte /* Loop again if still not DW aligned */
9494

95-
again: /* DW aligned, look for 'c' in new 8 bytes */
95+
again: /* DW aligned, look for 'c' in new 8 bytes */
9696

97-
lswx r6,r3,r12 /* Load r6/r7 from r3 src + r12 offset */
98-
/* from the start */
97+
lswx r6,r3,r12 /* Load r6/r7 from r3 src + r12 offset */
98+
/* from the start */
9999

100-
xor r6,r6,r4 /* XOR r4 & r6 to look for match */
101-
xor r7,r7,r4 /* XOR r4 & r7 to look for match */
100+
xor r6,r6,r4 /* XOR r4 & r6 to look for match */
101+
xor r7,r7,r4 /* XOR r4 & r7 to look for match */
102102

103103
DLMZBDOT(0,6,7) /* Check for hole created by match */
104104

105-
add r12,r12,r0 /* Update total offset with 1-8 */
105+
add r12,r12,r0 /* Update total offset with 1-8 */
106106
beq+ no_match /* Branch if no match found in 8 bytes */
107107

108108
/* Match was found, but first must see if we've exceeded max count */
@@ -113,7 +113,7 @@ again: /* DW aligned, look for 'c' in new 8 bytes */
113113
found:
114114

115115
addi r12,r12,-1
116-
add r3,r3,r12 /* Return string start addr + offset to 'c'*/
116+
add r3,r3,r12 /* Return string start addr + offset to 'c'*/
117117
blr
118118

119119
no_match:
@@ -123,7 +123,7 @@ no_match:
123123

124124
ret_null:
125125

126-
xor r3,r3,r3 /* Return NULL since no match found */
126+
xor r3,r3,r3 /* Return NULL since no match found */
127127
blr
128128

129129
function_epilog(__memchr440)

library/cpu/4xx/strchr440.S

+44-47
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function_prolog(__strchr440)
5757
cmpwi r4,0
5858
beq- char_is_null /* Search char is NULL, so do strlen op */
5959

60-
xor r5,r5,r5 /* Clear total offset from start */
61-
neg r9,r3 /* get 2's complement of input address */
60+
xor r5,r5,r5 /* Clear total offset from start */
61+
neg r9,r3 /* get 2's complement of input address */
6262
rlwinm. r7,r9,0,29,31 /* calc number of bytes to dword boundary */
6363
beq- dwbndry /* if zero, then already on dword bndry */
6464

@@ -74,30 +74,30 @@ bytebybyte:
7474

7575
dwbndry:
7676
addi r6,0,8 /* Byte count of 8 in XER for 'load */
77-
mtxer r6 /* string' instruction later */
77+
mtxer r6 /* string' instruction later */
7878

7979
rlwimi r4,r4,8,16,23 /* Set up 'c' in all bytes of word. */
80-
rlwimi. r4,r4,16,0,15 /* Remember 'c' in LSB of int */
80+
rlwimi. r4,r4,16,0,15 /* Remember 'c' in LSB of int */
8181

8282
b again
8383

8484
comp: /* No NULL in eight bytes, look for 'c' */
8585

86-
xor r6,r6,r4 /* XOR r4 & r6 to look for match */
87-
xor r7,r7,r4 /* XOR r4 & r7 to look for match */
86+
xor r6,r6,r4 /* XOR r4 & r6 to look for match */
87+
xor r7,r7,r4 /* XOR r4 & r7 to look for match */
8888

89-
DLMZBDOT(0,6,7) /* Check for hole created by match */
89+
DLMZBDOT(0,6,7) /* Check for hole created by match */
9090

91-
add r5,r5,r0 /* Update total offset with 1-8 */
91+
add r5,r5,r0 /* Update total offset with 1-8 */
9292

93-
bne- found /* If no hole, fall through and get next 8 */
94-
/* bytes, otherwise, go to logic to handle */
95-
/* 8 bytes w/ match */
93+
bne- found /* If no hole, fall through and get next 8 */
94+
/* bytes, otherwise, go to logic to handle */
95+
/* 8 bytes w/ match */
9696

9797
again: /* New 8 bytes, look for NULL first */
9898

9999
lswx r6,r3,r5 /* Load r6/r7 from r3 src + r5 offset */
100-
/* from the start */
100+
/* from the start */
101101
DLMZBDOT(12,6,7) /* Look for NULL in these current 8 bytes */
102102
beq+ comp /* If no NULL, search 8 bytes for 'c' */
103103

@@ -107,15 +107,13 @@ again: /* New 8 bytes, look for NULL first */
107107
*/
108108

109109
xor r6,r6,r4 /* XOR r4 & r6 to look for match */
110-
xor r7,r7,r4 /* XOR r4 & r7 to look for match */
110+
xor r7,r7,r4 /* XOR r4 & r7 to look for match */
111111

112-
DLMZBDOT(0,6,7) /* Check for hole created by match */
112+
DLMZBDOT(0,6,7) /* Check for hole created by match */
113113

114-
cmplw r0,r12 /* Was there a match before the NULL? */
115-
116-
bge ret_null /* If not, return NULL */
117-
118-
add r5,r5,r0 /* Else, update the offset from the start */
114+
cmplw r0,r12 /* Was there a match before the NULL? */
115+
bge ret_null /* If not, return NULL */
116+
add r5,r5,r0 /* Else, update the offset from the start */
119117

120118
/*
121119
* Here we know the string is not ending, but we found a match in
@@ -126,19 +124,19 @@ again: /* New 8 bytes, look for NULL first */
126124
found:
127125

128126
addi r5,r5,-1
129-
add r3,r3,r5 /* Return string start addr + offset to 'c'*/
127+
add r3,r3,r5 /* Return string start addr + offset to 'c'*/
130128
blr
131129

132130
ret_null:
133131

134-
xor r3,r3,r3 /* Return NULL since no match found */
132+
xor r3,r3,r3 /* Return NULL since no match found */
135133
blr
136134

137-
char_is_null: /* Since search char is NULL, we basically */
138-
/* do a strlen operation */
135+
char_is_null: /* Since search char is NULL, we basically */
136+
/* do a strlen operation */
139137

140-
xor r12,r12,r12 /* Clear total offset from the start */
141-
neg r9,r3 /* get 2's complement of input address */
138+
xor r12,r12,r12 /* Clear total offset from the start */
139+
neg r9,r3 /* get 2's complement of input address */
142140
rlwinm. r7,r9,0,29,31 /* calc number of bytes to dword boundary */
143141
beq- s_dwbndry /* if zero, then already on dword bndry */
144142

@@ -152,45 +150,44 @@ s_bytebybyte:
152150

153151
s_dwbndry:
154152
rlwinm. r7,r9,29,30,31 /* calc # of dwords to quad word bndry */
155-
beq s_qwbndry /* if zero, then already on qword bndry */
156-
addi r7,0,8 /* Byte count of 8 into XER for 'load */
157-
/* string' instruction later */
158-
mtxer r7 /* Load count for 'load string' */
159-
lswx r6,r3,r12 /* Load r6-r7 from r3 src + r12 offset */
153+
beq s_qwbndry /* if zero, then already on qword bndry */
154+
addi r7,0,8 /* Byte count of 8 into XER for 'load */
155+
/* string' instruction later */
156+
mtxer r7 /* Load count for 'load string' */
157+
lswx r6,r3,r12 /* Load r6-r7 from r3 src + r12 offset */
160158
DLMZBDOT(11,6,7) /* Look for NULL in these 8 bytes */
161-
add r12,r12,r11 /* Bump the offset from the start */
162-
bne- s_found /* If NULL found, done; else keep looking */
159+
add r12,r12,r11 /* Bump the offset from the start */
160+
bne- s_found /* If NULL found, done; else keep looking */
163161

164162
s_qwbndry:
165163

166-
addi r5,0,16 /* Byte count of 16 into XER for 'load */
167-
/* string' instruction later */
164+
addi r5,0,16 /* Byte count of 16 into XER for 'load */
165+
/* string' instruction later */
168166

169167
s_again: /* New 16 bytes, look for NULL */
170168

171-
mtxer r5 /* Load count for 'load string' */
172-
lswx r6,r3,r12 /* Load r6-r9 from r3 src + r12 offset */
173-
/* from the start */
169+
mtxer r5 /* Load count for 'load string' */
170+
lswx r6,r3,r12 /* Load r6-r9 from r3 src + r12 offset */
171+
/* from the start */
174172
DLMZBDOT(11,6,7) /* Look for NULL in these first 8 bytes */
175173

176-
add r12,r12,r11 /* Bump the offset from the start */
174+
add r12,r12,r11 /* Bump the offset from the start */
177175

178-
bne- s_found /* If no NULL in first 8 bytes, fall */
179-
/* through and test next 8 bytes, else, */
180-
/* we're done */
176+
bne- s_found /* If no NULL in first 8 bytes, fall */
177+
/* through and test next 8 bytes, else, */
178+
/* we're done */
181179

182-
DLMZBDOT(11,8,9) /* Look for NULL in these next 8 bytes */
180+
DLMZBDOT(11,8,9) /* Look for NULL in these next 8 bytes */
183181

184-
add r12,r12,r11 /* Bump the offset from the start */
182+
add r12,r12,r11 /* Bump the offset from the start */
185183

186-
beq+ s_again /* If no NULL, grab next 16 bytes, else, */
187-
/* we're done. */
184+
beq+ s_again /* If no NULL, grab next 16 bytes, else, */
185+
/* we're done. */
188186
s_found:
189187

190188
addi r12,r12,-1 /* Compensate for NULL */
189+
add r3,r12,r3 /* Add returned length to string pointer */
191190

192-
add r3,r12,r3 /* Add returned length to string pointer */
193-
194191
blr
195192

196193
function_epilog(__strchr440)

library/crtbegin.c

+17-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,23 @@
2929
* This hack does not work correctly with GCC 5 and higher. The optimizer
3030
* will see a one element array and act appropriately. The current workaround
3131
* is to use -fno-aggressive-loop-optimizations when compiling this file.
32-
*/
32+
*
33+
* NOTE: In order to be able to support SVR4 shared libraries, we arrange
34+
* to have one set of symbols { __CTOR_LIST__, __DTOR_LIST__, __CTOR_END__,
35+
* __DTOR_END__ } per root executable and also one set of these symbols
36+
* per shared library. So in any given whole process image, we may have
37+
* multiple definitions of each of these symbols. In order to prevent
38+
* these definitions from conflicting with one another, and in order to
39+
* ensure that the proper lists are used for the initialization/finalization
40+
* of each individual shared library (respectively), we give these symbols
41+
* only internal (i.e. `static') linkage, and we also make it a point to
42+
* refer to only the __CTOR_END__ symbol in sh/crtend.o and the __DTOR_LIST__
43+
* symbol in sh/crtbegin.o, where they are defined. */
44+
45+
typedef void (*func_ptr) (void);
3346

34-
static void (*__CTOR_LIST__[1])(void) __attribute__((used, section(".ctors"), aligned(sizeof(void (*)(void)))));
35-
static void (*__DTOR_LIST__[1])(void) __attribute__((used, section(".dtors"), aligned(sizeof(void (*)(void)))));
47+
static func_ptr __CTOR_LIST__[1] __attribute__((used, section(".ctors"), aligned(sizeof(func_ptr)))) = { (func_ptr) (-1) };;
48+
static func_ptr __DTOR_LIST__[1] __attribute__((used, section(".dtors"), aligned(sizeof(func_ptr)))) = { (func_ptr) (-1) };;
3649

3750
void _init(void) {
3851
int num_ctors, i;
@@ -50,7 +63,7 @@ void _init(void) {
5063

5164
void _fini(void) {
5265
int num_dtors, i;
53-
static int j;
66+
static int j = 0;
5467

5568
for (i = 1, num_dtors = 0; __DTOR_LIST__[i] != NULL; i++)
5669
num_dtors++;

0 commit comments

Comments
 (0)