#!/usr/bin/perl -w # We want to generate a stream of characters such that differences between # character pairs cover all the ranges between [-255, 255]. # # Naively, we could generate the cartesian product of [0,255] x [0,255], # resulting in a 128K input file, and the output C code from that causes # both GCC and Clang to use more than ~2G of memory to compile, even with # optimizations disabled. # # We can do a lot better by generating all byte pairs 0 x [0,255] instead. # Each byte pair covers the deltas in the range of [0,255], and overlap with # the starting byte of the next pair covers [-254,0]. We need one extra # zero byte at the end to cover the -255 case. This results in a 513 byte # file, which costs GCC only ~300MB of RAM to compile. use strict; die "$0 \n" unless $#ARGV == 0; open my $output, ">$ARGV[0]" or die $!; foreach my $i (0..255) { print $output chr(0), chr($i); } print $output chr(0); close $output;