From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 28 Sep 2018 08:19:48 +0000 (+0900) Subject: [coco] Introduce InstrIndex (#1670) X-Git-Tag: nncc_backup~1680 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=743f15c446d39fe71c045584cd27bc3d0d4321ed;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Introduce InstrIndex (#1670) This commit introduces InstIndex class which denotes the index of each instruction (inside a block). Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/InstrIndex.h b/contrib/coco/core/include/coco/IR/InstrIndex.h new file mode 100644 index 0000000..a61d97c --- /dev/null +++ b/contrib/coco/core/include/coco/IR/InstrIndex.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __COCO_IR_INSTR_INDEX_H__ +#define __COCO_IR_INSTR_INDEX_H__ + +#include + +namespace coco +{ + +/** + * @brief A InstrIndex denotes the index of an instruction in an instruction list + */ +class InstrIndex final +{ +private: + static const uint32_t undefined = 0xffffffff; + +public: + InstrIndex() : _value{undefined} + { + // DO NOTHING + } + +public: + InstrIndex(uint32_t value) { set(value); } + +public: + bool valid(void) const { return _value != undefined; } + +public: + uint32_t value(void) const { return _value; } + +public: + void set(uint32_t value); + void reset(void) { _value = undefined; } + +private: + uint32_t _value; +}; + +static inline bool operator<(const InstrIndex &lhs, const InstrIndex &rhs) +{ + return lhs.value() < rhs.value(); +} + +} // namespace coco + +#endif // __COCO_IR_INSTR_INDEX_H__ diff --git a/contrib/coco/core/src/IR/InstrIndex.cpp b/contrib/coco/core/src/IR/InstrIndex.cpp new file mode 100644 index 0000000..c447cfc --- /dev/null +++ b/contrib/coco/core/src/IR/InstrIndex.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "coco/IR/InstrIndex.h" + +#include + +namespace coco +{ + +void InstrIndex::set(uint32_t value) +{ + assert(value != undefined); + _value = value; +} + +} // namespace coco diff --git a/contrib/coco/core/src/IR/InstrIndex.test.cpp b/contrib/coco/core/src/IR/InstrIndex.test.cpp new file mode 100644 index 0000000..40f5d49 --- /dev/null +++ b/contrib/coco/core/src/IR/InstrIndex.test.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "coco/IR/InstrIndex.h" + +#include + +namespace +{ + +class InstrIndexTest : public ::testing::Test +{ +}; + +} // namespace + +TEST_F(InstrIndexTest, default_constructor) +{ + coco::InstrIndex ins_ind; + + ASSERT_FALSE(ins_ind.valid()); +} + +TEST_F(InstrIndexTest, explicit_constructor) +{ + coco::InstrIndex ins_ind{3}; + + ASSERT_TRUE(ins_ind.valid()); + ASSERT_EQ(ins_ind.value(), 3); +} + +TEST_F(InstrIndexTest, operator_lt) +{ + // Valid index is always less than undefined one. + ASSERT_TRUE(coco::InstrIndex(3) < coco::InstrIndex()); + ASSERT_TRUE(coco::InstrIndex(3) < coco::InstrIndex(4)); +}