2008-02-14 10:08:11 -08:00
|
|
|
/*
|
|
|
|
|
* (C) Copyright IBM Corporation 2008
|
|
|
|
|
* All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* on the rights to use, copy, modify, merge, publish, distribute, sub
|
|
|
|
|
* license, and/or sell copies of the Software, and to permit persons to whom
|
|
|
|
|
* the Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* AUTHORS, COPYRIGHT HOLDERS, AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
|
* USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2008-02-19 14:00:16 +09:00
|
|
|
* \file
|
2008-02-14 10:08:11 -08:00
|
|
|
* Real-time assembly generation interface for Cell B.E. SPEs.
|
|
|
|
|
*
|
|
|
|
|
* \author Ian Romanick <idr@us.ibm.com>
|
2008-09-12 21:52:47 -06:00
|
|
|
* \author Brian Paul
|
2008-02-14 10:08:11 -08:00
|
|
|
*/
|
|
|
|
|
|
2008-09-12 21:52:47 -06:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-02-19 14:00:16 +09:00
|
|
|
#include "pipe/p_compiler.h"
|
2008-08-24 17:48:55 -06:00
|
|
|
#include "util/u_memory.h"
|
2008-02-19 14:00:16 +09:00
|
|
|
#include "rtasm_ppc_spe.h"
|
|
|
|
|
|
2008-09-12 21:52:47 -06:00
|
|
|
|
2008-02-19 14:00:16 +09:00
|
|
|
#ifdef GALLIUM_CELL
|
2008-02-14 10:08:11 -08:00
|
|
|
/**
|
|
|
|
|
* SPE instruction types
|
|
|
|
|
*
|
|
|
|
|
* There are 6 primary instruction encodings used on the Cell's SPEs. Each of
|
|
|
|
|
* the following unions encodes one type.
|
|
|
|
|
*
|
|
|
|
|
* \bug
|
|
|
|
|
* If, at some point, we start generating SPE code from a little-endian host
|
|
|
|
|
* these unions will not work.
|
|
|
|
|
*/
|
|
|
|
|
/*@{*/
|
|
|
|
|
/**
|
|
|
|
|
* Encode one output register with two input registers
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RR {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:11;
|
|
|
|
|
unsigned rB:7;
|
|
|
|
|
unsigned rA:7;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encode one output register with three input registers
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RRR {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:4;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
unsigned rB:7;
|
|
|
|
|
unsigned rA:7;
|
|
|
|
|
unsigned rC:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encode one output register with one input reg. and a 7-bit signed immed
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RI7 {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:11;
|
|
|
|
|
unsigned i7:7;
|
|
|
|
|
unsigned rA:7;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-02-14 18:29:51 -08:00
|
|
|
/**
|
|
|
|
|
* Encode one output register with one input reg. and an 8-bit signed immed
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RI8 {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:10;
|
|
|
|
|
unsigned i8:8;
|
|
|
|
|
unsigned rA:7;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-02-14 10:08:11 -08:00
|
|
|
/**
|
|
|
|
|
* Encode one output register with one input reg. and a 10-bit signed immed
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RI10 {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:8;
|
|
|
|
|
unsigned i10:10;
|
|
|
|
|
unsigned rA:7;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encode one output register with a 16-bit signed immediate
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RI16 {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:9;
|
|
|
|
|
unsigned i16:16;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Encode one output register with a 18-bit signed immediate
|
|
|
|
|
*/
|
|
|
|
|
union spe_inst_RI18 {
|
|
|
|
|
uint32_t bits;
|
|
|
|
|
struct {
|
|
|
|
|
unsigned op:7;
|
|
|
|
|
unsigned i18:18;
|
|
|
|
|
unsigned rT:7;
|
|
|
|
|
} inst;
|
|
|
|
|
};
|
|
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
|
|
|
2008-09-12 21:52:47 -06:00
|
|
|
static void
|
|
|
|
|
indent(const struct spe_function *p)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < p->indent; i++) {
|
|
|
|
|
putchar(' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
rem_prefix(const char *longname)
|
|
|
|
|
{
|
|
|
|
|
return longname + 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-14 10:08:11 -08:00
|
|
|
static void emit_RR(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
unsigned rA, unsigned rB, const char *name)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RR inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.rB = rB;
|
|
|
|
|
inst.inst.rA = rA;
|
|
|
|
|
inst.inst.rT = rT;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("%s\t$%d, $%d, $%d\n", rem_prefix(name), rT, rA, rB);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void emit_RRR(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
unsigned rA, unsigned rB, unsigned rC, const char *name)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RRR inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.rT = rT;
|
|
|
|
|
inst.inst.rB = rB;
|
|
|
|
|
inst.inst.rA = rA;
|
|
|
|
|
inst.inst.rC = rC;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("%s\t$%d, $%d, $%d, $%d\n", rem_prefix(name), rT, rA, rB, rC);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void emit_RI7(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
unsigned rA, int imm, const char *name)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RI7 inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.i7 = imm;
|
|
|
|
|
inst.inst.rA = rA;
|
|
|
|
|
inst.inst.rT = rT;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("%s\t$%d, $%d, 0x%x\n", rem_prefix(name), rT, rA, imm);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-14 18:29:51 -08:00
|
|
|
static void emit_RI8(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
unsigned rA, int imm, const char *name)
|
2008-02-14 18:29:51 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RI8 inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.i8 = imm;
|
|
|
|
|
inst.inst.rA = rA;
|
|
|
|
|
inst.inst.rT = rT;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("%s\t$%d, $%d, 0x%x\n", rem_prefix(name), rT, rA, imm);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 18:29:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-14 10:08:11 -08:00
|
|
|
static void emit_RI10(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
unsigned rA, int imm, const char *name)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RI10 inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.i10 = imm;
|
|
|
|
|
inst.inst.rA = rA;
|
|
|
|
|
inst.inst.rT = rT;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
if (strcmp(name, "spe_lqd") == 0 ||
|
|
|
|
|
strcmp(name, "spe_stqd") == 0)
|
|
|
|
|
printf("%s\t$%d, 0x%x($%d)\n", rem_prefix(name), rT, imm, rA);
|
|
|
|
|
else
|
|
|
|
|
printf("%s\t$%d, $%d, 0x%x\n", rem_prefix(name), rT, rA, imm);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void emit_RI16(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
int imm, const char *name)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RI16 inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.i16 = imm;
|
|
|
|
|
inst.inst.rT = rT;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("%s\t$%d, 0x%x\n", rem_prefix(name), rT, imm);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void emit_RI18(struct spe_function *p, unsigned op, unsigned rT,
|
2008-09-12 21:52:47 -06:00
|
|
|
int imm, const char *name)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
|
|
|
|
union spe_inst_RI18 inst;
|
|
|
|
|
inst.inst.op = op;
|
|
|
|
|
inst.inst.i18 = imm;
|
|
|
|
|
inst.inst.rT = rT;
|
2008-09-10 17:11:48 -06:00
|
|
|
p->store[p->num_inst++] = inst.bits;
|
|
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-09-12 21:52:47 -06:00
|
|
|
if (p->print) {
|
|
|
|
|
indent(p);
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("%s\t$%d, 0x%x\n", rem_prefix(name), rT, imm);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define EMIT_(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RR(p, _op, rT, 0, 0, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_R(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, unsigned rA) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RR(p, _op, rT, rA, 0, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_RR(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RR(p, _op, rT, rA, rB, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_RRR(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, unsigned rA, unsigned rB, unsigned rC) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RRR(p, _op, rT, rA, rB, rC, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_RI7(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, _op, rT, rA, imm, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-03-24 12:15:59 -07:00
|
|
|
#define EMIT_RI8(_name, _op, bias) \
|
2008-02-14 18:29:51 -08:00
|
|
|
void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI8(p, _op, rT, rA, bias - imm, __FUNCTION__); \
|
2008-02-14 18:29:51 -08:00
|
|
|
}
|
|
|
|
|
|
2008-02-14 10:08:11 -08:00
|
|
|
#define EMIT_RI10(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, unsigned rA, int imm) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI10(p, _op, rT, rA, imm, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_RI16(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, int imm) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI16(p, _op, rT, imm, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_RI18(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, unsigned rT, int imm) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI18(p, _op, rT, imm, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define EMIT_I16(_name, _op) \
|
|
|
|
|
void _name (struct spe_function *p, int imm) \
|
|
|
|
|
{ \
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI16(p, _op, 0, imm, __FUNCTION__); \
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-02-19 14:00:16 +09:00
|
|
|
#include "rtasm_ppc_spe.h"
|
2008-02-14 10:08:11 -08:00
|
|
|
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/**
|
|
|
|
|
* Initialize an spe_function.
|
|
|
|
|
* \param code_size size of instruction buffer to allocate, in bytes.
|
2008-02-14 10:08:11 -08:00
|
|
|
*/
|
|
|
|
|
void spe_init_func(struct spe_function *p, unsigned code_size)
|
|
|
|
|
{
|
2008-02-19 14:00:16 +09:00
|
|
|
p->store = align_malloc(code_size, 16);
|
2008-09-10 17:11:48 -06:00
|
|
|
p->num_inst = 0;
|
|
|
|
|
p->max_inst = code_size / SPE_INST_SIZE;
|
|
|
|
|
|
2008-03-10 16:28:54 -07:00
|
|
|
/* Conservatively treat R0 - R2 and R80 - R127 as non-volatile.
|
|
|
|
|
*/
|
|
|
|
|
p->regs[0] = ~7;
|
|
|
|
|
p->regs[1] = (1U << (80 - 64)) - 1;
|
2008-09-12 21:52:47 -06:00
|
|
|
|
|
|
|
|
p->print = false;
|
|
|
|
|
p->indent = 0;
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void spe_release_func(struct spe_function *p)
|
|
|
|
|
{
|
2008-09-10 17:11:48 -06:00
|
|
|
assert(p->num_inst <= p->max_inst);
|
2008-03-17 16:07:54 -07:00
|
|
|
if (p->store != NULL) {
|
|
|
|
|
align_free(p->store);
|
|
|
|
|
}
|
2008-02-14 10:08:11 -08:00
|
|
|
p->store = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/**
|
2008-09-18 01:29:41 -06:00
|
|
|
* Allocate a SPE register.
|
2008-09-05 13:54:14 -06:00
|
|
|
* \return register index or -1 if none left.
|
|
|
|
|
*/
|
2008-03-10 16:28:54 -07:00
|
|
|
int spe_allocate_available_register(struct spe_function *p)
|
|
|
|
|
{
|
|
|
|
|
unsigned i;
|
2008-09-05 13:54:14 -06:00
|
|
|
for (i = 0; i < SPE_NUM_REGS; i++) {
|
2008-03-17 15:37:09 -07:00
|
|
|
const uint64_t mask = (1ULL << (i % 64));
|
|
|
|
|
const unsigned idx = i / 64;
|
2008-03-10 16:28:54 -07:00
|
|
|
|
2008-09-10 17:11:48 -06:00
|
|
|
assert(idx < 2);
|
2008-03-10 16:28:54 -07:00
|
|
|
if ((p->regs[idx] & mask) != 0) {
|
|
|
|
|
p->regs[idx] &= ~mask;
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/**
|
|
|
|
|
* Mark the given SPE register as "allocated".
|
|
|
|
|
*/
|
2008-03-10 16:28:54 -07:00
|
|
|
int spe_allocate_register(struct spe_function *p, int reg)
|
|
|
|
|
{
|
2008-03-17 15:37:09 -07:00
|
|
|
const unsigned idx = reg / 64;
|
|
|
|
|
const unsigned bit = reg % 64;
|
2008-03-10 16:28:54 -07:00
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
assert(reg < SPE_NUM_REGS);
|
2008-03-10 16:28:54 -07:00
|
|
|
assert((p->regs[idx] & (1ULL << bit)) != 0);
|
|
|
|
|
|
|
|
|
|
p->regs[idx] &= ~(1ULL << bit);
|
|
|
|
|
return reg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/**
|
|
|
|
|
* Mark the given SPE register as "unallocated".
|
|
|
|
|
*/
|
2008-03-10 16:28:54 -07:00
|
|
|
void spe_release_register(struct spe_function *p, int reg)
|
|
|
|
|
{
|
2008-03-17 15:37:09 -07:00
|
|
|
const unsigned idx = reg / 64;
|
|
|
|
|
const unsigned bit = reg % 64;
|
2008-03-10 16:28:54 -07:00
|
|
|
|
2008-09-10 17:11:48 -06:00
|
|
|
assert(idx < 2);
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
assert(reg < SPE_NUM_REGS);
|
2008-03-10 16:28:54 -07:00
|
|
|
assert((p->regs[idx] & (1ULL << bit)) == 0);
|
|
|
|
|
|
|
|
|
|
p->regs[idx] |= (1ULL << bit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-12 21:52:47 -06:00
|
|
|
void
|
|
|
|
|
spe_print_code(struct spe_function *p, boolean enable)
|
|
|
|
|
{
|
|
|
|
|
p->print = enable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_indent(struct spe_function *p, int spaces)
|
|
|
|
|
{
|
|
|
|
|
p->indent += spaces;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extern void
|
|
|
|
|
spe_comment(struct spe_function *p, int rel_indent, const char *s)
|
|
|
|
|
{
|
|
|
|
|
if (p->print) {
|
|
|
|
|
p->indent += rel_indent;
|
|
|
|
|
indent(p);
|
|
|
|
|
p->indent -= rel_indent;
|
2008-09-15 15:10:02 -06:00
|
|
|
printf("# %s\n", s);
|
2008-09-12 21:52:47 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/**
|
|
|
|
|
* For branch instructions:
|
|
|
|
|
* \param d if 1, disable interupts if branch is taken
|
|
|
|
|
* \param e if 1, enable interupts if branch is taken
|
|
|
|
|
* If d and e are both zero, don't change interupt status (right?)
|
|
|
|
|
*/
|
2008-03-10 16:28:54 -07:00
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch Indirect to address in rA */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_bi(struct spe_function *p, unsigned rA, int d, int e)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x1a8, 0, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Interupt Return */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_iret(struct spe_function *p, unsigned rA, int d, int e)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x1aa, 0, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch indirect and set link on external data */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_bisled(struct spe_function *p, unsigned rT, unsigned rA, int d,
|
2008-02-14 10:08:11 -08:00
|
|
|
int e)
|
|
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x1ab, rT, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch indirect and set link. Save PC in rT, jump to rA. */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_bisl(struct spe_function *p, unsigned rT, unsigned rA, int d,
|
2008-02-14 10:08:11 -08:00
|
|
|
int e)
|
|
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x1a9, rT, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch indirect if zero word. If rT.word[0]==0, jump to rA. */
|
|
|
|
|
void spe_biz(struct spe_function *p, unsigned rT, unsigned rA, int d, int e)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x128, rT, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch indirect if non-zero word. If rT.word[0]!=0, jump to rA. */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_binz(struct spe_function *p, unsigned rT, unsigned rA, int d, int e)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x129, rT, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch indirect if zero halfword. If rT.halfword[1]==0, jump to rA. */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_bihz(struct spe_function *p, unsigned rT, unsigned rA, int d, int e)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x12a, rT, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
2008-09-05 13:54:14 -06:00
|
|
|
/** Branch indirect if non-zero halfword. If rT.halfword[1]!=0, jump to rA. */
|
2008-02-14 17:42:34 -08:00
|
|
|
void spe_bihnz(struct spe_function *p, unsigned rT, unsigned rA, int d, int e)
|
2008-02-14 10:08:11 -08:00
|
|
|
{
|
2008-09-12 21:52:47 -06:00
|
|
|
emit_RI7(p, 0x12b, rT, rA, (d << 5) | (e << 4), __FUNCTION__);
|
2008-02-14 10:08:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Hint-for-branch instructions
|
|
|
|
|
*/
|
|
|
|
|
#if 0
|
|
|
|
|
hbr;
|
|
|
|
|
hbra;
|
|
|
|
|
hbrr;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Control instructions
|
|
|
|
|
*/
|
|
|
|
|
#if 0
|
|
|
|
|
stop;
|
2008-02-14 17:42:34 -08:00
|
|
|
EMIT_RR (spe_stopd, 0x140);
|
|
|
|
|
EMIT_ (spe_lnop, 0x001);
|
|
|
|
|
EMIT_ (spe_nop, 0x201);
|
2008-02-14 10:08:11 -08:00
|
|
|
sync;
|
2008-02-14 17:42:34 -08:00
|
|
|
EMIT_ (spe_dsync, 0x003);
|
|
|
|
|
EMIT_R (spe_mfspr, 0x00c);
|
|
|
|
|
EMIT_R (spe_mtspr, 0x10c);
|
2008-02-14 10:08:11 -08:00
|
|
|
#endif
|
|
|
|
|
|
2008-09-10 17:11:48 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
** Helper / "macro" instructions.
|
|
|
|
|
** Use somewhat verbose names as a reminder that these aren't native
|
|
|
|
|
** SPE instructions.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_load_float(struct spe_function *p, unsigned rT, float x)
|
|
|
|
|
{
|
2008-09-11 17:07:30 -06:00
|
|
|
if (x == 0.0f) {
|
|
|
|
|
spe_il(p, rT, 0x0);
|
|
|
|
|
}
|
|
|
|
|
else if (x == 0.5f) {
|
|
|
|
|
spe_ilhu(p, rT, 0x3f00);
|
|
|
|
|
}
|
|
|
|
|
else if (x == 1.0f) {
|
|
|
|
|
spe_ilhu(p, rT, 0x3f80);
|
|
|
|
|
}
|
|
|
|
|
else if (x == -1.0f) {
|
|
|
|
|
spe_ilhu(p, rT, 0xbf80);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
union {
|
|
|
|
|
float f;
|
|
|
|
|
unsigned u;
|
|
|
|
|
} bits;
|
|
|
|
|
bits.f = x;
|
|
|
|
|
spe_ilhu(p, rT, bits.u >> 16);
|
|
|
|
|
spe_iohl(p, rT, bits.u & 0xffff);
|
|
|
|
|
}
|
2008-09-10 17:11:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_load_int(struct spe_function *p, unsigned rT, int i)
|
|
|
|
|
{
|
2008-09-11 17:07:30 -06:00
|
|
|
if (-32768 <= i && i <= 32767) {
|
|
|
|
|
spe_il(p, rT, i);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
spe_ilhu(p, rT, i >> 16);
|
2008-09-12 08:22:15 -06:00
|
|
|
if (i & 0xffff)
|
|
|
|
|
spe_iohl(p, rT, i & 0xffff);
|
2008-09-11 17:07:30 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_splat(struct spe_function *p, unsigned rT, unsigned rA)
|
|
|
|
|
{
|
|
|
|
|
spe_ila(p, rT, 66051);
|
|
|
|
|
spe_shufb(p, rT, rA, rA, rT);
|
2008-09-10 17:11:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_complement(struct spe_function *p, unsigned rT)
|
|
|
|
|
{
|
|
|
|
|
spe_nor(p, rT, rT, rT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_move(struct spe_function *p, unsigned rT, unsigned rA)
|
|
|
|
|
{
|
|
|
|
|
spe_ori(p, rT, rA, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
spe_zero(struct spe_function *p, unsigned rT)
|
|
|
|
|
{
|
|
|
|
|
spe_xor(p, rT, rT, rT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-09-12 21:08:01 -06:00
|
|
|
void
|
|
|
|
|
spe_splat_word(struct spe_function *p, unsigned rT, unsigned rA, int word)
|
|
|
|
|
{
|
|
|
|
|
assert(word >= 0);
|
|
|
|
|
assert(word <= 3);
|
|
|
|
|
|
|
|
|
|
if (word == 0) {
|
|
|
|
|
int tmp1 = rT;
|
|
|
|
|
spe_ila(p, tmp1, 66051);
|
|
|
|
|
spe_shufb(p, rT, rA, rA, tmp1);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* XXX review this, we may not need the rotqbyi instruction */
|
|
|
|
|
int tmp1 = rT;
|
|
|
|
|
int tmp2 = spe_allocate_available_register(p);
|
|
|
|
|
|
|
|
|
|
spe_ila(p, tmp1, 66051);
|
|
|
|
|
spe_rotqbyi(p, tmp2, rA, 4 * word);
|
|
|
|
|
spe_shufb(p, rT, tmp2, tmp2, tmp1);
|
|
|
|
|
|
|
|
|
|
spe_release_register(p, tmp2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-18 01:29:41 -06:00
|
|
|
/* For each 32-bit float element of rA and rB, choose the smaller of the
|
|
|
|
|
* two, compositing them into the rT register.
|
|
|
|
|
*
|
|
|
|
|
* The Float Compare Greater Than (fcgt) instruction will put 1s into
|
|
|
|
|
* compare_reg where rA > rB, and 0s where rA <= rB.
|
|
|
|
|
*
|
|
|
|
|
* Then the Select Bits (selb) instruction will take bits from rA where
|
|
|
|
|
* compare_reg is 0, and from rB where compare_reg is 1; i.e., from rA
|
|
|
|
|
* where rA <= rB and from rB where rB > rA, which is exactly the
|
|
|
|
|
* "min" operation.
|
|
|
|
|
*
|
|
|
|
|
* The compare_reg could in many cases be the same as rT, unless
|
|
|
|
|
* rT == rA || rt == rB. But since this is common in constructions
|
|
|
|
|
* like "x = min(x, a)", we always allocate a new register to be safe.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
spe_float_min(struct spe_function *p, unsigned int rT, unsigned int rA, unsigned int rB)
|
|
|
|
|
{
|
|
|
|
|
unsigned int compare_reg = spe_allocate_available_register(p);
|
|
|
|
|
spe_fcgt(p, compare_reg, rA, rB);
|
|
|
|
|
spe_selb(p, rT, rA, rB, compare_reg);
|
|
|
|
|
spe_release_register(p, compare_reg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For each 32-bit float element of rA and rB, choose the greater of the
|
|
|
|
|
* two, compositing them into the rT register.
|
|
|
|
|
*
|
|
|
|
|
* The logic is similar to that of spe_float_min() above; the only
|
|
|
|
|
* difference is that the registers on spe_selb() have been reversed,
|
|
|
|
|
* so that the larger of the two is selected instead of the smaller.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
spe_float_max(struct spe_function *p, unsigned int rT, unsigned int rA, unsigned int rB)
|
|
|
|
|
{
|
|
|
|
|
unsigned int compare_reg = spe_allocate_available_register(p);
|
|
|
|
|
spe_fcgt(p, compare_reg, rA, rB);
|
|
|
|
|
spe_selb(p, rT, rB, rA, compare_reg);
|
|
|
|
|
spe_release_register(p, compare_reg);
|
|
|
|
|
}
|
2008-09-12 21:08:01 -06:00
|
|
|
|
2008-02-14 10:08:11 -08:00
|
|
|
#endif /* GALLIUM_CELL */
|