From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnSFJ-0000LL-Fl for qemu-devel@nongnu.org; Wed, 29 Apr 2015 09:41:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnSFE-0002dS-CS for qemu-devel@nongnu.org; Wed, 29 Apr 2015 09:41:49 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:32783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnSFE-0002dI-4T for qemu-devel@nongnu.org; Wed, 29 Apr 2015 09:41:44 -0400 Received: by pacwv17 with SMTP id wv17so28390113pac.0 for ; Wed, 29 Apr 2015 06:41:43 -0700 (PDT) Message-ID: <5540DF93.4090000@linaro.org> Date: Wed, 29 Apr 2015 21:41:39 +0800 From: Shannon Zhao MIME-Version: 1.0 References: <1429104309-3844-1-git-send-email-zhaoshenglong@huawei.com> <1429104309-3844-14-git-send-email-zhaoshenglong@huawei.com> <20150428085412.5d215d01@nial.brq.redhat.com> <553F3ACE.2060208@huawei.com> <20150428101529.5feb4915@nial.brq.redhat.com> <553F4A43.2090104@huawei.com> <20150428113503.0fe6fe9c@nial.brq.redhat.com> <553F5782.7020707@huawei.com> In-Reply-To: <553F5782.7020707@huawei.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5 13/20] hw/acpi/aml-build: Add ToUUID macro List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Shannon Zhao , Igor Mammedov Cc: peter.maydell@linaro.org, hangaohuai@huawei.com, mst@redhat.com, a.spyridakis@virtualopensystems.com, claudio.fontana@huawei.com, qemu-devel@nongnu.org, peter.huangpeng@huawei.com, alex.bennee@linaro.org, hanjun.guo@linaro.org, pbonzini@redhat.com, lersek@redhat.com, christoffer.dall@linaro.org On 2015/4/28 17:48, Shannon Zhao wrote: > On 2015/4/28 17:35, Igor Mammedov wrote: >> On Tue, 28 Apr 2015 16:52:19 +0800 >> Shannon Zhao wrote: >> >>> On 2015/4/28 16:15, Igor Mammedov wrote: >>>>>> btw: >>>>>>>> whole thing might be simpler if an intermediate conversion is avoided, >>>>>>>> just pack buffer as in spec byte by byte: >>>>>>>> >>>>>>>> /* format: aabbccdd-eeff-gghh-iijj-kkllmmnnoopp */ >>>>>>>> assert(strlen(uuid) == ...); >>>>>>>> build_append_byte(var->buf, HEX2BYTE(uuid[3]); /* dd */ >>>>>> >>>>>> use build_append_byte(var->buf, HEX2BYTE(uuid + 7); ? >>>>>> >>>>>>>> build_append_byte(var->buf, HEX2BYTE(uuid[2]); /* cc */ >>>>>> >>>>>> use build_append_byte(var->buf, HEX2BYTE(uuid + 5); ? >>>> if you mean hyphens /-/ then they are not encoded, >>>> but you surely can add checks for them to make sure that >>>> UUID format is as expected. >>>> >>> >>> I mean uuid[3] points to b not dd. Maybe use following way: >>> >>> static uint8_t Hex2Byte(char *src) >> or even better: >> Hex2Byte(char *src, byte_idx) >> and do pointer arithmetic inside >> >> [...] >>> build_append_byte(var->buf, Hex2Byte(uuid + (3 * 2))); /* dd */ >> build_append_byte(var->buf, Hex2Byte(uuid, 3)); /* dd - at offset 00 */ >> build_append_byte(var->buf, Hex2Byte(uuid, 2)); /* cc - at offset 01 */ >> ... >> > Yes, it's better to first four bytes. But there are hyphens /-/, for > offset 04, 05 and etc it doesn't work. We can't use following expression: > > build_append_byte(var->buf, Hex2Byte(uuid, 5)); /* ff - at offset 04 */ > build_append_byte(var->buf, Hex2Byte(uuid, 4)); /* ee - at offset 05 */ > ... > > So about the implementation of this macro, I think I'd like to use following approach. This lets Hex2Byte do what it should only do and still has a clear look of UUID. What do you think about? static uint8_t Hex2Byte(char *src) { int hi = Hex2Digit(*src++); int lo = Hex2Digit(*src); if ((hi < 0) || (lo < 0)) return -1; return (hi << 4) | lo; } g_assert((strlen(uuid) == 36) && (uuid[8] == '-') && (uuid[13] == '-') && (uuid[18] == '-') && (uuid[23] == '-')); build_append_byte(var->buf, Hex2Byte(uuid + (3 * 2))); /* dd */ build_append_byte(var->buf, Hex2Byte(uuid + (2 * 2))); /* cc */ build_append_byte(var->buf, Hex2Byte(uuid + (1 * 2))); /* bb */ build_append_byte(var->buf, Hex2Byte(uuid + (0 * 2))); /* aa */ build_append_byte(var->buf, Hex2Byte(uuid + (5 * 2 + 1))); /* ff */ build_append_byte(var->buf, Hex2Byte(uuid + (4 * 2 + 1))); /* ee */ build_append_byte(var->buf, Hex2Byte(uuid + (7 * 2 + 2))); /* hh */ build_append_byte(var->buf, Hex2Byte(uuid + (6 * 2 + 2))); /* gg */ build_append_byte(var->buf, Hex2Byte(uuid + (8 * 2 + 3))); /* ii */ build_append_byte(var->buf, Hex2Byte(uuid + (9 * 2 + 3))); /* jj */ build_append_byte(var->buf, Hex2Byte(uuid + (10 * 2 + 4))); /* kk */ build_append_byte(var->buf, Hex2Byte(uuid + (11 * 2 + 4))); /* ll */ build_append_byte(var->buf, Hex2Byte(uuid + (12 * 2 + 4))); /* mm */ build_append_byte(var->buf, Hex2Byte(uuid + (13 * 2 + 4))); /* nn */ build_append_byte(var->buf, Hex2Byte(uuid + (14 * 2 + 4))); /* oo */ build_append_byte(var->buf, Hex2Byte(uuid + (15 * 2 + 4))); /* pp */