From: adam Date: Wed, 2 Jan 2008 12:29:25 +0000 (+0100) Subject: split literals into low-half/high-half X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=095ebd4bc48551b5add5105806556bc608859b3b;p=fleet.git split literals into low-half/high-half --- diff --git a/src/edu/berkeley/fleet/api/Instruction.java b/src/edu/berkeley/fleet/api/Instruction.java index f021242..e3e909f 100644 --- a/src/edu/berkeley/fleet/api/Instruction.java +++ b/src/edu/berkeley/fleet/api/Instruction.java @@ -124,14 +124,16 @@ public abstract class Instruction { public static class LocalLiteral extends Executable { public final long literal; + public final boolean high; public boolean isRequeueing() { return true; } - public LocalLiteral(Pump pump, long literal, int count) { + public LocalLiteral(Pump pump, long literal, int count, boolean high) { super(pump, count); this.literal = literal; + this.high = high; } public Instruction.Executable decrementCount() { if (count==1) return null; - return new LocalLiteral(pump, literal, count-1); + return new LocalLiteral(pump, literal, count-1, high); } } diff --git a/src/edu/berkeley/fleet/assembler/Parser.java b/src/edu/berkeley/fleet/assembler/Parser.java index e4b7105..aa9bab4 100644 --- a/src/edu/berkeley/fleet/assembler/Parser.java +++ b/src/edu/berkeley/fleet/assembler/Parser.java @@ -5,6 +5,7 @@ import edu.berkeley.sbp.chr.*; import edu.berkeley.sbp.misc.*; import edu.berkeley.sbp.meta.*; import edu.berkeley.sbp.util.*; +import static edu.berkeley.fleet.util.BitManipulations.*; import java.util.*; import java.io.*; @@ -268,7 +269,7 @@ public class Parser { } else if ("massacre".equals(tt.head())) { cb.add(new Instruction.Massacre(pump)); continue; - } else if ("literal".equals(tt.head())) { + } else if ("literal".equals(tt.head())) { long literal = 0; if (tt.child(0).head().equals("CodeBagBody")) { Tree tq = tt; @@ -293,7 +294,8 @@ public class Parser { } else if ("forever".equals(tt.child(1).head())) { count = 0; } - cb.add(new Instruction.LocalLiteral(pump, literal, count)); + cb.add(new Instruction.LocalLiteral(pump, getField(36, 19, literal), count, true)); + cb.add(new Instruction.LocalLiteral(pump, getField(18, 0, literal), count, false)); continue; } Tree ttx = null; diff --git a/src/edu/berkeley/fleet/fpga/Generator.java b/src/edu/berkeley/fleet/fpga/Generator.java index 5d5667f..835b6da 100644 --- a/src/edu/berkeley/fleet/fpga/Generator.java +++ b/src/edu/berkeley/fleet/fpga/Generator.java @@ -641,8 +641,11 @@ public class Generator { new AssignAction(instruction_count_ondeck, repcount) } ); - Assignable data_latch = new SimpleAssignable(inbox ? data_out.getName() : "`packet_data("+data_out.getName()+")"); - String data_latch_input = inbox ? "`packet_data("+data_in.getName()+")" : data_in.getName(); + box.addPreCrap("wire [(`DATAWIDTH-1):0] data_latch_output;"); + box.addPreCrap("assign data_latch_output = " + (inbox ? data_out.getName() : "`packet_data("+data_out.getName()+")")+";"); + + Assignable data_latch = new SimpleAssignable(inbox ? data_out.getName() : "`packet_data("+data_out.getName()+")"); + String data_latch_input = inbox ? "`packet_data("+data_in.getName()+")" : data_in.getName(); box.new Event( new Object[] { ondeckFull.isFull(), @@ -666,7 +669,8 @@ public class Generator { new ConditionalAction("!`instruction_bit_requeue(ondeck) && `instruction_count(ondeck)!=1", doRepeat.doFill()), new ConditionalAction("`instruction_count(ondeck)==0", new AssignAction(repcount, "0")), new ConditionalAction("`instruction_count(ondeck)!=0", new AssignAction(repcount, instruction_count_ondeck+"-1")), - new ConditionalAction("`instruction_is_literal(ondeck)", new AssignAction(data_latch, "`instruction_literal(ondeck)")), + new ConditionalAction("`instruction_is_literal(ondeck)", + new AssignAction(data_latch, "`instruction_literal(ondeck,data_latch_output)")), new ConditionalAction("`instruction_bit_datain(ondeck)", data_in), new ConditionalAction("`instruction_bit_dataout(ondeck)", data_out), new ConditionalAction("`instruction_bit_tokenin(ondeck)", token_in), @@ -702,16 +706,28 @@ public class Generator { pw.println("`define instruction_is_normal(i) (i["+(OFFSET_MASK_NORMAL+WIDTH_MASK_NORMAL-1)+":"+OFFSET_MASK_NORMAL+"]=="+MASK_NORMAL+")"); pw.println("`define instruction_bit_requeue(instruction) (instruction["+OFFSET_RQ+"] && !`instruction_is_literal(instruction))"); + pw.println("`define high_half(w) (w[36:19])"); // FIXME kinda ugly that we mention numbers here + pw.println("`define low_half(w) (w[18:0])"); + pw.println("`define instruction_bit_tokenout(i) (!`instruction_is_literal(i) && i["+OFFSET_TO+"])"); pw.println("`define instruction_bit_tokenoutlast(i) (!`instruction_is_literal(i) && i["+OFFSET_IG+"])"); pw.println("`define instruction_bit_dataout(i) (!`instruction_is_literal(i) && i["+OFFSET_DO+"])"); pw.println("`define instruction_bit_latch(i) (!`instruction_is_literal(i) && i["+OFFSET_DL+"])"); pw.println("`define instruction_bit_datain(i) (!`instruction_is_literal(i) && i["+OFFSET_DI+"])"); pw.println("`define instruction_bit_tokenin(i) (!`instruction_is_literal(i) && i["+OFFSET_TI+"])"); + pw.println("`define instruction_bit_literal_loadhigh(i) (i["+OFFSET_LITERAL_LOADHIGH+"])"); int signextbits = WIDTH_WORD - WIDTH_LITERAL; + /* pw.println("`define instruction_literal(i) {{ "+signextbits+"{i["+(OFFSET_LITERAL+WIDTH_LITERAL-1)+"]}},"+ " i["+(OFFSET_LITERAL+WIDTH_LITERAL-1)+":"+OFFSET_LITERAL+"]}"); + */ + + pw.println("`define instruction_literal(i,d) "+ + " (`instruction_bit_literal_loadhigh(i) "+ + " ? { (i[17:0]), (d[18:0]) } "+ + " : { (d[36:19]), (i[18:0]) }) "); + box.dump(pw); pw.flush(); return box; diff --git a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java index 7a3d3cd..2d9dada 100644 --- a/src/edu/berkeley/fleet/ies44/InstructionEncoder.java +++ b/src/edu/berkeley/fleet/ies44/InstructionEncoder.java @@ -12,36 +12,23 @@ public abstract class InstructionEncoder { public static final int WIDTH_DEST_ADDR = 11; public static final int WIDTH_COUNT = 7; - public static final int OFFSET_MASK_LITERAL = 24; - public static final int WIDTH_MASK_LITERAL = 2; - public static final int MASK_LITERAL = 1; - /* public static final int OFFSET_MASK_LITERAL = 20; public static final int WIDTH_MASK_LITERAL = 6; - public static final int MASK_LITERAL = 13; - */ + public static final int MASK_LITERAL = 13; // this is an excessive approximation + public static final int OFFSET_MASK_MASSACRE = 14; public static final int WIDTH_MASK_MASSACRE = 26-14; public static final int MASK_MASSACRE = 1; - //public static final int OFFSET_MASK_KILL = 21; - //public static final int WIDTH_MASK_KILL = 5; - //public static final int MASK_KILL = 5; public static final int OFFSET_MASK_KILL = 14; public static final int WIDTH_MASK_KILL = 26-14; public static final int MASK_KILL = 0; - //public static final int OFFSET_MASK_UNCLOG = 21; - //public static final int WIDTH_MASK_UNCLOG = 5; - //public static final int MASK_UNCLOG = 2; public static final int OFFSET_MASK_UNCLOG = 14; public static final int WIDTH_MASK_UNCLOG = 26-14; public static final int MASK_UNCLOG = 3; - //public static final int OFFSET_MASK_CLOG = 21; - //public static final int WIDTH_MASK_CLOG = 5; - //public static final int MASK_CLOG = 4; public static final int OFFSET_MASK_CLOG = 14; public static final int WIDTH_MASK_CLOG = 26-14; public static final int MASK_CLOG = 2; @@ -60,11 +47,13 @@ public abstract class InstructionEncoder { public static final int OFFSET_DL = OFFSET_CONTROL+4; public static final int OFFSET_DI = OFFSET_CONTROL+5; public static final int OFFSET_TI = OFFSET_CONTROL+6; + public static final int OFFSET_LITERAL_LOADHIGH = 19; public static final int OFFSET_INSTRUCTIONTYPE = OFFSET_CONTROL+7; public static final int OFFSET_PUMP_ADDR = OFFSET_INSTRUCTIONTYPE+1; - public static final int OFFSET_LITERAL = OFFSET_COUNT+WIDTH_COUNT; - public static final int WIDTH_LITERAL = OFFSET_MASK_LITERAL - OFFSET_LITERAL; + public static final int OFFSET_LITERAL = 0; + public static final int WIDTH_LITERAL = 19; + /** get the bits describing this box's location on the DESTINATION HORN */ protected abstract long getDestAddr(Destination box); @@ -116,7 +105,8 @@ public abstract class InstructionEncoder { boolean dataOutDest = name.isOutbox() && dataOut && tokenOut; boolean isLiteral = getIntField(OFFSET_MASK_LITERAL+WIDTH_MASK_LITERAL-1, OFFSET_MASK_LITERAL, inst)==MASK_LITERAL; if (isLiteral) - return new Instruction.LocalLiteral(name, getSignedField(OFFSET_LITERAL+WIDTH_LITERAL-1, OFFSET_LITERAL, inst), 0); + return new Instruction.LocalLiteral(name, getField(OFFSET_LITERAL+WIDTH_LITERAL-1, OFFSET_LITERAL, inst), 0, + getField(OFFSET_LITERAL_LOADHIGH, OFFSET_LITERAL_LOADHIGH, inst)!=0); if (dataOutDest) tokenOut = false; return new Instruction.Move(name, dest, @@ -139,7 +129,8 @@ public abstract class InstructionEncoder { if (d instanceof Instruction.CodeBagDescriptor) { Instruction.CodeBagDescriptor lc = (Instruction.CodeBagDescriptor)d; - d = new Instruction.LocalLiteral(lc.pump, ((lc.offset << WIDTH_CODEBAG_SIZE)) | lc.size, 1); + // MAJOR MAJOR FIXME: upper half here... + d = new Instruction.LocalLiteral(lc.pump, ((lc.offset << WIDTH_CODEBAG_SIZE)) | lc.size, 1, false); } if (d instanceof Instruction.UnClog) { @@ -160,9 +151,8 @@ public abstract class InstructionEncoder { Instruction.LocalLiteral inst = (Instruction.LocalLiteral)d; if (inst.pump != null) { instr |= putField(OFFSET_MASK_LITERAL+WIDTH_MASK_LITERAL-1, OFFSET_MASK_LITERAL, MASK_LITERAL); - instr |= putSignedField(OFFSET_LITERAL+WIDTH_LITERAL-1, OFFSET_LITERAL, inst.literal); - // FIXME remove soon - //instr |= putField(OFFSET_COUNT+WIDTH_COUNT-1, OFFSET_COUNT, inst.count); + instr |= putField(OFFSET_LITERAL+WIDTH_LITERAL-1, OFFSET_LITERAL, inst.literal); + instr |= putField(OFFSET_LITERAL_LOADHIGH, OFFSET_LITERAL_LOADHIGH, (inst.high?1:0)); } else { instr = inst.literal; } diff --git a/src/edu/berkeley/fleet/interpreter/Inbox.java b/src/edu/berkeley/fleet/interpreter/Inbox.java index 701c6e4..2b95dfc 100644 --- a/src/edu/berkeley/fleet/interpreter/Inbox.java +++ b/src/edu/berkeley/fleet/interpreter/Inbox.java @@ -1,6 +1,7 @@ package edu.berkeley.fleet.interpreter; import edu.berkeley.sbp.util.ANSI; import edu.berkeley.fleet.api.*; +import static edu.berkeley.fleet.util.BitManipulations.*; import java.util.*; /** this is a generic inbox which stores <32-bit items (tokens or data) */ @@ -54,7 +55,12 @@ public class Inbox extends InstructionPump { if (instruction_ instanceof Instruction.Clog) { clogged++; return true; } if (instruction_ instanceof Instruction.LocalLiteral) { Instruction.LocalLiteral ll = (Instruction.LocalLiteral)instruction_; - register = new Packet(getInterpreter(), null, ll.literal, null); + long val = (register==null) ? 0 : register.value; + val = + ll.high + ? setField(36, 19, ll.literal, val) + : setField(18, 0, ll.literal, val); + register = new Packet(getInterpreter(), null, val, null); return true; } Instruction.Move instruction = (Instruction.Move)instruction_; diff --git a/src/edu/berkeley/fleet/interpreter/Outbox.java b/src/edu/berkeley/fleet/interpreter/Outbox.java index cae2ca0..4aeb320 100644 --- a/src/edu/berkeley/fleet/interpreter/Outbox.java +++ b/src/edu/berkeley/fleet/interpreter/Outbox.java @@ -2,7 +2,9 @@ package edu.berkeley.fleet.interpreter; import edu.berkeley.sbp.util.ANSI; import edu.berkeley.fleet.api.*; import edu.berkeley.fleet.ies44.*; +import edu.berkeley.sbp.util.*; import edu.berkeley.fleet.util.*; +import static edu.berkeley.fleet.util.BitManipulations.*; import edu.berkeley.fleet.api.Instruction; public class Outbox extends InstructionPump { @@ -30,7 +32,10 @@ public class Outbox extends InstructionPump { if (instruction_ instanceof Instruction.Clog) { clogged++; return true; } if (instruction_ instanceof Instruction.LocalLiteral) { Instruction.LocalLiteral ll = (Instruction.LocalLiteral)instruction_; - register = ll.literal; + register = + ll.high + ? setField(36, 19, ll.literal, register) + : setField(18, 0, ll.literal, register); return true; } Instruction.Move instruction = (Instruction.Move)instruction_; diff --git a/src/edu/berkeley/fleet/util/BitManipulations.java b/src/edu/berkeley/fleet/util/BitManipulations.java index adaf160..9bd98d4 100644 --- a/src/edu/berkeley/fleet/util/BitManipulations.java +++ b/src/edu/berkeley/fleet/util/BitManipulations.java @@ -25,7 +25,9 @@ public class BitManipulations { ret = ret >> lowBit; return ret; } - + public static long setField(int highBit, int lowBit, long val, long target) { + return (target & ~putField(highBit, lowBit, ~(-1L<<(1+highBit-lowBit)))) | putField(highBit, lowBit, val); + } public static long doPutField(int highBit, int lowBit, long val) { long mask = 0xffffffffffffffffL; mask = mask << (highBit-lowBit+1);