Merge pull request #1754 from xexyl/richards11-opt

Restore optimiser in 2011/richards
This commit is contained in:
Landon Curt Noll authored and GitHub committed 2023-12-19 11:04:48 -08:00
commit 48520aa50c
17 files changed
+246 -55

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ CINCLUDE=
# Optimization # Optimization
# #
OPT= OPT= -O3
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "Running shark.sh:" echo "Running shark.sh:"
./shark.sh shark.sh README.md jaw.c try.sh > receive || exit 1 ./shark.sh atob shark.sh README.md jaw.c try.sh > receive || exit 1
echo "Done." echo "Done."
+8 -3
View File
@@ -42,7 +42,7 @@ CSILENCE= -Wno-bitwise-op-parentheses -Wno-char-subscripts \
-Wno-deprecated-declarations -Wno-empty-body -Wno-error \ -Wno-deprecated-declarations -Wno-empty-body -Wno-error \
-Wno-implicit-function-declaration -Wno-parentheses -Wno-pedantic \ -Wno-implicit-function-declaration -Wno-parentheses -Wno-pedantic \
-Wno-return-type -Wno-unused-parameter -Wno-unused-value \ -Wno-return-type -Wno-unused-parameter -Wno-unused-value \
-Wno-deprecated-non-prototype -Wno-deprecated-non-prototype -Wno-implicit-int
# Common C compiler warning flags # Common C compiler warning flags
# #
@@ -69,7 +69,9 @@ CINCLUDE=
# Optimization # Optimization
# #
OPT= # We DISABLE the optimiser because having it enabled will cause a crash in some
# invocations in some systems.
OPT= -O0
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
@@ -133,8 +135,11 @@ all: data ${TARGET}
clean clobber install love haste waste maker easter_egg \ clean clobber install love haste waste maker easter_egg \
sandwich supernova deep_magic magic charon pluto sandwich supernova deep_magic magic charon pluto
# We DISABLE THE OPTIMISER because when it's enabled in some conditions it
# crashes.
#
${PROG}: ${PROG}.c ${PROG}: ${PROG}.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} ${CC} ${CFLAGS} -O0 $< -o $@ ${LDFLAGS}
ag: ${PROG} ag: ${PROG}
${RM} -f $@ ${RM} -f $@
+6 -1
View File
@@ -4,6 +4,10 @@
make all make all
``` ```
NOTE: we DISABLE the optimiser because having it enabled causes some invocations
to crash in some systems.
### Bugs and (Mis)features: ### Bugs and (Mis)features:
The current status of this entry is: The current status of this entry is:
@@ -127,13 +131,14 @@ Instead, it tries to achieve both its speed and its obscurity through a
careful choice of algorithms. Some of the finer points of those careful choice of algorithms. Some of the finer points of those
algorithms are outlined in the spoiler below. algorithms are outlined in the spoiler below.
### How it works: ### How it works:
Here follows a description of some of the data structures and Here follows a description of some of the data structures and
algorithms used by AG. It is by no means complete, but it may help algorithms used by AG. It is by no means complete, but it may help
you get an idea about the general principles. you get an idea about the general principles.
-- ---
Internally, AG represents words and sentences as arrays of 32 Internally, AG represents words and sentences as arrays of 32
4-bit integer elements. Each element represents the number of 4-bit integer elements. Each element represents the number of
+117
View File
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
#
# try.sh - demonstrate IOCCC winner 1992/gson
#
# make sure CC is set so that when we do make CC="$CC" it isn't empty. Doing it
# this way allows us to have the user specify a different compiler in an easy
# way.
if [[ -z "$CC" ]]; then
CC="cc"
fi
make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown
clear
# attempt to find a dictionary file if DICT unset or not a regular readable file
#
if [[ -z "$DICT" || ! -f "$DICT" || ! -r "$DICT" ]]; then
DICT="/usr/share/dict/words"
if [[ ! -r "$DICT" ]]; then
DICT="/usr/share/lib/spell/words"
if [[ ! -r "$DICT" ]]; then
DICT="/usr/ucblib/dict/words"
if [[ ! -r "$DICT" ]]; then
DICT="/dev/null"
fi
fi
fi
fi
# safety check that DICT is not empty and is a readable file
#
if [[ -n "$DICT" && -f "$DICT" && -r "$DICT" ]]; then
echo "$ ./ag free software foundation < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag free software foundation < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag obfuscated c contest < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag obfuscated c contest < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag unix international < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag unix international < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag george bush < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag george bush < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag bill clinton < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag bill clinton < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag ross perot < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag ross perot < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag paul e tsongas < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag paul e tsongas < "$DICT" 2>/dev/null | less -rEXF
fi
# now try making our own dictionary with mkdict.sh:
#
rm -f words
cat README.md try.sh Makefile | ./mkdict.sh > words
DICT="words"
read -r -n 1 -p "Press any key to use our own dict from mkdict.sh: "
echo 1>&2
echo "$ ./ag free software foundation < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag free software foundation < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag obfuscated c contest < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag obfuscated c contest < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag unix international < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag unix international < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag george bush < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag george bush < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag bill clinton < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag bill clinton < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag ross perot < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag ross perot < "$DICT" 2>/dev/null | less -rEXF
echo "$ ./ag paul e tsongas < $DICT" 1>&2
read -r -n 1 -p "Press any key to continue (space = next page, q = quit): "
echo 1>&2
./ag paul e tsongas < "$DICT" 2>/dev/null | less -rEXF
-5
View File
@@ -15,11 +15,6 @@ make CC="$CC" all >/dev/null || exit 1
# clear screen after compilation so that only the entry is shown # clear screen after compilation so that only the entry is shown
clear clear
if [[ ! -f "tomx" || ! -e "tomx" ]]; then
echo "Compiling tomx.c:" 1>&2
make all || exit 1
fi
echo "Running tomx:" 1>&2 echo "Running tomx:" 1>&2
echo "$ ./tomx" 1>&2 echo "$ ./tomx" 1>&2
./tomx ./tomx
+1 -1
View File
@@ -71,7 +71,7 @@ CINCLUDE=
# Optimization # Optimization
# #
OPT= OPT= -O3
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
+1 -1
View File
@@ -68,7 +68,7 @@ CINCLUDE= -I ${X11_INCDIR} -I ${X11_INCDIR}/X11
# Optimization # Optimization
# #
OPT= -ggdb3 OPT= -O3
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
+5 -2
View File
@@ -66,7 +66,8 @@ CINCLUDE= -include stdio.h -include setjmp.h -include string.h -include time.h -
# Optimization # Optimization
# #
OPT= # We DISABLE the optimiser because having it enabled BREAKS the program.
OPT= -O0
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
@@ -131,8 +132,10 @@ all: data ${TARGET}
clean clobber install love haste waste maker easter_egg \ clean clobber install love haste waste maker easter_egg \
sandwich supernova deep_magic magic charon pluto sandwich supernova deep_magic magic charon pluto
# NOTE: We FORCE the use of -O0 even if someone overrides it because this entry
# will not work with it enabled.
${PROG}: ${PROG}.c ${PROG}: ${PROG}.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} ${CC} ${CFLAGS} -O0 $< -o $@ ${LDFLAGS}
# alternative executable # alternative executable
# #
+3
View File
@@ -4,6 +4,9 @@
make make
``` ```
NOTE: We FORCE the use of -O0 even if someone overrides it because this entry
will not work with it enabled.
## To use: ## To use:
+5 -2
View File
@@ -66,7 +66,8 @@ CINCLUDE=
# Optimization # Optimization
# #
OPT= # We DISABLE the optimiser because having it enabled BREAKS the program.
OPT= -O0
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
@@ -129,8 +130,10 @@ all: data ${TARGET}
clean clobber install love haste waste maker easter_egg \ clean clobber install love haste waste maker easter_egg \
sandwich supernova deep_magic magic charon pluto sandwich supernova deep_magic magic charon pluto
# NOTE: We FORCE the use of -O0 even if someone overrides it because this entry
# will not work with it enabled.
${PROG}: ${PROG}.c ${PROG}: ${PROG}.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} ${CC} ${CFLAGS} -O0 $< -o $@ ${LDFLAGS}
# alternative executable # alternative executable
# #
+7 -15
View File
@@ -4,6 +4,9 @@
make make
``` ```
NOTE: We FORCE the use of -O0 even if someone overrides it because this entry
will not work with it enabled.
## To use: ## To use:
@@ -15,22 +18,9 @@ make
### Try: ### Try:
```sh ```sh
./kopczynski < kopczynski-8a ./try
./kopczynski < kopczynski-8b
./kopczynski < kopczynski-8c
./kopczynski < kopczynski-9
./kopczynski < kopczynski-10
./kopczynski < kopczynski-11
``` ```
Also try:
```sh
./kopczynski < kopczynski-a
```
What happens?
What happens if you feed the program source to the program? Can you figure out What happens if you feed the program source to the program? Can you figure out
why? why?
@@ -38,7 +28,9 @@ why?
## Alternate code: ## Alternate code:
The judges modified the program to print its result. The original The judges modified the program to print its result. The original
program returned the result as an exit code: program returned the result as an exit code which is what the alternate version
does.
### Alternate build: ### Alternate build:
+5 -2
View File
@@ -69,8 +69,9 @@ CDEFINE=
CINCLUDE= -include stdio.h -include string.h -include unistd.h -include stdlib.h CINCLUDE= -include stdio.h -include string.h -include unistd.h -include stdlib.h
# Optimization # Optimization
# We DISABLE the optimiser because having it enabled BREAKS the program.
# #
OPT= OPT= -O0
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
@@ -135,8 +136,10 @@ all: data ${TARGET}
clean clobber install love haste waste maker easter_egg \ clean clobber install love haste waste maker easter_egg \
sandwich supernova deep_magic magic charon pluto sandwich supernova deep_magic magic charon pluto
# NOTE: We FORCE the use of -O0 even if someone overrides it because this entry
# will not work with it enabled.
${PROG}: ${PROG}.c ${PROG}: ${PROG}.c
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} ${CC} ${CFLAGS} -O0 $< -o $@ ${LDFLAGS}
test: ${PROG} test.sh test: ${PROG} test.sh
./test.sh ./test.sh
+3
View File
@@ -4,6 +4,9 @@
make make
``` ```
NOTE: We FORCE the use of -O0 even if someone overrides it because this entry
will not work with it enabled.
### Bugs and (Mis)features: ### Bugs and (Mis)features:
+1 -1
View File
@@ -66,7 +66,7 @@ CINCLUDE= -include stdlib.h -include string.h -include stdio.h -include ctype.h
# Optimization # Optimization
# #
OPT= OPT= -O3
# Default flags for ANSI C compilation # Default flags for ANSI C compilation
# #
+69 -1
View File
@@ -302,6 +302,9 @@ crashes.
NOTE: this does NOT apply to entries under the INABIAF status (though they're NOTE: this does NOT apply to entries under the INABIAF status (though they're
not mutually exclusive in some cases). not mutually exclusive in some cases).
REMINDER: if you're debugging a crash it will be very helpful to have `-O0 -g`
or if you can `-ggdb3` when compiling as that will help with debugging symbols.
## STATUS: uses gets() - change to fgets() if possible ## STATUS: uses gets() - change to fgets() if possible
@@ -667,6 +670,60 @@ Enjoy! :-)
# 1990 # 1990
## 1990 jaw
### STATUS: known bug - please help us fix
### Source code: [1990/jaw/jaw.c](1990/jaw/jaw.c)
### Information: [1990/jaw/README.md](1990/jaw/README.md)
[Cody Boone Ferguson](https://www.ioccc.org/winners.html#Cody_Boone_Ferguson)
fixed some issues in this program and [Yusuke
Endoh](https://www.ioccc.org/winners.html#Yusuke_Endoh) provided the `btoa`
script but it appears there is a bug in this entry. The judges wrote that to
test the entry one can do:
```sh
echo "Quartz glyph jocks vend, fix, BMW." | compress | ./btoa | ./jaw
```
which should apply the identity transformation to a minimal holoalphabetic
sentence.
But doing this shows instead:
```sh
echo "Quartz glyph jocks vend, fix, BMW." | compress | ./btoa | ./jaw
a얖?)V...?????777??hC??h??-? )SSSSXXX????r?L=???*?-???ppp,,,?R
?j
111-)))? '..F@E
???b111?
..F..F.?n,,,,,L@E$
```
Notice how there's no newline at the end: that final `$` is the prompt.
If one does, however:
```sh
echo "Quartz glyph jocks vend, fix, BMW." | compress | ./btoa | ./jaw | ./jaw
```
they will get just
```
oops
```
which seems to be an error message (one of the fixes was to make it not use
`perror(3)` - this fixed something else though it's no longer known what).
The script [shark.sh](/1990/jaw/shark.sh) has some issues too in that due to
path not having `.` (this and maybe some other things were fixed) and `tar` not
wanting to accept reading from `stdin` (this in particular) even with the right
options used, seemingly, it has to write to disk the tarball which seems to
defeat the purpose. This would ideally be fixed.
## 1990 theorem ## 1990 theorem
### STATUS: INABIAF - please **DO NOT** fix ### STATUS: INABIAF - please **DO NOT** fix
@@ -839,7 +896,18 @@ problem of `gets()` being used in a more complex way.
It would be ideal if it were to use `fgets()` though. This will probably be It would be ideal if it were to use `fgets()` though. This will probably be
looked at later but you're welcome to try and fix this too! A tip on how looked at later but you're welcome to try and fix this too! A tip on how
`gets()` is being used is in the [FAQ](/faq.md#gets) file. `gets()` is being used from Cody:
Previously it had a buffer size of 256 which could easily overflow. In this
entry `gets(3)` is used in a more complicated way: first `m` is set to `*++p` in
a for loop where `p` is argv. Later `m` is set to point to `h` which was of size
256. `gets(3)` is called as `m = gets(m)`) but trying to change it to use
`fgets(3)` proved more a problem. Since the input must come from the command
line Cody changed the buffer size to `ARG_MAX+1` which should be enough (again
theoretically) especially since the command expects redirecting a dictionary
file as part of the command line. This also makes it possible for longer strings
to be read (in case the `gets(3)` was not used in a loop).
## 1992 kivinen ## 1992 kivinen
+13 -19
View File
@@ -1420,25 +1420,19 @@ commands that we suggested and some additional ones that provide for some fun.
[Cody](#cody) fixed a crash that prevented this entry from working in some cases in some [Cody](#cody) fixed a crash that prevented this entry from working in some cases in some
systems (like macOS) by disabling the optimiser in the Makefile. systems (like macOS) by disabling the optimiser in the Makefile.
Cody also changed the buffer size in such a way that `gets(3)` should be safe Cody also added the [try.sh](/1992/gson/try.sh) script.
(theoretically) as it comes from the command line (though it can also read input
from stdin after starting the program). Ideally `fgets(3)` would be used but this
is a more problematic. Previously it had a buffer size of 256 which could
easily overflow. In this entry `gets(3)` is used in a more complicated way:
first `m` is set to `*++p` in a for loop where `p` is argv. Later `m` is set to
point to `h` which was of size 256. `gets(3)` is called as `m = gets(m)`) but
trying to change it to use `fgets(3)` proved more a problem. Since the input must
come from the command line Cody changed the buffer size to `ARG_MAX+1` which
should be enough (again theoretically) especially since the command expects
redirecting a dictionary file as part of the command line. This also makes it
possible for longer strings to be read (in case the `gets(3)` was not used in a
loop).
Cody also added the [mkdict.sh](/1992/gson/mkdict.sh) script that the author Cody also added the [mkdict.sh](/1992/gson/mkdict.sh) script that the author
included in their remarks. See the README.md for its purpose. It was NOT fixed included in their remarks. See the README.md for its purpose. It was NOT fixed
for [ShellCheck](https://github.com/koalaman/shellcheck) for [ShellCheck](https://github.com/koalaman/shellcheck)
because the author deliberately obfuscated it so **PLEASE DO NOT because the author deliberately obfuscated it so **PLEASE *DO NOT* FIX THIS OR
FIX THIS**. MODERNISE IT**.
Cody also changed the buffer size in such a way that `gets(3)` should be safe
(well, theoretically) as it comes from the command line (though it can also read input
from `stdin` after starting the program). Ideally `fgets(3)` would be used but this
is a more problematic. See [1992/gson in bugs.md](/bugs.md#1992-gson) for more
details if you're interested in trying to understand it (or fix?).
## <a name="1992_imc"></a>[1992/imc](/1992/imc/imc.c) ([README.md](/1992/imc/README.md])) ## <a name="1992_imc"></a>[1992/imc](/1992/imc/imc.c) ([README.md](/1992/imc/README.md]))
@@ -2671,16 +2665,16 @@ For clang the problem was that `main()` had one arg, a `char *` and this is not
allowed in any version of clang. In some versions it is allowed if the arg is an allowed in any version of clang. In some versions it is allowed if the arg is an
`int` but never if it's anything else. To get it to work took numerous changes. `int` but never if it's anything else. To get it to work took numerous changes.
First the inclusion of `setjmp.h` was necessary. Without this `longjmp()` First the inclusion of `setjmp.h` was necessary. Without this `longjmp(3)`
implicitly returned int which was used for the purpose of binary expression but implicitly returned `int` which was used for the purpose of binary expression but
this no longer worked. this no longer worked.
But by including `setjmp.h` it naturally made the binary expressions invalid (as But by including `setjmp.h` it naturally made the binary expressions invalid (as
it returns void which no longer is allowed in binary expressions) so the comma it returns `void` which is not allowed in binary expressions) so the comma
operator with `0` (`,0`) had to be used (`,1` was tried first but this did not operator with `0` (`,0`) had to be used (`,1` was tried first but this did not
work right). work right).
`longjmp()` was being called with one arg which was an element `longjmp(3)` was being called with one arg which was an element
of an `int[4][1000]` which had to be changed to a `jmp_buf p[4]` (this due to of an `int[4][1000]` which had to be changed to a `jmp_buf p[4]` (this due to
the prototype being included). the prototype being included).