// Copyright 2009 Altera Corporation. All rights reserved. // Altera products are protected under numerous U.S. and foreign patents, // maskwork rights, copyrights and other intellectual property laws. // // This reference design file, and your use thereof, is subject to and governed // by the terms and conditions of the applicable Altera Reference Design // License Agreement (either as signed by you or found at www.altera.com). By // using this reference design file, you indicate your acceptance of such terms // and conditions between you and Altera Corporation. In the event that you do // not agree with such terms and conditions, you may not use the reference // design file and please promptly destroy any copies you have made. // // This reference design file is being provided on an "as-is" basis and as an // accommodation and therefore all warranties, representations or guarantees of // any kind (whether express, implied or statutory) including, without // limitation, warranties of merchantability, non-infringement, or fitness for // a particular purpose, are specifically disclaimed. By making this reference // design file available, Altera expressly does not recommend, suggest or // require that this reference design file be used in combination with any // other product not provided by Altera. ///////////////////////////////////////////////////////////////////////////// // baeckler - 03-27-2009 #include #include void panic (char * msg) { fprintf (stdout,"PANIC: %s\n",msg); exit(1); } int const word_out_bits = 67; int const word_in_bits = 40; int const storage_len = word_out_bits-1+word_in_bits; bool storage [storage_len]; int holding = 0; void init_storage () { int n = 0; for (n=0; n=storage_len-word_out_bits; n--) { storage[n] = true; } holding = word_out_bits; } // bool OK? bool shl_storage (int shift_dist) { int n = 0; for (n=storage_len-1; n>=storage_len-shift_dist; n--) { if (storage[n]) { //panic ("SHL is losing most significant bits"); return (false); } } for (n=storage_len-1; n>=shift_dist; n--) { storage[n] = storage[n-shift_dist]; } for (n=0; n 0 && !storage[word_in_bits+shift_dist]) { // not adjoining exitsting residue return (false); } for (n=0; n= storage_len) { // ("Access out of range"); return (false); } if (storage[n+shift_dist]) { // ("New data is stomping old"); return (false); } storage[n+shift_dist] = true; } holding += word_in_bits; return (true); } // scratch area for solution int dat_shift [100]; int store_shift [100]; int extract_point [100]; // bool found a solution? bool search (int phase) { bool viable = true; bool last_storage [storage_len]; int last_holding; int n,a,b,c,bb,aa; if (phase == word_out_bits+1) return (true); // save state for (n=0; n= word_out_bits) { if (!extract_word (a)) { viable = false; bb = 100; // if A doesn't work all B,C are wash } } else { // extract point a is a don't care a = 0; } if (viable) { if (!shl_storage (b)) { viable = false; c = 100; // if B doesn't work all C are wash } } if (viable) { if (!insert_data (c)) viable = false; } // if it looks OK keep searching if (viable) { fprintf (stdout,"phase %d - %d %d %d works\n",phase,a,b,c); if (search (phase+1)) { fprintf (stdout,"sol phase %d ext %d shl storage %d shl data %d\n", phase,a,b,c); dat_shift [phase] = c; store_shift [phase] = b; extract_point [phase] = a; return (true); } } // restore state for (n=0; n