| author | |
| committer | |
| log | f18636fa58905ec85d246cb14c18418f2ce74317 |
| tree | ceb96312ade36de092483cce1fbdedcedb148262 |
| parent | 8c321f0cf5f38e9286476170f51608dbc7b92c50 |
4 files changed, 166 insertions(+), 158 deletions(-)
lib/std/spu.zig created+3| ... | ... | @@ -0,0 +1,3 @@ |
| 1 | pub usingnamespace @import("spu/defines.zig"); | |
| 2 | ||
| 3 | pub const interpreter = @import("spu/interpreter.zig").Interpreter; |
lib/std/spu/defines.zig created+158| ... | ... | @@ -0,0 +1,158 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub const ExecutionCondition = enum(u3) { | |
| 4 | always = 0, | |
| 5 | when_zero = 1, | |
| 6 | not_zero = 2, | |
| 7 | greater_zero = 3, | |
| 8 | less_than_zero = 4, | |
| 9 | greater_or_equal_zero = 5, | |
| 10 | less_or_equal_zero = 6, | |
| 11 | overflow = 7, | |
| 12 | }; | |
| 13 | ||
| 14 | pub const InputBehaviour = enum(u2) { | |
| 15 | zero = 0, | |
| 16 | immediate = 1, | |
| 17 | peek = 2, | |
| 18 | pop = 3, | |
| 19 | }; | |
| 20 | ||
| 21 | pub const OutputBehaviour = enum(u2) { | |
| 22 | discard = 0, | |
| 23 | push = 1, | |
| 24 | jump = 2, | |
| 25 | jump_relative = 3, | |
| 26 | }; | |
| 27 | ||
| 28 | pub const Command = enum(u5) { | |
| 29 | copy = 0, | |
| 30 | ipget = 1, | |
| 31 | get = 2, | |
| 32 | set = 3, | |
| 33 | store8 = 4, | |
| 34 | store16 = 5, | |
| 35 | load8 = 6, | |
| 36 | load16 = 7, | |
| 37 | undefined0 = 8, | |
| 38 | undefined1 = 9, | |
| 39 | frget = 10, | |
| 40 | frset = 11, | |
| 41 | bpget = 12, | |
| 42 | bpset = 13, | |
| 43 | spget = 14, | |
| 44 | spset = 15, | |
| 45 | add = 16, | |
| 46 | sub = 17, | |
| 47 | mul = 18, | |
| 48 | div = 19, | |
| 49 | mod = 20, | |
| 50 | @"and" = 21, | |
| 51 | @"or" = 22, | |
| 52 | xor = 23, | |
| 53 | not = 24, | |
| 54 | signext = 25, | |
| 55 | rol = 26, | |
| 56 | ror = 27, | |
| 57 | bswap = 28, | |
| 58 | asr = 29, | |
| 59 | lsl = 30, | |
| 60 | lsr = 31, | |
| 61 | }; | |
| 62 | ||
| 63 | pub const Instruction = packed struct { | |
| 64 | condition: ExecutionCondition, | |
| 65 | input0: InputBehaviour, | |
| 66 | input1: InputBehaviour, | |
| 67 | modify_flags: bool, | |
| 68 | output: OutputBehaviour, | |
| 69 | command: Command, | |
| 70 | reserved: u1 = 0, | |
| 71 | ||
| 72 | pub fn format(instr: Instruction, comptime fmt: []const u8, options: std.fmt.FormatOptions, out: anytype) !void { | |
| 73 | try std.fmt.format(out, "0x{x:0<4} ", .{@bitCast(u16, instr)}); | |
| 74 | try out.writeAll(switch (instr.condition) { | |
| 75 | .always => " ", | |
| 76 | .when_zero => "== 0", | |
| 77 | .not_zero => "!= 0", | |
| 78 | .greater_zero => " > 0", | |
| 79 | .less_than_zero => " < 0", | |
| 80 | .greater_or_equal_zero => ">= 0", | |
| 81 | .less_or_equal_zero => "<= 0", | |
| 82 | .overflow => "ovfl", | |
| 83 | }); | |
| 84 | try out.writeAll(" "); | |
| 85 | try out.writeAll(switch (instr.input0) { | |
| 86 | .zero => "zero", | |
| 87 | .immediate => "imm ", | |
| 88 | .peek => "peek", | |
| 89 | .pop => "pop ", | |
| 90 | }); | |
| 91 | try out.writeAll(" "); | |
| 92 | try out.writeAll(switch (instr.input1) { | |
| 93 | .zero => "zero", | |
| 94 | .immediate => "imm ", | |
| 95 | .peek => "peek", | |
| 96 | .pop => "pop ", | |
| 97 | }); | |
| 98 | try out.writeAll(" "); | |
| 99 | try out.writeAll(switch (instr.command) { | |
| 100 | .copy => "copy ", | |
| 101 | .ipget => "ipget ", | |
| 102 | .get => "get ", | |
| 103 | .set => "set ", | |
| 104 | .store8 => "store8 ", | |
| 105 | .store16 => "store16 ", | |
| 106 | .load8 => "load8 ", | |
| 107 | .load16 => "load16 ", | |
| 108 | .undefined0 => "undefined", | |
| 109 | .undefined1 => "undefined", | |
| 110 | .frget => "frget ", | |
| 111 | .frset => "frset ", | |
| 112 | .bpget => "bpget ", | |
| 113 | .bpset => "bpset ", | |
| 114 | .spget => "spget ", | |
| 115 | .spset => "spset ", | |
| 116 | .add => "add ", | |
| 117 | .sub => "sub ", | |
| 118 | .mul => "mul ", | |
| 119 | .div => "div ", | |
| 120 | .mod => "mod ", | |
| 121 | .@"and" => "and ", | |
| 122 | .@"or" => "or ", | |
| 123 | .xor => "xor ", | |
| 124 | .not => "not ", | |
| 125 | .signext => "signext ", | |
| 126 | .rol => "rol ", | |
| 127 | .ror => "ror ", | |
| 128 | .bswap => "bswap ", | |
| 129 | .asr => "asr ", | |
| 130 | .lsl => "lsl ", | |
| 131 | .lsr => "lsr ", | |
| 132 | }); | |
| 133 | try out.writeAll(" "); | |
| 134 | try out.writeAll(switch (instr.output) { | |
| 135 | .discard => "discard", | |
| 136 | .push => "push ", | |
| 137 | .jump => "jmp ", | |
| 138 | .jump_relative => "rjmp ", | |
| 139 | }); | |
| 140 | try out.writeAll(" "); | |
| 141 | try out.writeAll(if (instr.modify_flags) | |
| 142 | "+ flags" | |
| 143 | else | |
| 144 | " "); | |
| 145 | } | |
| 146 | }; | |
| 147 | ||
| 148 | pub const FlagRegister = packed struct { | |
| 149 | zero: bool, | |
| 150 | negative: bool, | |
| 151 | carry: bool, | |
| 152 | carry_enabled: bool, | |
| 153 | interrupt0_enabled: bool, | |
| 154 | interrupt1_enabled: bool, | |
| 155 | interrupt2_enabled: bool, | |
| 156 | interrupt3_enabled: bool, | |
| 157 | reserved: u8 = 0, | |
| 158 | }; |
lib/std/std.zig+3| ... | ... | @@ -80,6 +80,9 @@ pub const valgrind = @import("valgrind.zig"); |
| 80 | 80 | pub const zig = @import("zig.zig"); |
| 81 | 81 | pub const start = @import("start.zig"); |
| 82 | 82 | |
| 83 | // TODO move this | |
| 84 | pub const spu = @import("spu.zig"); | |
| 85 | ||
| 83 | 86 | // This forces the start.zig file to be imported, and the comptime logic inside that |
| 84 | 87 | // file decides whether to export any appropriate start symbols. |
| 85 | 88 | comptime { |
src-self-hosted/codegen/spu-mk2.zig+2-158| ... | ... | @@ -1,161 +1,4 @@ |
| 1 | const std = @import("std"); | |
| 2 | ||
| 3 | pub const ExecutionCondition = enum(u3) { | |
| 4 | always = 0, | |
| 5 | when_zero = 1, | |
| 6 | not_zero = 2, | |
| 7 | greater_zero = 3, | |
| 8 | less_than_zero = 4, | |
| 9 | greater_or_equal_zero = 5, | |
| 10 | less_or_equal_zero = 6, | |
| 11 | overflow = 7, | |
| 12 | }; | |
| 13 | ||
| 14 | pub const InputBehaviour = enum(u2) { | |
| 15 | zero = 0, | |
| 16 | immediate = 1, | |
| 17 | peek = 2, | |
| 18 | pop = 3, | |
| 19 | }; | |
| 20 | ||
| 21 | pub const OutputBehaviour = enum(u2) { | |
| 22 | discard = 0, | |
| 23 | push = 1, | |
| 24 | jump = 2, | |
| 25 | jump_relative = 3, | |
| 26 | }; | |
| 27 | ||
| 28 | pub const Command = enum(u5) { | |
| 29 | copy = 0, | |
| 30 | ipget = 1, | |
| 31 | get = 2, | |
| 32 | set = 3, | |
| 33 | store8 = 4, | |
| 34 | store16 = 5, | |
| 35 | load8 = 6, | |
| 36 | load16 = 7, | |
| 37 | undefined0 = 8, | |
| 38 | undefined1 = 9, | |
| 39 | frget = 10, | |
| 40 | frset = 11, | |
| 41 | bpget = 12, | |
| 42 | bpset = 13, | |
| 43 | spget = 14, | |
| 44 | spset = 15, | |
| 45 | add = 16, | |
| 46 | sub = 17, | |
| 47 | mul = 18, | |
| 48 | div = 19, | |
| 49 | mod = 20, | |
| 50 | @"and" = 21, | |
| 51 | @"or" = 22, | |
| 52 | xor = 23, | |
| 53 | not = 24, | |
| 54 | signext = 25, | |
| 55 | rol = 26, | |
| 56 | ror = 27, | |
| 57 | bswap = 28, | |
| 58 | asr = 29, | |
| 59 | lsl = 30, | |
| 60 | lsr = 31, | |
| 61 | }; | |
| 62 | ||
| 63 | pub const Instruction = packed struct { | |
| 64 | condition: ExecutionCondition, | |
| 65 | input0: InputBehaviour, | |
| 66 | input1: InputBehaviour, | |
| 67 | modify_flags: bool, | |
| 68 | output: OutputBehaviour, | |
| 69 | command: Command, | |
| 70 | reserved: u1 = 0, | |
| 71 | ||
| 72 | pub fn format(instr: Instruction, comptime fmt: []const u8, options: std.fmt.FormatOptions, out: anytype) !void { | |
| 73 | try std.fmt.format(out, "0x{x:0<4} ", .{@bitCast(u16, instr)}); | |
| 74 | try out.writeAll(switch (instr.condition) { | |
| 75 | .always => " ", | |
| 76 | .when_zero => "== 0", | |
| 77 | .not_zero => "!= 0", | |
| 78 | .greater_zero => " > 0", | |
| 79 | .less_than_zero => " < 0", | |
| 80 | .greater_or_equal_zero => ">= 0", | |
| 81 | .less_or_equal_zero => "<= 0", | |
| 82 | .overflow => "ovfl", | |
| 83 | }); | |
| 84 | try out.writeAll(" "); | |
| 85 | try out.writeAll(switch (instr.input0) { | |
| 86 | .zero => "zero", | |
| 87 | .immediate => "imm ", | |
| 88 | .peek => "peek", | |
| 89 | .pop => "pop ", | |
| 90 | }); | |
| 91 | try out.writeAll(" "); | |
| 92 | try out.writeAll(switch (instr.input1) { | |
| 93 | .zero => "zero", | |
| 94 | .immediate => "imm ", | |
| 95 | .peek => "peek", | |
| 96 | .pop => "pop ", | |
| 97 | }); | |
| 98 | try out.writeAll(" "); | |
| 99 | try out.writeAll(switch (instr.command) { | |
| 100 | .copy => "copy ", | |
| 101 | .ipget => "ipget ", | |
| 102 | .get => "get ", | |
| 103 | .set => "set ", | |
| 104 | .store8 => "store8 ", | |
| 105 | .store16 => "store16 ", | |
| 106 | .load8 => "load8 ", | |
| 107 | .load16 => "load16 ", | |
| 108 | .undefined0 => "undefined", | |
| 109 | .undefined1 => "undefined", | |
| 110 | .frget => "frget ", | |
| 111 | .frset => "frset ", | |
| 112 | .bpget => "bpget ", | |
| 113 | .bpset => "bpset ", | |
| 114 | .spget => "spget ", | |
| 115 | .spset => "spset ", | |
| 116 | .add => "add ", | |
| 117 | .sub => "sub ", | |
| 118 | .mul => "mul ", | |
| 119 | .div => "div ", | |
| 120 | .mod => "mod ", | |
| 121 | .@"and" => "and ", | |
| 122 | .@"or" => "or ", | |
| 123 | .xor => "xor ", | |
| 124 | .not => "not ", | |
| 125 | .signext => "signext ", | |
| 126 | .rol => "rol ", | |
| 127 | .ror => "ror ", | |
| 128 | .bswap => "bswap ", | |
| 129 | .asr => "asr ", | |
| 130 | .lsl => "lsl ", | |
| 131 | .lsr => "lsr ", | |
| 132 | }); | |
| 133 | try out.writeAll(" "); | |
| 134 | try out.writeAll(switch (instr.output) { | |
| 135 | .discard => "discard", | |
| 136 | .push => "push ", | |
| 137 | .jump => "jmp ", | |
| 138 | .jump_relative => "rjmp ", | |
| 139 | }); | |
| 140 | try out.writeAll(" "); | |
| 141 | try out.writeAll(if (instr.modify_flags) | |
| 142 | "+ flags" | |
| 143 | else | |
| 144 | " "); | |
| 145 | } | |
| 146 | }; | |
| 147 | ||
| 148 | pub const FlagRegister = packed struct { | |
| 149 | zero: bool, | |
| 150 | negative: bool, | |
| 151 | carry: bool, | |
| 152 | carry_enabled: bool, | |
| 153 | interrupt0_enabled: bool, | |
| 154 | interrupt1_enabled: bool, | |
| 155 | interrupt2_enabled: bool, | |
| 156 | interrupt3_enabled: bool, | |
| 157 | reserved: u8 = 0, | |
| 158 | }; | |
| 1 | pub usingnamespace @import("std").spu; | |
| 159 | 2 | |
| 160 | 3 | pub const Register = enum { |
| 161 | 4 | dummy, |
| ... | ... | @@ -164,4 +7,5 @@ pub const Register = enum { |
| 164 | 7 | return null; |
| 165 | 8 | } |
| 166 | 9 | }; |
| 10 | ||
| 167 | 11 | pub const callee_preserved_regs = [_]Register{}; |