Running clang-format on alloy.
All except x64_sequences, which needs work.
This commit is contained in:
@@ -9,9 +9,8 @@
|
||||
|
||||
#include <alloy/hir/value.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::hir;
|
||||
|
||||
namespace alloy {
|
||||
namespace hir {
|
||||
|
||||
Value::Use* Value::AddUse(Arena* arena, Instr* instr) {
|
||||
Use* use = arena->Alloc<Use>();
|
||||
@@ -39,34 +38,34 @@ void Value::RemoveUse(Use* use) {
|
||||
uint32_t Value::AsUint32() {
|
||||
XEASSERT(IsConstant());
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
return constant.i8;
|
||||
case INT16_TYPE:
|
||||
return constant.i16;
|
||||
case INT32_TYPE:
|
||||
return constant.i32;
|
||||
case INT64_TYPE:
|
||||
return (uint32_t)constant.i64;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
return 0;
|
||||
case INT8_TYPE:
|
||||
return constant.i8;
|
||||
case INT16_TYPE:
|
||||
return constant.i16;
|
||||
case INT32_TYPE:
|
||||
return constant.i32;
|
||||
case INT64_TYPE:
|
||||
return (uint32_t)constant.i64;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Value::AsUint64() {
|
||||
XEASSERT(IsConstant());
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
return constant.i8;
|
||||
case INT16_TYPE:
|
||||
return constant.i16;
|
||||
case INT32_TYPE:
|
||||
return constant.i32;
|
||||
case INT64_TYPE:
|
||||
return constant.i64;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
return 0;
|
||||
case INT8_TYPE:
|
||||
return constant.i8;
|
||||
case INT16_TYPE:
|
||||
return constant.i16;
|
||||
case INT32_TYPE:
|
||||
return constant.i32;
|
||||
case INT64_TYPE:
|
||||
return constant.i64;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,87 +76,6 @@ void Value::Cast(TypeName target_type) {
|
||||
|
||||
void Value::ZeroExtend(TypeName target_type) {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
return;
|
||||
case INT16_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFF;
|
||||
return;
|
||||
case INT32_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFFFFFF;
|
||||
return;
|
||||
}
|
||||
// Unsupported types.
|
||||
XEASSERTALWAYS();
|
||||
}
|
||||
|
||||
void Value::SignExtend(TypeName target_type) {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
switch (target_type) {
|
||||
case INT16_TYPE:
|
||||
constant.i16 = constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i8;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case INT16_TYPE:
|
||||
type = target_type;
|
||||
switch (target_type) {
|
||||
case INT32_TYPE:
|
||||
constant.i32 = constant.i16;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i16;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case INT32_TYPE:
|
||||
type = target_type;
|
||||
switch (target_type) {
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i32;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Unsupported types.
|
||||
XEASSERTALWAYS();
|
||||
}
|
||||
|
||||
void Value::Truncate(TypeName target_type) {
|
||||
switch (type) {
|
||||
case INT16_TYPE:
|
||||
switch (target_type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
switch (target_type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
return;
|
||||
case INT16_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFF;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
switch (target_type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
@@ -170,8 +88,89 @@ void Value::Truncate(TypeName target_type) {
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFFFFFF;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Unsupported types.
|
||||
XEASSERTALWAYS();
|
||||
}
|
||||
|
||||
void Value::SignExtend(TypeName target_type) {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
switch (target_type) {
|
||||
case INT16_TYPE:
|
||||
constant.i16 = constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i8;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case INT16_TYPE:
|
||||
type = target_type;
|
||||
switch (target_type) {
|
||||
case INT32_TYPE:
|
||||
constant.i32 = constant.i16;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i16;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
case INT32_TYPE:
|
||||
type = target_type;
|
||||
switch (target_type) {
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i32;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Unsupported types.
|
||||
XEASSERTALWAYS();
|
||||
}
|
||||
|
||||
void Value::Truncate(TypeName target_type) {
|
||||
switch (type) {
|
||||
case INT16_TYPE:
|
||||
switch (target_type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
switch (target_type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
return;
|
||||
case INT16_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFF;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
switch (target_type) {
|
||||
case INT8_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFF;
|
||||
return;
|
||||
case INT16_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFF;
|
||||
return;
|
||||
case INT32_TYPE:
|
||||
type = target_type;
|
||||
constant.i64 = constant.i64 & 0xFFFFFFFF;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Unsupported types.
|
||||
XEASSERTALWAYS();
|
||||
@@ -188,70 +187,70 @@ void Value::Round(RoundMode round_mode) {
|
||||
}
|
||||
|
||||
bool Value::Add(Value* other) {
|
||||
#define CHECK_DID_CARRY(v1, v2) (((uint64_t)v2) > ~((uint64_t)v1))
|
||||
#define ADD_DID_CARRY(a, b) CHECK_DID_CARRY(a, b)
|
||||
#define CHECK_DID_CARRY(v1, v2) (((uint64_t)v2) > ~((uint64_t)v1))
|
||||
#define ADD_DID_CARRY(a, b) CHECK_DID_CARRY(a, b)
|
||||
XEASSERT(type == other->type);
|
||||
bool did_carry = false;
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i8, other->constant.i8);
|
||||
constant.i8 += other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i16, other->constant.i16);
|
||||
constant.i16 += other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i32, other->constant.i32);
|
||||
constant.i32 += other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i64, other->constant.i64);
|
||||
constant.i64 += other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 += other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 += other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i8, other->constant.i8);
|
||||
constant.i8 += other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i16, other->constant.i16);
|
||||
constant.i16 += other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i32, other->constant.i32);
|
||||
constant.i32 += other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
did_carry = ADD_DID_CARRY(constant.i64, other->constant.i64);
|
||||
constant.i64 += other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 += other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 += other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
return did_carry;
|
||||
}
|
||||
|
||||
bool Value::Sub(Value* other) {
|
||||
#define SUB_DID_CARRY(a, b) (b > a)
|
||||
#define SUB_DID_CARRY(a, b) (b > a)
|
||||
XEASSERT(type == other->type);
|
||||
bool did_carry = false;
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i8, other->constant.i8);
|
||||
constant.i8 -= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i16, other->constant.i16);
|
||||
constant.i16 -= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i32, other->constant.i32);
|
||||
constant.i32 -= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i64, other->constant.i64);
|
||||
constant.i64 -= other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 -= other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 -= other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i8, other->constant.i8);
|
||||
constant.i8 -= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i16, other->constant.i16);
|
||||
constant.i16 -= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i32, other->constant.i32);
|
||||
constant.i32 -= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
did_carry = SUB_DID_CARRY(constant.i64, other->constant.i64);
|
||||
constant.i64 -= other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 -= other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 -= other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
return did_carry;
|
||||
}
|
||||
@@ -259,54 +258,54 @@ bool Value::Sub(Value* other) {
|
||||
void Value::Mul(Value* other) {
|
||||
XEASSERT(type == other->type);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 *= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 *= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 *= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 *= other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 *= other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 *= other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 *= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 *= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 *= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 *= other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 *= other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 *= other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Div(Value* other) {
|
||||
XEASSERT(type == other->type);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 /= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 /= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 /= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 /= other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 /= other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 /= other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 /= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 /= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 /= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 /= other->constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 /= other->constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 /= other->constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,276 +321,276 @@ void Value::MulSub(Value* dest, Value* value1, Value* value2, Value* value3) {
|
||||
|
||||
void Value::Neg() {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = -constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = -constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = -constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = -constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = -constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = -constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = -constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = -constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = -constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = -constant.i64;
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = -constant.f32;
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = -constant.f64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Abs() {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = abs(constant.i8);
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = abs(constant.i16);
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = abs(constant.i32);
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = abs(constant.i64);
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = abs(constant.f32);
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = abs(constant.f64);
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = abs(constant.i8);
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = abs(constant.i16);
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = abs(constant.i32);
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = abs(constant.i64);
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = abs(constant.f32);
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = abs(constant.f64);
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Sqrt() {
|
||||
switch (type) {
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = 1.0f / sqrtf(constant.f32);
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = 1.0 / sqrt(constant.f64);
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = 1.0f / sqrtf(constant.f32);
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = 1.0 / sqrt(constant.f64);
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::RSqrt() {
|
||||
switch (type) {
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = sqrt(constant.f32);
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = sqrt(constant.f64);
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case FLOAT32_TYPE:
|
||||
constant.f32 = sqrt(constant.f32);
|
||||
break;
|
||||
case FLOAT64_TYPE:
|
||||
constant.f64 = sqrt(constant.f64);
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::And(Value* other) {
|
||||
XEASSERT(type == other->type);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 &= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 &= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 &= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 &= other->constant.i64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 &= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 &= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 &= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 &= other->constant.i64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Or(Value* other) {
|
||||
XEASSERT(type == other->type);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 |= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 |= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 |= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 |= other->constant.i64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 |= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 |= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 |= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 |= other->constant.i64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Xor(Value* other) {
|
||||
XEASSERT(type == other->type);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 ^= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 ^= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 ^= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 ^= other->constant.i64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 ^= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 ^= other->constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 ^= other->constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 ^= other->constant.i64;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Not() {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = ~constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = ~constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = ~constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = ~constant.i64;
|
||||
break;
|
||||
case VEC128_TYPE:
|
||||
constant.v128.low = ~constant.v128.low;
|
||||
constant.v128.high = ~constant.v128.high;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = ~constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = ~constant.i16;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = ~constant.i32;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = ~constant.i64;
|
||||
break;
|
||||
case VEC128_TYPE:
|
||||
constant.v128.low = ~constant.v128.low;
|
||||
constant.v128.high = ~constant.v128.high;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Shl(Value* other) {
|
||||
XEASSERT(other->type == INT8_TYPE);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 <<= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 <<= other->constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 <<= other->constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 <<= other->constant.i8;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 <<= other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 <<= other->constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 <<= other->constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 <<= other->constant.i8;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Shr(Value* other) {
|
||||
XEASSERT(other->type == INT8_TYPE);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = (uint8_t)constant.i8 >> other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = (uint16_t)constant.i16 >> other->constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = (uint32_t)constant.i32 >> other->constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = (uint16_t)constant.i64 >> other->constant.i8;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = (uint8_t)constant.i8 >> other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = (uint16_t)constant.i16 >> other->constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = (uint32_t)constant.i32 >> other->constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = (uint16_t)constant.i64 >> other->constant.i8;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::Sha(Value* other) {
|
||||
XEASSERT(other->type == INT8_TYPE);
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = constant.i8 >> other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = constant.i16 >> other->constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = constant.i32 >> other->constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i64 >> other->constant.i8;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = constant.i8 >> other->constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = constant.i16 >> other->constant.i8;
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = constant.i32 >> other->constant.i8;
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = constant.i64 >> other->constant.i8;
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::ByteSwap() {
|
||||
switch (type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = XESWAP16(constant.i16);
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = XESWAP32(constant.i32);
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = XESWAP64(constant.i64);
|
||||
break;
|
||||
case VEC128_TYPE:
|
||||
for (int n = 0; n < 4; n++) {
|
||||
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = constant.i8;
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i16 = XESWAP16(constant.i16);
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i32 = XESWAP32(constant.i32);
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i64 = XESWAP64(constant.i64);
|
||||
break;
|
||||
case VEC128_TYPE:
|
||||
for (int n = 0; n < 4; n++) {
|
||||
constant.v128.i4[n] = XESWAP32(constant.v128.i4[n]);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Value::CountLeadingZeros(const Value* other) {
|
||||
switch (other->type) {
|
||||
case INT8_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i8) - 8);
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i16));
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt(other->constant.i32));
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt64(other->constant.i64));
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
case INT8_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i8) - 8);
|
||||
break;
|
||||
case INT16_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt16(other->constant.i16));
|
||||
break;
|
||||
case INT32_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt(other->constant.i32));
|
||||
break;
|
||||
case INT64_TYPE:
|
||||
constant.i8 = static_cast<uint8_t>(__lzcnt64(other->constant.i64));
|
||||
break;
|
||||
default:
|
||||
XEASSERTALWAYS();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -600,3 +599,6 @@ bool Value::Compare(Opcode opcode, Value* other) {
|
||||
XEASSERTALWAYS();
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace hir
|
||||
} // namespace alloy
|
||||
|
||||
Reference in New Issue
Block a user