Mercurial > hg > octave-nkf
changeset 18631:d464edd2552b draft
Fully uint32 type support
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 06:50:59 +0800 |
parents | 2204a9a252c0 |
children | 5a5a67799338 |
files | libinterp/corefcn/jit-typeinfo.cc |
diffstat | 1 files changed, 138 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/jit-typeinfo.cc +++ b/libinterp/corefcn/jit-typeinfo.cc @@ -75,6 +75,7 @@ #include "ov-int64.h" #include "ov-uint8.h" #include "ov-uint16.h" +#include "ov-uint32.h" #include "ov-uint64.h" #include "pager.h" @@ -298,6 +299,20 @@ return new octave_uint16_scalar (value); } +extern "C" uint32_t +octave_jit_cast_uint32_any (octave_base_value *obv) +{ + uint32_t ret = obv->uint32_scalar_value (); + obv->release (); + return ret; +} + +extern "C" octave_base_value * +octave_jit_cast_any_uint32 (uint32_t value) +{ + return new octave_uint32_scalar (value); +} + extern "C" uint64_t octave_jit_cast_uint64_any (octave_base_value *obv) { @@ -987,6 +1002,53 @@ /************************************************************ * + * uint32 related external helper function + * + ************************************************************/ + +extern "C" uint32_t +octave_jit_add_uint32_uint32 (uint32_t lhs, uint32_t rhs) +{ + uint32_t res = lhs + rhs; + res |= -(res < lhs); + + return res; +} + +extern "C" uint32_t +octave_jit_sub_uint32_uint32 (uint32_t lhs, uint32_t rhs) +{ + uint32_t res = lhs - rhs; + res &= -(res <= lhs); + + return res; +} + +extern "C" uint32_t +octave_jit_mul_uint32_uint32 (uint32_t lhs, uint32_t rhs) +{ + uint64_t res = (uint64_t) lhs * (uint64_t) rhs; + + uint32_t hi = res >> 32; + uint32_t lo = res; + + return lo | -!!hi; +} + +extern "C" uint32_t +octave_jit_incr_uint32 (uint32_t val) +{ + return octave_jit_add_uint32_uint32 (val, 1); +} + +extern "C" uint32_t +octave_jit_decr_uint32 (uint32_t val) +{ + return octave_jit_sub_uint32_uint32 (val, 1); +} + +/************************************************************ + * * uint64 related external helper function * ************************************************************/ @@ -1673,6 +1735,7 @@ llvm::Type *int64__t = llvm::Type::getIntNTy (context, 64); llvm::Type *uint8__t = llvm::Type::getIntNTy (context, 8); llvm::Type *uint16__t = llvm::Type::getIntNTy (context, 16); + llvm::Type *uint32__t = llvm::Type::getIntNTy (context, 32); llvm::Type *uint64__t = llvm::Type::getIntNTy (context, 64); llvm::Type *bool_t = llvm::Type::getInt1Ty (context); llvm::Type *string_t = llvm::Type::getInt8Ty (context); @@ -1729,6 +1792,7 @@ create_uint (8); create_uint (16); + create_uint (32); create_uint (64); casts.resize (next_id + 1); @@ -1830,6 +1894,7 @@ grab_fn.add_overload (create_identity (intN (64))); grab_fn.add_overload (create_identity (uintN (8))); grab_fn.add_overload (create_identity (uintN (16))); + grab_fn.add_overload (create_identity (uintN (32))); grab_fn.add_overload (create_identity (uintN (64))); grab_fn.add_overload (create_identity (scalar_ptr)); grab_fn.add_overload (create_identity (any_ptr)); @@ -1857,6 +1922,7 @@ destroy_fn.add_overload (create_identity(intN (64))); destroy_fn.add_overload (create_identity(uintN (8))); destroy_fn.add_overload (create_identity(uintN (16))); + destroy_fn.add_overload (create_identity(uintN (32))); destroy_fn.add_overload (create_identity(uintN (64))); destroy_fn.add_overload (create_identity(boolean)); destroy_fn.add_overload (create_identity(index)); @@ -2472,6 +2538,60 @@ /************************************************************ * + * uint32 related operations + * + ************************************************************/ + + // now for binary uint32 operations + fn = create_external (JIT_FN (octave_jit_add_uint32_uint32), uintN (32), uintN (32), + uintN (32)); + binary_ops[octave_value::op_add].add_overload (fn); + fn = create_external (JIT_FN (octave_jit_sub_uint32_uint32), uintN (32), uintN (32), + uintN (32)); + binary_ops[octave_value::op_sub].add_overload (fn); + fn = create_external (JIT_FN (octave_jit_mul_uint32_uint32), uintN (32), uintN (32), + uintN (32)); + binary_ops[octave_value::op_mul].add_overload (fn); + binary_ops[octave_value::op_el_mul].add_overload (fn); + + add_binary_icmp (uintN (32), octave_value::op_lt, llvm::CmpInst::ICMP_ULT); + add_binary_icmp (uintN (32), octave_value::op_le, llvm::CmpInst::ICMP_ULE); + add_binary_icmp (uintN (32), octave_value::op_eq, llvm::CmpInst::ICMP_EQ); + add_binary_icmp (uintN (32), octave_value::op_ge, llvm::CmpInst::ICMP_UGE); + add_binary_icmp (uintN (32), octave_value::op_gt, llvm::CmpInst::ICMP_UGT); + add_binary_icmp (uintN (32), octave_value::op_ne, llvm::CmpInst::ICMP_NE); + + // FIXME: saturation divide definition? interpreter convert uint to double, calculate and round. + // divide is annoying because it might error + // FIXME: Implement div + + // FIXME: Implement pow + + // now for unary uint32 operations + // FIXME: Impelment not + fn = create_external (JIT_FN (octave_jit_incr_uint32), uintN (32), uintN (32)); + unary_ops[octave_value::op_incr].add_overload (fn); + + fn = create_external (JIT_FN (octave_jit_decr_uint32), uintN (32), uintN (32)); + unary_ops[octave_value::op_decr].add_overload (fn); + + fn = create_internal ("octave_jit_uminus", uintN (32), uintN (32)); + body = fn.new_block (); + builder.SetInsertPoint (body); + { + llvm::Value *zero = llvm::ConstantInt::get (uint32__t, 0); + + fn.do_return (builder, zero); + } + unary_ops[octave_value::op_uminus].add_overload (fn); + + fn = create_identity (uintN (32)); + unary_ops[octave_value::op_uplus].add_overload (fn); + unary_ops[octave_value::op_transpose].add_overload (fn); + unary_ops[octave_value::op_hermitian].add_overload (fn); + + /************************************************************ + * * uint64 related operations * ************************************************************/ @@ -2907,6 +3027,7 @@ casts[intN (64)->type_id ()].stash_name ("(int64)"); casts[uintN (8)->type_id ()].stash_name ("(uint8)"); casts[uintN (16)->type_id ()].stash_name ("(uint16)"); + casts[uintN (32)->type_id ()].stash_name ("(uint32)"); casts[uintN (64)->type_id ()].stash_name ("(uint64)"); casts[complex->type_id ()].stash_name ("(complex)"); casts[matrix->type_id ()].stash_name ("(matrix)"); @@ -2992,6 +3113,14 @@ fn = create_external (JIT_FN (octave_jit_cast_uint16_any), uintN (16), any); casts[uintN (16)->type_id ()].add_overload (fn); + // cast any <- uint32 + fn = create_external (JIT_FN (octave_jit_cast_any_uint32), any, uintN (32)); + casts[any->type_id ()].add_overload (fn); + + // cast uint32 <- any + fn = create_external (JIT_FN (octave_jit_cast_uint32_any), uintN (32), any); + casts[uintN (32)->type_id ()].add_overload (fn); + // cast any <- uint64 fn = create_external (JIT_FN (octave_jit_cast_any_uint64), any, uintN (64)); casts[any->type_id ()].add_overload (fn); @@ -3061,6 +3190,10 @@ fn = create_identity (uintN (16)); casts[uintN (16)->type_id ()].add_overload (fn); + // cast uint32 <- uint32 + fn = create_identity (uintN (32)); + casts[uintN (32)->type_id ()].add_overload (fn); + // cast uint64 <- uint64 fn = create_identity (uintN (64)); casts[uintN (64)->type_id ()].add_overload (fn); @@ -3553,6 +3686,11 @@ return uintN (16); } + if (ov.is_uint32_type()) + { + return uintN (32); + } + if (ov.is_uint64_type()) { return uintN (64);