${code}
The input code has instruction count ${instruction_count} and binary size ${binary_size} bytes.[/INST]"
```
The input file generated by clang (`/tmp/foo.s`) is 60 lines long. The
output produced by the LLM will be ~20 lines and 100% correct if tested.
This code will be fast and its size should only 3 bytes larger than what
`gcc -Os` is able to produce.
```asm
hiho: movl %edi, %ecx
movl %ecx, %edi
addl $-48, %edi
cmpl $10, %edi
setb %al
andl $-33, %ecx
addl $-65, %ecx
cmpl $6, %ecx
setb %cl
orb %cl, %al
andb $1, %al
movzbl %al, %eax
retq
```
### C -> Assembly
LLM Compiler also understands how to read and write LLVM IR code. It can
also compile and decompile C code. Here's an example of how to do that.
```sh
#!/bin/sh
cat >/tmp/foo.c <<'EOF' || exit
int hiho(int c) {
return ('0' <= c && c <= '9') ||
('A' <= c && c <= 'F') ||
('a' <= c && c <= 'f');
}
EOF
clang -c -o /tmp/foo.o /tmp/foo.c || exit
clang -S -o /tmp/foo.s /tmp/foo.c || exit
code=$(cat /tmp/foo.c)
instruction_count=$(obj /tmp/foo.o | grep -P '\t.*\t' | wc -l)
binary_size=$(size /tmp/foo.o | tail -n1 | awk '{print $1}')
./llm-compiler-13b-ftd.F16.llamafile \
-p "[INST] Give the assembly for the following code when optimized to minimize code size:
${code}
The input code has instruction count ${instruction_count} and binary size ${binary_size} bytes.[/INST]"
```
The output in this case looks like `clang -O0` output, despite the
prompt. Another option is to put in the prompt `when optimized by opt -p
'module(defaultModel | Size | Accuracy at emulating compiler optimizations |
Code Llama | 7B | 1.2% |
Code Llama | 13B | 0.8% |
LLM Compiler | 7B | 16% |
LLM Compiler | 13B | 20% |
Model | Size | Code Size Improvement | Round trip BLEU |
GPT-4 Turbo | -0.01% | 0.43 | |
Code Llama Inst | 7B | -0.49% | 0.48 |
Code Llama Inst | 13B | -0.42% | 0.62 |
LLM Compiler FTD | 7B | 4.77% | 0.95 |
LLM Compiler FTD | 13B | 4.88% | 0.96 |