Staging
v0.5.1
https://github.com/python/cpython
Revision 6f9cd142a20d0d2a5825a9db376ce0ddf1933694 authored by Miss Islington (bot) on 04 April 2019, 08:25:59 UTC, committed by Serhiy Storchaka on 04 April 2019, 08:25:59 UTC
(cherry picked from commit 461c416dd78a98f2bba7f323af8c9738e060b6f2)

Co-authored-by: Matt Houglum <houglum@google.com>
1 parent 513d142
Raw File
Tip revision: 6f9cd142a20d0d2a5825a9db376ce0ddf1933694 authored by Miss Islington (bot) on 04 April 2019, 08:25:59 UTC
bpo-36522: Print all values for headers with multiple values. (GH-12681) (GH-12682)
Tip revision: 6f9cd14
wordcode_helpers.h
/* This file contains code shared by the compiler and the peephole
   optimizer.
 */

#ifdef WORDS_BIGENDIAN
#  define PACKOPARG(opcode, oparg) ((_Py_CODEUNIT)(((opcode) << 8) | (oparg)))
#else
#  define PACKOPARG(opcode, oparg) ((_Py_CODEUNIT)(((oparg) << 8) | (opcode)))
#endif

/* Minimum number of code units necessary to encode instruction with
   EXTENDED_ARGs */
static int
instrsize(unsigned int oparg)
{
    return oparg <= 0xff ? 1 :
        oparg <= 0xffff ? 2 :
        oparg <= 0xffffff ? 3 :
        4;
}

/* Spits out op/oparg pair using ilen bytes. codestr should be pointed at the
   desired location of the first EXTENDED_ARG */
static void
write_op_arg(_Py_CODEUNIT *codestr, unsigned char opcode,
    unsigned int oparg, int ilen)
{
    switch (ilen) {
        case 4:
            *codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 24) & 0xff);
            /* fall through */
        case 3:
            *codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 16) & 0xff);
            /* fall through */
        case 2:
            *codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 8) & 0xff);
            /* fall through */
        case 1:
            *codestr++ = PACKOPARG(opcode, oparg & 0xff);
            break;
        default:
            Py_UNREACHABLE();
    }
}
back to top