From 54ea34d560dc9db9b1a6280f453c4dcd9879ec6d Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Tue, 8 May 2018 22:39:18 +0200 Subject: [PATCH] pdp10-arith: add pdp10_sext_uint18() --- include/pdp10-arith.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/pdp10-arith.h b/include/pdp10-arith.h index cf5caa5..e1823d8 100644 --- a/include/pdp10-arith.h +++ b/include/pdp10-arith.h @@ -1,6 +1,6 @@ /* * pdp10-arith.h -- arithmetic on PDP10 integer types - * Copyright (C) 2013-2015 Mikael Pettersson + * Copyright (C) 2013-2018 Mikael Pettersson * * This file is part of pdp10-tools. * @@ -44,6 +44,14 @@ static inline pdp10_int36_t pdp10_sext_int36(pdp10_uint36_t x) return ((x & PDP10_UINT36_MAX) ^ PDP10_UINT36_SBIT) - PDP10_UINT36_SBIT; } +/* Sign-extend a pdp10_uint18_t to the full width of its representation type. */ +static inline pdp10_uint18_t pdp10_sext_uint18(pdp10_uint18_t x) +{ + const pdp10_uint18_t PDP10_UINT18_SBIT = ~(PDP10_UINT18_MAX >> 1) & PDP10_UINT18_MAX; + + return ((x & PDP10_UINT18_MAX) ^ PDP10_UINT18_SBIT) - PDP10_UINT18_SBIT; +} + static inline pdp10_uint36_t pdp10_neg_int36(pdp10_uint36_t x) { return pdp10_zext_uint36(-pdp10_sext_int36(x));